@datatruck/cli 0.40.1 → 0.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/BackupAction.js +20 -13
- package/lib/actions/CopyAction.js +20 -12
- package/lib/actions/ExportAction.js +13 -6
- package/lib/actions/RestoreAction.js +13 -6
- package/lib/cli.js +2 -3
- package/lib/repositories/ResticRepository.d.ts +2 -2
- package/lib/tasks/MysqlDumpTask.js +12 -5
- package/lib/tasks/ScriptTask.js +2 -2
- package/lib/utils/async-process.d.ts +0 -5
- package/lib/utils/async.d.ts +0 -1
- package/lib/utils/async.js +1 -2
- package/lib/utils/bytes.js +2 -3
- package/lib/utils/cli.d.ts +0 -1
- package/lib/utils/cli.js +13 -13
- package/lib/utils/cron.js +1 -2
- package/lib/utils/crypto.js +2 -3
- package/lib/utils/datatruck/client.js +3 -3
- package/lib/utils/datatruck/command.js +3 -3
- package/lib/utils/datatruck/config.js +15 -15
- package/lib/utils/datatruck/cron-server.js +1 -2
- package/lib/utils/datatruck/job.js +4 -5
- package/lib/utils/datatruck/paths.js +2 -3
- package/lib/utils/datatruck/report-list.js +1 -2
- package/lib/utils/datatruck/repository-server.d.ts +0 -1
- package/lib/utils/datatruck/repository-server.js +2 -2
- package/lib/utils/datatruck/repository.js +4 -5
- package/lib/utils/datatruck/snapshot.js +1 -2
- package/lib/utils/datatruck/task.js +1 -2
- package/lib/utils/date.js +4 -5
- package/lib/utils/exit.js +4 -5
- package/lib/utils/fs.d.ts +0 -3
- package/lib/utils/fs.js +40 -40
- package/lib/utils/git.d.ts +1 -1
- package/lib/utils/http.d.ts +0 -1
- package/lib/utils/http.js +11 -11
- package/lib/utils/list.d.ts +2 -2
- package/lib/utils/list.js +36 -26
- package/lib/utils/logs.js +3 -3
- package/lib/utils/math.js +2 -2
- package/lib/utils/mongodb.js +2 -3
- package/lib/utils/mysql.d.ts +0 -1
- package/lib/utils/mysql.js +30 -21
- package/lib/utils/object.js +6 -6
- package/lib/utils/options.js +2 -3
- package/lib/utils/process.d.ts +0 -1
- package/lib/utils/process.js +3 -4
- package/lib/utils/progress.d.ts +0 -2
- package/lib/utils/progress.js +3 -3
- package/lib/utils/reportSteps.js +2 -3
- package/lib/utils/spawnSteps.js +2 -3
- package/lib/utils/stream.d.ts +0 -1
- package/lib/utils/stream.js +2 -3
- package/lib/utils/string.js +11 -12
- package/lib/utils/tar.js +6 -7
- package/lib/utils/temp.d.ts +2 -3
- package/lib/utils/temp.js +16 -15
- package/lib/utils/virtual-fs.js +2 -2
- package/lib/utils/watcher.js +1 -2
- package/package.json +14 -14
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.params = exports.dbNameParams = exports.pkgRestorePathParams = exports.pkgExcludeParams = exports.pkgIncludeParams = exports.pkgPathParams = void 0;
|
|
4
|
+
exports.findRepositoryOrFail = findRepositoryOrFail;
|
|
5
|
+
exports.findPackageOrFail = findPackageOrFail;
|
|
6
|
+
exports.findPackageRepositoryConfig = findPackageRepositoryConfig;
|
|
7
|
+
exports.filterRepository = filterRepository;
|
|
8
|
+
exports.sortReposByType = sortReposByType;
|
|
9
|
+
exports.ensureSameRepositoryType = ensureSameRepositoryType;
|
|
10
|
+
exports.filterRepositoryByEnabled = filterRepositoryByEnabled;
|
|
11
|
+
exports.filterPackages = filterPackages;
|
|
12
|
+
exports.resolvePackagePath = resolvePackagePath;
|
|
13
|
+
exports.resolveDatabaseName = resolveDatabaseName;
|
|
14
|
+
exports.resolvePackage = resolvePackage;
|
|
15
|
+
exports.resolvePackages = resolvePackages;
|
|
16
|
+
exports.createPkgFilter = createPkgFilter;
|
|
17
|
+
exports.createTaskFilter = createTaskFilter;
|
|
4
18
|
const error_1 = require("../error");
|
|
5
19
|
const string_1 = require("../string");
|
|
6
20
|
const temp_1 = require("../temp");
|
|
@@ -10,19 +24,16 @@ function findRepositoryOrFail(config, repositoryName) {
|
|
|
10
24
|
throw new error_1.AppError(`Repository '${repositoryName}' not found in the config`);
|
|
11
25
|
return repo;
|
|
12
26
|
}
|
|
13
|
-
exports.findRepositoryOrFail = findRepositoryOrFail;
|
|
14
27
|
function findPackageOrFail(config, packageName) {
|
|
15
28
|
const pkg = config.packages.find((v) => v.name === packageName);
|
|
16
29
|
if (!pkg)
|
|
17
30
|
throw new error_1.AppError(`Package '${packageName}' not found in the config`);
|
|
18
31
|
return pkg;
|
|
19
32
|
}
|
|
20
|
-
exports.findPackageOrFail = findPackageOrFail;
|
|
21
33
|
function findPackageRepositoryConfig(pkg, repo) {
|
|
22
34
|
return pkg.repositoryConfigs?.find((config) => config.type === repo.type &&
|
|
23
35
|
(!config.names || config.names.includes(repo.name)))?.config;
|
|
24
36
|
}
|
|
25
|
-
exports.findPackageRepositoryConfig = findPackageRepositoryConfig;
|
|
26
37
|
function filterRepository(repositories, options) {
|
|
27
38
|
return repositories.filter((r) => {
|
|
28
39
|
if (options.include && !options.include.includes(r.name))
|
|
@@ -34,7 +45,6 @@ function filterRepository(repositories, options) {
|
|
|
34
45
|
return true;
|
|
35
46
|
});
|
|
36
47
|
}
|
|
37
|
-
exports.filterRepository = filterRepository;
|
|
38
48
|
function sortReposByType(repositories, types) {
|
|
39
49
|
const groups = repositories.reduce((group, item) => {
|
|
40
50
|
if (!group[item.type])
|
|
@@ -53,7 +63,6 @@ function sortReposByType(repositories, types) {
|
|
|
53
63
|
}
|
|
54
64
|
return result;
|
|
55
65
|
}
|
|
56
|
-
exports.sortReposByType = sortReposByType;
|
|
57
66
|
function ensureSameRepositoryType(a, b) {
|
|
58
67
|
if (a.type !== b.type) {
|
|
59
68
|
const names = [a.name, b.name].join(" and ");
|
|
@@ -61,7 +70,6 @@ function ensureSameRepositoryType(a, b) {
|
|
|
61
70
|
throw new error_1.AppError(`Incompatible repository types between ${names} (${types})`);
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
|
-
exports.ensureSameRepositoryType = ensureSameRepositoryType;
|
|
65
73
|
function filterRepositoryByEnabled(repository, action) {
|
|
66
74
|
const enabled = repository.enabled ?? true;
|
|
67
75
|
if (typeof enabled === "boolean")
|
|
@@ -69,7 +77,6 @@ function filterRepositoryByEnabled(repository, action) {
|
|
|
69
77
|
const defaults = enabled["defaults"] ?? true;
|
|
70
78
|
return action ? enabled[action] ?? defaults : true;
|
|
71
79
|
}
|
|
72
|
-
exports.filterRepositoryByEnabled = filterRepositoryByEnabled;
|
|
73
80
|
function filterPackages(config, options) {
|
|
74
81
|
const filterRepo = (0, string_1.createPatternFilter)(options.repositoryNames);
|
|
75
82
|
const filterRepoType = (0, string_1.createPatternFilter)(options.repositoryTypes);
|
|
@@ -93,7 +100,6 @@ function filterPackages(config, options) {
|
|
|
93
100
|
filterPkg(pkg.name));
|
|
94
101
|
});
|
|
95
102
|
}
|
|
96
|
-
exports.filterPackages = filterPackages;
|
|
97
103
|
function resolvePackagePath(value, params) {
|
|
98
104
|
return (0, string_1.render)(value, {
|
|
99
105
|
...params,
|
|
@@ -102,11 +108,9 @@ function resolvePackagePath(value, params) {
|
|
|
102
108
|
},
|
|
103
109
|
});
|
|
104
110
|
}
|
|
105
|
-
exports.resolvePackagePath = resolvePackagePath;
|
|
106
111
|
function resolveDatabaseName(value, params) {
|
|
107
112
|
return (0, string_1.render)(value, params);
|
|
108
113
|
}
|
|
109
|
-
exports.resolveDatabaseName = resolveDatabaseName;
|
|
110
114
|
function resolvePackage(pkg, params) {
|
|
111
115
|
pkg = Object.assign({}, pkg);
|
|
112
116
|
const pkgParams = {
|
|
@@ -127,11 +131,9 @@ function resolvePackage(pkg, params) {
|
|
|
127
131
|
});
|
|
128
132
|
return pkg;
|
|
129
133
|
}
|
|
130
|
-
exports.resolvePackage = resolvePackage;
|
|
131
134
|
function resolvePackages(packages, params) {
|
|
132
135
|
return packages.map((pkg) => resolvePackage(pkg, params));
|
|
133
136
|
}
|
|
134
|
-
exports.resolvePackages = resolvePackages;
|
|
135
137
|
exports.pkgPathParams = {
|
|
136
138
|
action: "{action}",
|
|
137
139
|
packageName: "{packageName}",
|
|
@@ -170,7 +172,6 @@ function createPkgFilter(patterns) {
|
|
|
170
172
|
const { include, exclude } = (0, string_1.splitPatterns)(patterns, map);
|
|
171
173
|
return (subject) => (0, string_1.match)(subject, include, exclude);
|
|
172
174
|
}
|
|
173
|
-
exports.createPkgFilter = createPkgFilter;
|
|
174
175
|
function createTaskFilter(patterns) {
|
|
175
176
|
if (patterns === undefined)
|
|
176
177
|
return () => true;
|
|
@@ -181,4 +182,3 @@ function createTaskFilter(patterns) {
|
|
|
181
182
|
return (0, string_1.match)(subject, include, exclude);
|
|
182
183
|
};
|
|
183
184
|
}
|
|
184
|
-
exports.createTaskFilter = createTaskFilter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCronServer =
|
|
3
|
+
exports.createCronServer = createCronServer;
|
|
4
4
|
const ConfigAction_1 = require("../../actions/ConfigAction");
|
|
5
5
|
const cli_1 = require("../cli");
|
|
6
6
|
const cron_1 = require("../cron");
|
|
@@ -86,4 +86,3 @@ async function createCronServer(options) {
|
|
|
86
86
|
};
|
|
87
87
|
return handler;
|
|
88
88
|
}
|
|
89
|
-
exports.createCronServer = createCronServer;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getJobCliOptions = getJobCliOptions;
|
|
4
|
+
exports.runJob = runJob;
|
|
5
|
+
exports.runCronJob = runCronJob;
|
|
4
6
|
const async_process_1 = require("../async-process");
|
|
5
7
|
const cli_1 = require("../cli");
|
|
6
8
|
const fs_1 = require("../fs");
|
|
@@ -32,10 +34,9 @@ function getJobCliOptions(job) {
|
|
|
32
34
|
const Command = command_1.datatruckCommands[job.action];
|
|
33
35
|
const command = new Command({ config: { packages: [], repositories: [] } }, {});
|
|
34
36
|
return (0, options_1.stringifyOptions)(command.optionsConfig, job.action === "prune"
|
|
35
|
-
?
|
|
37
|
+
? { ...job.options, confirm: true }
|
|
36
38
|
: job.options);
|
|
37
39
|
}
|
|
38
|
-
exports.getJobCliOptions = getJobCliOptions;
|
|
39
40
|
async function runJob(job, name, config) {
|
|
40
41
|
const cliOptions = getJobCliOptions(job);
|
|
41
42
|
const [node, bin] = process.argv;
|
|
@@ -56,7 +57,6 @@ async function runJob(job, name, config) {
|
|
|
56
57
|
stdio: "inherit",
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
exports.runJob = runJob;
|
|
60
60
|
async function runCronJob(job, name, config) {
|
|
61
61
|
let pid = 0;
|
|
62
62
|
try {
|
|
@@ -106,4 +106,3 @@ async function runCronJob(job, name, config) {
|
|
|
106
106
|
console.error(error);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
exports.runCronJob = runCronJob;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parsePaths = parsePaths;
|
|
4
|
+
exports.parseBackupPaths = parseBackupPaths;
|
|
4
5
|
const spawnSteps_1 = require("../spawnSteps");
|
|
5
6
|
async function parsePaths(values, options) {
|
|
6
7
|
let paths = [];
|
|
@@ -19,7 +20,6 @@ async function parsePaths(values, options) {
|
|
|
19
20
|
}
|
|
20
21
|
return paths;
|
|
21
22
|
}
|
|
22
|
-
exports.parsePaths = parsePaths;
|
|
23
23
|
async function parseBackupPaths(paths, options) {
|
|
24
24
|
return parsePaths(paths, {
|
|
25
25
|
cwd: options.path,
|
|
@@ -31,4 +31,3 @@ async function parseBackupPaths(paths, options) {
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
exports.parseBackupPaths = parseBackupPaths;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createReportListTasks =
|
|
3
|
+
exports.createReportListTasks = createReportListTasks;
|
|
4
4
|
const error_1 = require("../error");
|
|
5
5
|
const reportSteps_1 = require("../reportSteps");
|
|
6
6
|
const spawnSteps_1 = require("../spawnSteps");
|
|
@@ -55,4 +55,3 @@ function createReportListTasks(list, options) {
|
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
exports.createReportListTasks = createReportListTasks;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.headerKey = void 0;
|
|
4
|
+
exports.createDatatruckRepositoryServer = createDatatruckRepositoryServer;
|
|
4
5
|
const ConfigAction_1 = require("../../actions/ConfigAction");
|
|
5
6
|
const cli_1 = require("../cli");
|
|
6
7
|
const http_1 = require("../http");
|
|
@@ -139,4 +140,3 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
|
|
|
139
140
|
server.keepAliveTimeout = inOptions.keepAliveTimeout;
|
|
140
141
|
return server;
|
|
141
142
|
}
|
|
142
|
-
exports.createDatatruckRepositoryServer = createDatatruckRepositoryServer;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getRepoConstructor = getRepoConstructor;
|
|
4
|
+
exports.createRepo = createRepo;
|
|
5
|
+
exports.createAndInitRepo = createAndInitRepo;
|
|
6
|
+
exports.initSnapshotPath = initSnapshotPath;
|
|
4
7
|
const DatatruckRepository_1 = require("../../repositories/DatatruckRepository");
|
|
5
8
|
const GitRepository_1 = require("../../repositories/GitRepository");
|
|
6
9
|
const ResticRepository_1 = require("../../repositories/ResticRepository");
|
|
@@ -17,21 +20,17 @@ function getRepoConstructor(type) {
|
|
|
17
20
|
throw new error_1.AppError(`Invalid repository type: ${type}`);
|
|
18
21
|
return Constructor;
|
|
19
22
|
}
|
|
20
|
-
exports.getRepoConstructor = getRepoConstructor;
|
|
21
23
|
function createRepo(repository, verbose) {
|
|
22
24
|
const Constructor = getRepoConstructor(repository.type);
|
|
23
25
|
return new Constructor(repository, verbose);
|
|
24
26
|
}
|
|
25
|
-
exports.createRepo = createRepo;
|
|
26
27
|
async function createAndInitRepo(repository, verbose) {
|
|
27
28
|
const repo = createRepo(repository, verbose);
|
|
28
29
|
await repo.init({ options: { verbose } });
|
|
29
30
|
return repo;
|
|
30
31
|
}
|
|
31
|
-
exports.createAndInitRepo = createAndInitRepo;
|
|
32
32
|
async function initSnapshotPath(path, minFreeDiskSpace) {
|
|
33
33
|
await (0, fs_1.initEmptyDir)(path);
|
|
34
34
|
if (minFreeDiskSpace)
|
|
35
35
|
await (0, fs_1.ensureFreeDiskSpace)([path], minFreeDiskSpace);
|
|
36
36
|
}
|
|
37
|
-
exports.initSnapshotPath = initSnapshotPath;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.groupAndFilter =
|
|
3
|
+
exports.groupAndFilter = groupAndFilter;
|
|
4
4
|
const date_1 = require("../date");
|
|
5
5
|
const object_1 = require("../object");
|
|
6
6
|
function groupAndFilter(snapshots, groupKeys, inFilter) {
|
|
@@ -18,4 +18,3 @@ function groupAndFilter(snapshots, groupKeys, inFilter) {
|
|
|
18
18
|
.map((snapshot) => keep.find((v) => v.item === snapshot))
|
|
19
19
|
.filter((v) => !!v);
|
|
20
20
|
}
|
|
21
|
-
exports.groupAndFilter = groupAndFilter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTask =
|
|
3
|
+
exports.createTask = createTask;
|
|
4
4
|
const GitTask_1 = require("../../tasks/GitTask");
|
|
5
5
|
const MariadbTask_1 = require("../../tasks/MariadbTask");
|
|
6
6
|
const MongoDumpTask_1 = require("../../tasks/MongoDumpTask");
|
|
@@ -35,4 +35,3 @@ function createTask(task) {
|
|
|
35
35
|
throw new error_1.AppError(`Invalid task name: ${task["name"]}`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
exports.createTask = createTask;
|
package/lib/utils/date.js
CHANGED
|
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createFilterByLastOptions = createFilterByLastOptions;
|
|
7
|
+
exports.filterByLast = filterByLast;
|
|
8
|
+
exports.createTimer = createTimer;
|
|
9
|
+
exports.duration = duration;
|
|
7
10
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
11
|
const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
|
|
9
12
|
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
@@ -24,7 +27,6 @@ function createFilterByLastOptions(keep) {
|
|
|
24
27
|
lastYearly: keep.keepYearly,
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
|
-
exports.createFilterByLastOptions = createFilterByLastOptions;
|
|
28
30
|
function filterByLast(items, options) {
|
|
29
31
|
const filters = {
|
|
30
32
|
last: {
|
|
@@ -91,7 +93,6 @@ function filterByLast(items, options) {
|
|
|
91
93
|
reasons: [...(reasons.get(item) || [])],
|
|
92
94
|
}));
|
|
93
95
|
}
|
|
94
|
-
exports.filterByLast = filterByLast;
|
|
95
96
|
function createTimer() {
|
|
96
97
|
let startTime = Date.now();
|
|
97
98
|
let endTime;
|
|
@@ -109,8 +110,6 @@ function createTimer() {
|
|
|
109
110
|
};
|
|
110
111
|
return timer;
|
|
111
112
|
}
|
|
112
|
-
exports.createTimer = createTimer;
|
|
113
113
|
function duration(ms) {
|
|
114
114
|
return dayjs_1.default.duration(ms, "ms").format("HH:mm:ss");
|
|
115
115
|
}
|
|
116
|
-
exports.duration = duration;
|
package/lib/utils/exit.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.triggerExitEvent = triggerExitEvent;
|
|
4
|
+
exports.enableExitEvents = enableExitEvents;
|
|
5
|
+
exports.disableExitEvents = disableExitEvents;
|
|
6
|
+
exports.onExit = onExit;
|
|
4
7
|
const eventNames = [
|
|
5
8
|
`exit`,
|
|
6
9
|
`SIGINT`,
|
|
@@ -30,7 +33,6 @@ function triggerExitEvent(eventName, ...args) {
|
|
|
30
33
|
process.exit(5);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
exports.triggerExitEvent = triggerExitEvent;
|
|
34
36
|
function enableExitEvents() {
|
|
35
37
|
disableExitEvents();
|
|
36
38
|
for (const eventName of eventNames) {
|
|
@@ -39,13 +41,11 @@ function enableExitEvents() {
|
|
|
39
41
|
disableExitDisposes.add(() => process.off(eventName, listener));
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
exports.enableExitEvents = enableExitEvents;
|
|
43
44
|
function disableExitEvents() {
|
|
44
45
|
for (const dispose of disableExitDisposes)
|
|
45
46
|
dispose();
|
|
46
47
|
disableExitDisposes.clear();
|
|
47
48
|
}
|
|
48
|
-
exports.disableExitEvents = disableExitEvents;
|
|
49
49
|
function onExit(cb, priority) {
|
|
50
50
|
if (!disableExitDisposes.size)
|
|
51
51
|
enableExitEvents();
|
|
@@ -53,4 +53,3 @@ function onExit(cb, priority) {
|
|
|
53
53
|
listeners.add(listener);
|
|
54
54
|
return () => listeners.delete(listener);
|
|
55
55
|
}
|
|
56
|
-
exports.onExit = onExit;
|
package/lib/utils/fs.d.ts
CHANGED
package/lib/utils/fs.js
CHANGED
|
@@ -3,7 +3,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.parseFileExtensions = exports.isWSLSystem = void 0;
|
|
7
|
+
exports.isEmptyDir = isEmptyDir;
|
|
8
|
+
exports.isLocalDir = isLocalDir;
|
|
9
|
+
exports.mkdirIfNotExists = mkdirIfNotExists;
|
|
10
|
+
exports.ensureEmptyDir = ensureEmptyDir;
|
|
11
|
+
exports.ensureSingleFile = ensureSingleFile;
|
|
12
|
+
exports.ensureExistsDir = ensureExistsDir;
|
|
13
|
+
exports.safeStat = safeStat;
|
|
14
|
+
exports.existsDir = existsDir;
|
|
15
|
+
exports.existsFile = existsFile;
|
|
16
|
+
exports.writeJSONFile = writeJSONFile;
|
|
17
|
+
exports.include = include;
|
|
18
|
+
exports.parseFile = parseFile;
|
|
19
|
+
exports.parsePackageFile = parsePackageFile;
|
|
20
|
+
exports.findFile = findFile;
|
|
21
|
+
exports.fastFolderSizeAsync = fastFolderSizeAsync;
|
|
22
|
+
exports.readPartialFile = readPartialFile;
|
|
23
|
+
exports.safeReaddir = safeReaddir;
|
|
24
|
+
exports.tryReaddir = tryReaddir;
|
|
25
|
+
exports.forEachFile = forEachFile;
|
|
26
|
+
exports.fastglobToGitIgnore = fastglobToGitIgnore;
|
|
27
|
+
exports.writeGitIgnoreList = writeGitIgnoreList;
|
|
28
|
+
exports.copyFileWithStreams = copyFileWithStreams;
|
|
29
|
+
exports.updateFileStats = updateFileStats;
|
|
30
|
+
exports.isNotFoundError = isNotFoundError;
|
|
31
|
+
exports.readTextFile = readTextFile;
|
|
32
|
+
exports.cpy = cpy;
|
|
33
|
+
exports.createProgress = createProgress;
|
|
34
|
+
exports.createFileScanner = createFileScanner;
|
|
35
|
+
exports.createWriteStreamPool = createWriteStreamPool;
|
|
36
|
+
exports.countFileLines = countFileLines;
|
|
37
|
+
exports.fetchData = fetchData;
|
|
38
|
+
exports.safeRename = safeRename;
|
|
39
|
+
exports.tryRm = tryRm;
|
|
40
|
+
exports.initEmptyDir = initEmptyDir;
|
|
41
|
+
exports.fetchDiskStats = fetchDiskStats;
|
|
42
|
+
exports.checkFreeDiskSpace = checkFreeDiskSpace;
|
|
43
|
+
exports.ensureFreeDiskSpace = ensureFreeDiskSpace;
|
|
44
|
+
exports.groupFiles = groupFiles;
|
|
45
|
+
exports.asFile = asFile;
|
|
7
46
|
const pkg_1 = require("../pkg");
|
|
8
47
|
const bytes_1 = require("./bytes");
|
|
9
48
|
const error_1 = require("./error");
|
|
@@ -38,25 +77,21 @@ async function isEmptyDir(path) {
|
|
|
38
77
|
}
|
|
39
78
|
}
|
|
40
79
|
}
|
|
41
|
-
exports.isEmptyDir = isEmptyDir;
|
|
42
80
|
function pathIterator(stream) {
|
|
43
81
|
return stream;
|
|
44
82
|
}
|
|
45
83
|
function isLocalDir(path) {
|
|
46
84
|
return /^[\/\.]|([A-Z]:)/i.test(path);
|
|
47
85
|
}
|
|
48
|
-
exports.isLocalDir = isLocalDir;
|
|
49
86
|
async function mkdirIfNotExists(path) {
|
|
50
87
|
if (!(await existsDir(path)))
|
|
51
88
|
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
52
89
|
return path;
|
|
53
90
|
}
|
|
54
|
-
exports.mkdirIfNotExists = mkdirIfNotExists;
|
|
55
91
|
async function ensureEmptyDir(path) {
|
|
56
92
|
if (!(await isEmptyDir(path)))
|
|
57
93
|
throw new error_1.AppError(`Dir is not empty: ${path}`);
|
|
58
94
|
}
|
|
59
|
-
exports.ensureEmptyDir = ensureEmptyDir;
|
|
60
95
|
async function ensureSingleFile(path) {
|
|
61
96
|
const files = await safeReaddir(path);
|
|
62
97
|
if (files.length !== 1)
|
|
@@ -64,38 +99,31 @@ async function ensureSingleFile(path) {
|
|
|
64
99
|
const [file] = files;
|
|
65
100
|
return (0, path_1.join)(path, file);
|
|
66
101
|
}
|
|
67
|
-
exports.ensureSingleFile = ensureSingleFile;
|
|
68
102
|
async function ensureExistsDir(path) {
|
|
69
103
|
if (!(await existsDir(path)))
|
|
70
104
|
throw new error_1.AppError(`Dir is not created: ${path}`);
|
|
71
105
|
}
|
|
72
|
-
exports.ensureExistsDir = ensureExistsDir;
|
|
73
106
|
async function safeStat(path) {
|
|
74
107
|
try {
|
|
75
108
|
return await (0, promises_1.stat)(path);
|
|
76
109
|
}
|
|
77
110
|
catch (e) { }
|
|
78
111
|
}
|
|
79
|
-
exports.safeStat = safeStat;
|
|
80
112
|
async function existsDir(path) {
|
|
81
113
|
return (await safeStat(path))?.isDirectory() ?? false;
|
|
82
114
|
}
|
|
83
|
-
exports.existsDir = existsDir;
|
|
84
115
|
async function existsFile(path) {
|
|
85
116
|
return (await safeStat(path))?.isFile() ?? false;
|
|
86
117
|
}
|
|
87
|
-
exports.existsFile = existsFile;
|
|
88
118
|
async function writeJSONFile(path, json) {
|
|
89
119
|
await (0, promises_1.writeFile)(path, JSON.stringify(json));
|
|
90
120
|
}
|
|
91
|
-
exports.writeJSONFile = writeJSONFile;
|
|
92
121
|
exports.parseFileExtensions = ["json", "js", "ts", "yaml", "yml"];
|
|
93
122
|
function include(path) {
|
|
94
123
|
path = (0, path_1.resolve)(path);
|
|
95
124
|
delete require.cache[path];
|
|
96
125
|
return require(path);
|
|
97
126
|
}
|
|
98
|
-
exports.include = include;
|
|
99
127
|
async function parseFile(path, jsKey) {
|
|
100
128
|
if (!(0, path_2.isAbsolute)(path))
|
|
101
129
|
path = (0, path_1.join)(process.cwd(), path);
|
|
@@ -115,11 +143,9 @@ async function parseFile(path, jsKey) {
|
|
|
115
143
|
return typeof value === "function" ? await value() : value;
|
|
116
144
|
}
|
|
117
145
|
}
|
|
118
|
-
exports.parseFile = parseFile;
|
|
119
146
|
function parsePackageFile() {
|
|
120
147
|
return pkg_1.pkg;
|
|
121
148
|
}
|
|
122
|
-
exports.parsePackageFile = parsePackageFile;
|
|
123
149
|
async function findFile(sourcePath, baseName, extensions, errorMessage = "Path not found") {
|
|
124
150
|
const info = await (0, promises_1.stat)(sourcePath);
|
|
125
151
|
let path;
|
|
@@ -139,11 +165,9 @@ async function findFile(sourcePath, baseName, extensions, errorMessage = "Path n
|
|
|
139
165
|
throw new Error(errorMessage);
|
|
140
166
|
return path;
|
|
141
167
|
}
|
|
142
|
-
exports.findFile = findFile;
|
|
143
168
|
async function fastFolderSizeAsync(path) {
|
|
144
169
|
return (await (0, util_1.promisify)(fast_folder_size_1.default)(path)) || 0;
|
|
145
170
|
}
|
|
146
|
-
exports.fastFolderSizeAsync = fastFolderSizeAsync;
|
|
147
171
|
async function readPartialFile(path, positions) {
|
|
148
172
|
let result = "";
|
|
149
173
|
const statResult = await (0, promises_1.stat)(path);
|
|
@@ -170,7 +194,6 @@ async function readPartialFile(path, positions) {
|
|
|
170
194
|
.on("close", () => resolve(result));
|
|
171
195
|
});
|
|
172
196
|
}
|
|
173
|
-
exports.readPartialFile = readPartialFile;
|
|
174
197
|
async function safeReaddir(path) {
|
|
175
198
|
try {
|
|
176
199
|
return await (0, promises_1.readdir)(path);
|
|
@@ -187,7 +210,6 @@ async function safeReaddir(path) {
|
|
|
187
210
|
throw anyError;
|
|
188
211
|
}
|
|
189
212
|
}
|
|
190
|
-
exports.safeReaddir = safeReaddir;
|
|
191
213
|
async function tryReaddir(path) {
|
|
192
214
|
try {
|
|
193
215
|
return await safeReaddir(path);
|
|
@@ -198,7 +220,6 @@ async function tryReaddir(path) {
|
|
|
198
220
|
throw error;
|
|
199
221
|
}
|
|
200
222
|
}
|
|
201
|
-
exports.tryReaddir = tryReaddir;
|
|
202
223
|
async function forEachFile(dirPath, cb, includeDir) {
|
|
203
224
|
const files = await safeReaddir(dirPath);
|
|
204
225
|
for (const file of files) {
|
|
@@ -213,7 +234,6 @@ async function forEachFile(dirPath, cb, includeDir) {
|
|
|
213
234
|
}
|
|
214
235
|
}
|
|
215
236
|
}
|
|
216
|
-
exports.forEachFile = forEachFile;
|
|
217
237
|
/**
|
|
218
238
|
* @experimental
|
|
219
239
|
*/
|
|
@@ -222,7 +242,6 @@ function fastglobToGitIgnore(patterns, baseDir) {
|
|
|
222
242
|
// https://git-scm.com/docs/gitignore
|
|
223
243
|
return patterns.map((p) => `${baseDir}/${p}`);
|
|
224
244
|
}
|
|
225
|
-
exports.fastglobToGitIgnore = fastglobToGitIgnore;
|
|
226
245
|
async function writeGitIgnoreList(options) {
|
|
227
246
|
const { outDir } = options;
|
|
228
247
|
const path = (0, path_1.join)(outDir, `.gitignore`);
|
|
@@ -256,7 +275,6 @@ async function writeGitIgnoreList(options) {
|
|
|
256
275
|
});
|
|
257
276
|
return path;
|
|
258
277
|
}
|
|
259
|
-
exports.writeGitIgnoreList = writeGitIgnoreList;
|
|
260
278
|
async function copyFileWithStreams(source, target) {
|
|
261
279
|
const r = (0, fs_1.createReadStream)(source);
|
|
262
280
|
const w = (0, fs_2.createWriteStream)(target);
|
|
@@ -274,17 +292,14 @@ async function copyFileWithStreams(source, target) {
|
|
|
274
292
|
throw error;
|
|
275
293
|
}
|
|
276
294
|
}
|
|
277
|
-
exports.copyFileWithStreams = copyFileWithStreams;
|
|
278
295
|
async function updateFileStats(path, fileInfo) {
|
|
279
296
|
await (0, promises_1.utimes)(path, fileInfo.atime, fileInfo.mtime);
|
|
280
297
|
await (0, promises_1.chmod)(path, fileInfo.mode);
|
|
281
298
|
await (0, promises_1.chown)(path, fileInfo.uid, fileInfo.gid);
|
|
282
299
|
}
|
|
283
|
-
exports.updateFileStats = updateFileStats;
|
|
284
300
|
function isNotFoundError(error) {
|
|
285
301
|
return error.code === "ENOENT";
|
|
286
302
|
}
|
|
287
|
-
exports.isNotFoundError = isNotFoundError;
|
|
288
303
|
async function readTextFile(path, onlyIfExists) {
|
|
289
304
|
let buffer;
|
|
290
305
|
try {
|
|
@@ -297,7 +312,6 @@ async function readTextFile(path, onlyIfExists) {
|
|
|
297
312
|
}
|
|
298
313
|
return buffer.toString();
|
|
299
314
|
}
|
|
300
|
-
exports.readTextFile = readTextFile;
|
|
301
315
|
async function cpy(options) {
|
|
302
316
|
const stats = { paths: 0, files: 0, dirs: 0 };
|
|
303
317
|
const dirs = new Set();
|
|
@@ -403,7 +417,6 @@ async function cpy(options) {
|
|
|
403
417
|
});
|
|
404
418
|
return stats;
|
|
405
419
|
}
|
|
406
|
-
exports.cpy = cpy;
|
|
407
420
|
function createProgress(options) {
|
|
408
421
|
const progress = {
|
|
409
422
|
disposed: false,
|
|
@@ -447,7 +460,6 @@ function createProgress(options) {
|
|
|
447
460
|
};
|
|
448
461
|
return progress;
|
|
449
462
|
}
|
|
450
|
-
exports.createProgress = createProgress;
|
|
451
463
|
async function createFileScanner(options) {
|
|
452
464
|
const progress = createProgress(options);
|
|
453
465
|
Object.assign(progress, {
|
|
@@ -482,7 +494,6 @@ async function createFileScanner(options) {
|
|
|
482
494
|
});
|
|
483
495
|
return progress;
|
|
484
496
|
}
|
|
485
|
-
exports.createFileScanner = createFileScanner;
|
|
486
497
|
function createWriteStreamPool(options) {
|
|
487
498
|
const pool = {};
|
|
488
499
|
const create = (key) => {
|
|
@@ -545,7 +556,6 @@ function createWriteStreamPool(options) {
|
|
|
545
556
|
},
|
|
546
557
|
};
|
|
547
558
|
}
|
|
548
|
-
exports.createWriteStreamPool = createWriteStreamPool;
|
|
549
559
|
function countFileLines(path) {
|
|
550
560
|
let lines = 0;
|
|
551
561
|
const rl = (0, readline_1.createInterface)({
|
|
@@ -560,7 +570,6 @@ function countFileLines(path) {
|
|
|
560
570
|
rl.on("error", reject);
|
|
561
571
|
});
|
|
562
572
|
}
|
|
563
|
-
exports.countFileLines = countFileLines;
|
|
564
573
|
async function fetchData(input, onPath) {
|
|
565
574
|
if (typeof input === "string")
|
|
566
575
|
return input;
|
|
@@ -569,7 +578,6 @@ async function fetchData(input, onPath) {
|
|
|
569
578
|
return (await (0, promises_1.readFile)(path)).toString();
|
|
570
579
|
return null;
|
|
571
580
|
}
|
|
572
|
-
exports.fetchData = fetchData;
|
|
573
581
|
async function safeRename(oldPath, newPath) {
|
|
574
582
|
try {
|
|
575
583
|
await (0, promises_1.rename)(oldPath, newPath);
|
|
@@ -585,14 +593,12 @@ async function safeRename(oldPath, newPath) {
|
|
|
585
593
|
}
|
|
586
594
|
}
|
|
587
595
|
}
|
|
588
|
-
exports.safeRename = safeRename;
|
|
589
596
|
async function tryRm(path) {
|
|
590
597
|
try {
|
|
591
598
|
await (0, promises_1.rm)(path);
|
|
592
599
|
}
|
|
593
600
|
catch (_) { }
|
|
594
601
|
}
|
|
595
|
-
exports.tryRm = tryRm;
|
|
596
602
|
async function initEmptyDir(path) {
|
|
597
603
|
if (!path)
|
|
598
604
|
throw new Error(`Path is not defined`);
|
|
@@ -600,21 +606,18 @@ async function initEmptyDir(path) {
|
|
|
600
606
|
await ensureEmptyDir(path);
|
|
601
607
|
return path;
|
|
602
608
|
}
|
|
603
|
-
exports.initEmptyDir = initEmptyDir;
|
|
604
609
|
async function fetchDiskStats(path) {
|
|
605
610
|
const fs = await (0, promises_1.statfs)(path);
|
|
606
611
|
const total = fs.bsize * fs.blocks;
|
|
607
612
|
const free = fs.bsize * fs.bavail;
|
|
608
613
|
return { total, free };
|
|
609
614
|
}
|
|
610
|
-
exports.fetchDiskStats = fetchDiskStats;
|
|
611
615
|
async function checkFreeDiskSpace(stat, inSize) {
|
|
612
616
|
const humanSize = typeof inSize === "number" ? (0, bytes_1.formatBytes)(inSize) : inSize;
|
|
613
617
|
const size = typeof inSize === "number" ? inSize : (0, bytes_1.parseSize)(inSize);
|
|
614
618
|
if (stat.free < size)
|
|
615
619
|
throw new Error(`Free disk space is less than ${humanSize}: ${(0, bytes_1.formatBytes)(stat.free)}/${(0, bytes_1.formatBytes)(stat.total)}`);
|
|
616
620
|
}
|
|
617
|
-
exports.checkFreeDiskSpace = checkFreeDiskSpace;
|
|
618
621
|
async function ensureFreeDiskSpace(input, inSize) {
|
|
619
622
|
if (Array.isArray(input)) {
|
|
620
623
|
for (const path of input) {
|
|
@@ -626,7 +629,6 @@ async function ensureFreeDiskSpace(input, inSize) {
|
|
|
626
629
|
await checkFreeDiskSpace(input, inSize);
|
|
627
630
|
}
|
|
628
631
|
}
|
|
629
|
-
exports.ensureFreeDiskSpace = ensureFreeDiskSpace;
|
|
630
632
|
function groupFiles(inFiles, suffixes, gzSuffix = ".tar.gz") {
|
|
631
633
|
const compressed = {};
|
|
632
634
|
if (suffixes) {
|
|
@@ -650,7 +652,6 @@ function groupFiles(inFiles, suffixes, gzSuffix = ".tar.gz") {
|
|
|
650
652
|
}
|
|
651
653
|
return [Object.keys(grouped), compressed];
|
|
652
654
|
}
|
|
653
|
-
exports.groupFiles = groupFiles;
|
|
654
655
|
async function asFile(input) {
|
|
655
656
|
if (typeof input === "string") {
|
|
656
657
|
const dir = await (0, temp_1.mkTmpDir)("text-as-file");
|
|
@@ -667,4 +668,3 @@ async function asFile(input) {
|
|
|
667
668
|
return [input.path, undefined];
|
|
668
669
|
}
|
|
669
670
|
}
|
|
670
|
-
exports.asFile = asFile;
|
package/lib/utils/git.d.ts
CHANGED