1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.renameSync = exports.copyFile = exports.updateJsonFile = exports.createDirectory = exports.isRelativePath = exports.directoryExists = exports.fileExists = void 0;
|
4 | const fs_1 = require("fs");
|
5 | const path_1 = require("path");
|
6 | const fileutils_1 = require("nx/src/utils/fileutils");
|
7 | Object.defineProperty(exports, "fileExists", { enumerable: true, get: function () { return fileutils_1.fileExists; } });
|
8 | Object.defineProperty(exports, "directoryExists", { enumerable: true, get: function () { return fileutils_1.directoryExists; } });
|
9 | Object.defineProperty(exports, "isRelativePath", { enumerable: true, get: function () { return fileutils_1.isRelativePath; } });
|
10 | Object.defineProperty(exports, "createDirectory", { enumerable: true, get: function () { return fileutils_1.createDirectory; } });
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function updateJsonFile(path, callback) {
|
20 | const json = (0, fileutils_1.readJsonFile)(path);
|
21 | callback(json);
|
22 | (0, fileutils_1.writeJsonFile)(path, json);
|
23 | }
|
24 | exports.updateJsonFile = updateJsonFile;
|
25 | function copyFile(file, target) {
|
26 | const f = (0, path_1.basename)(file);
|
27 | const source = (0, fs_1.createReadStream)(file);
|
28 | const dest = (0, fs_1.createWriteStream)((0, path_1.resolve)(target, f));
|
29 | source.pipe(dest);
|
30 | source.on('error', (e) => console.error(e));
|
31 | }
|
32 | exports.copyFile = copyFile;
|
33 | function renameSync(from, to, cb) {
|
34 | try {
|
35 | if (!(0, fs_1.existsSync)(from)) {
|
36 | throw new Error(`Path: ${from} does not exist`);
|
37 | }
|
38 | else if ((0, fs_1.existsSync)(to)) {
|
39 | throw new Error(`Path: ${to} already exists`);
|
40 | }
|
41 |
|
42 | const parentPath = (0, path_1.resolve)(to, '..');
|
43 | (0, fileutils_1.createDirectory)(parentPath);
|
44 | (0, fs_1.renameSync)(from, to);
|
45 | cb(null);
|
46 | }
|
47 | catch (e) {
|
48 | cb(e);
|
49 | }
|
50 | }
|
51 | exports.renameSync = renameSync;
|
52 |
|
\ | No newline at end of file |