1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.renameSync = exports.copyFile = exports.updateJsonFile = exports.writeToFile = 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 | function writeToFile(filePath, str) {
|
12 | (0, fs_1.mkdirSync)((0, path_1.dirname)(filePath), { recursive: true });
|
13 | (0, fs_1.writeFileSync)(filePath, str);
|
14 | }
|
15 | exports.writeToFile = writeToFile;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function updateJsonFile(path, callback) {
|
25 | const json = (0, fileutils_1.readJsonFile)(path);
|
26 | callback(json);
|
27 | (0, fileutils_1.writeJsonFile)(path, json);
|
28 | }
|
29 | exports.updateJsonFile = updateJsonFile;
|
30 | function copyFile(file, target) {
|
31 | const f = (0, path_1.basename)(file);
|
32 | const source = (0, fs_1.createReadStream)(file);
|
33 | const dest = (0, fs_1.createWriteStream)((0, path_1.resolve)(target, f));
|
34 | source.pipe(dest);
|
35 | source.on('error', (e) => console.error(e));
|
36 | }
|
37 | exports.copyFile = copyFile;
|
38 | function renameSync(from, to, cb) {
|
39 | try {
|
40 | if (!(0, fs_1.existsSync)(from)) {
|
41 | throw new Error(`Path: ${from} does not exist`);
|
42 | }
|
43 | else if ((0, fs_1.existsSync)(to)) {
|
44 | throw new Error(`Path: ${to} already exists`);
|
45 | }
|
46 |
|
47 | const parentPath = (0, path_1.resolve)(to, '..');
|
48 | (0, fileutils_1.createDirectory)(parentPath);
|
49 | (0, fs_1.renameSync)(from, to);
|
50 | cb(null);
|
51 | }
|
52 | catch (e) {
|
53 | cb(e);
|
54 | }
|
55 | }
|
56 | exports.renameSync = renameSync;
|
57 |
|
\ | No newline at end of file |