@datatruck/cli 0.36.8 → 0.38.0
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/config.schema.json +168 -108
- package/lib/actions/BackupAction.d.ts +61 -20
- package/lib/actions/BackupAction.js +43 -17
- package/lib/actions/CleanCacheAction.d.ts +6 -7
- package/lib/actions/CleanCacheAction.js +2 -1
- package/lib/actions/ConfigAction.d.ts +3 -5
- package/lib/actions/ConfigAction.js +0 -1
- package/lib/actions/CopyAction.d.ts +43 -12
- package/lib/actions/CopyAction.js +31 -4
- package/lib/actions/ExportAction.d.ts +94 -0
- package/lib/actions/ExportAction.js +236 -0
- package/lib/actions/InitAction.d.ts +17 -7
- package/lib/actions/InitAction.js +9 -1
- package/lib/actions/PruneAction.d.ts +76 -17
- package/lib/actions/PruneAction.js +62 -2
- package/lib/actions/RestoreAction.d.ts +61 -22
- package/lib/actions/RestoreAction.js +46 -58
- package/lib/actions/SnapshotsAction.d.ts +80 -21
- package/lib/actions/SnapshotsAction.js +82 -1
- package/lib/cli.d.ts +0 -3
- package/lib/cli.js +31 -56
- package/lib/commands/BackupCommand.d.ts +121 -13
- package/lib/commands/BackupCommand.js +29 -54
- package/lib/commands/CleanCacheCommand.d.ts +10 -3
- package/lib/commands/CleanCacheCommand.js +14 -6
- package/lib/commands/CommandAbstract.d.ts +11 -10
- package/lib/commands/CommandAbstract.js +6 -9
- package/lib/commands/ConfigCommand.d.ts +72 -9
- package/lib/commands/ConfigCommand.js +36 -28
- package/lib/commands/CopyCommand.d.ts +103 -10
- package/lib/commands/CopyCommand.js +25 -44
- package/lib/commands/ExportCommand.d.ts +143 -0
- package/lib/commands/ExportCommand.js +50 -0
- package/lib/commands/InitCommand.d.ts +43 -7
- package/lib/commands/InitCommand.js +22 -19
- package/lib/commands/PruneCommand.d.ts +237 -17
- package/lib/commands/PruneCommand.js +27 -99
- package/lib/commands/RestoreCommand.d.ts +127 -13
- package/lib/commands/RestoreCommand.js +27 -53
- package/lib/commands/RunCommand.d.ts +29 -0
- package/lib/commands/RunCommand.js +44 -0
- package/lib/commands/SnapshotsCommand.d.ts +240 -23
- package/lib/commands/SnapshotsCommand.js +23 -101
- package/lib/commands/StartServerCommand.d.ts +10 -3
- package/lib/commands/StartServerCommand.js +23 -15
- package/lib/repositories/DatatruckRepository.js +1 -1
- package/lib/tasks/MssqlTask.js +1 -1
- package/lib/tasks/MysqlDumpTask.js +1 -1
- package/lib/tasks/SqlDumpTaskAbstract.js +2 -2
- package/lib/utils/cli.d.ts +1 -18
- package/lib/utils/cli.js +9 -49
- package/lib/utils/datatruck/command.d.ts +8 -5
- package/lib/utils/datatruck/command.js +8 -4
- package/lib/utils/datatruck/config-type.d.ts +4 -0
- package/lib/utils/datatruck/cron-server.d.ts +8 -39
- package/lib/utils/datatruck/cron-server.js +35 -57
- package/lib/utils/datatruck/job.d.ts +41 -0
- package/lib/utils/datatruck/job.js +82 -0
- package/lib/utils/datatruck/report-list.js +1 -1
- package/lib/utils/datatruck/repository.d.ts +1 -0
- package/lib/utils/datatruck/repository.js +8 -1
- package/lib/utils/list.d.ts +5 -0
- package/lib/utils/list.js +9 -0
- package/lib/utils/math.js +1 -1
- package/lib/utils/object.d.ts +5 -0
- package/lib/utils/object.js +10 -1
- package/lib/utils/options.d.ts +24 -0
- package/lib/utils/options.js +94 -0
- package/lib/utils/progress.js +1 -1
- package/lib/utils/restic.js +1 -1
- package/lib/utils/string.d.ts +2 -1
- package/lib/utils/string.js +5 -1
- package/lib/utils/watcher.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyOptions = exports.createCommand = void 0;
|
|
4
|
+
const string_1 = require("./string");
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
function createCommand(config, action) {
|
|
7
|
+
const command = commander_1.program.createCommand(config.name);
|
|
8
|
+
const argumentOptions = [];
|
|
9
|
+
if (config.alias)
|
|
10
|
+
command.alias(config.alias);
|
|
11
|
+
for (const name in config.options) {
|
|
12
|
+
const option = config.options[name];
|
|
13
|
+
const flag = option.flag ?? name;
|
|
14
|
+
const description = `${option.description}${option.defaults ? ` (defaults: ${option.defaults})` : ""}`;
|
|
15
|
+
if (flag === false) {
|
|
16
|
+
const arg = new commander_1.Argument(name, description);
|
|
17
|
+
if (option.required) {
|
|
18
|
+
arg.argRequired();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
arg.argOptional();
|
|
22
|
+
}
|
|
23
|
+
command.addArgument(arg);
|
|
24
|
+
argumentOptions.push(name);
|
|
25
|
+
}
|
|
26
|
+
else if (typeof flag === "string") {
|
|
27
|
+
const flags = [
|
|
28
|
+
option.shortFlag ? `-${option.shortFlag},` : "",
|
|
29
|
+
`--${name}`,
|
|
30
|
+
option.value !== "boolean"
|
|
31
|
+
? option.value === "array"
|
|
32
|
+
? " <values>"
|
|
33
|
+
: " <value>"
|
|
34
|
+
: "",
|
|
35
|
+
].join("");
|
|
36
|
+
const opt = new commander_1.Option(flags, description);
|
|
37
|
+
opt.makeOptionMandatory(!!option.required);
|
|
38
|
+
command.addOption(opt);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const parsers = {
|
|
42
|
+
number: Number,
|
|
43
|
+
array: string_1.parseStringList,
|
|
44
|
+
};
|
|
45
|
+
return command.action(async (...args) => {
|
|
46
|
+
const inlineValues = args.slice(0, argumentOptions.length);
|
|
47
|
+
const cliOptions = args[argumentOptions.length] || {};
|
|
48
|
+
const commandOptions = {};
|
|
49
|
+
for (const name in config.options) {
|
|
50
|
+
const option = config.options[name];
|
|
51
|
+
if (option.flag !== false) {
|
|
52
|
+
const parse = typeof option.value === "string" ? parsers[option.value] : undefined;
|
|
53
|
+
const cliValue = cliOptions[option.flag ?? name] ?? option.defaults;
|
|
54
|
+
commandOptions[name] = parse ? parse(cliValue) : cliValue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const options = argumentOptions.reduce((result, inlineOption, index) => {
|
|
58
|
+
const value = inlineValues[index];
|
|
59
|
+
if (value !== undefined)
|
|
60
|
+
result[inlineOption] = value;
|
|
61
|
+
return result;
|
|
62
|
+
}, commandOptions);
|
|
63
|
+
return await action(options);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.createCommand = createCommand;
|
|
67
|
+
function stringifyOptions(options, object) {
|
|
68
|
+
const result = [];
|
|
69
|
+
const prepend = [];
|
|
70
|
+
for (const key in options) {
|
|
71
|
+
const option = options[key];
|
|
72
|
+
const value = object[key];
|
|
73
|
+
if (value !== undefined)
|
|
74
|
+
continue;
|
|
75
|
+
if (option.flag === false) {
|
|
76
|
+
prepend.push(value);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const flag = option.shortFlag
|
|
80
|
+
? `-${option.shortFlag}`
|
|
81
|
+
: `--${option.flag ?? option.shortFlag}`;
|
|
82
|
+
if (option.value === "boolean") {
|
|
83
|
+
if (option.value)
|
|
84
|
+
result.push(flag);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
result.push(flag);
|
|
88
|
+
result.push(`${value}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [...prepend, ...result];
|
|
93
|
+
}
|
|
94
|
+
exports.stringifyOptions = stringifyOptions;
|
package/lib/utils/progress.js
CHANGED
|
@@ -67,7 +67,7 @@ class ProgressManager {
|
|
|
67
67
|
this.keydownListener = undefined;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
create(input, delay =
|
|
70
|
+
create(input, delay = 1_000) {
|
|
71
71
|
const update = (progress, force) => {
|
|
72
72
|
const text = this.renderProgress(progress, force);
|
|
73
73
|
if (typeof text === "string") {
|
package/lib/utils/restic.js
CHANGED
|
@@ -165,7 +165,7 @@ class Restic {
|
|
|
165
165
|
}
|
|
166
166
|
async restore(options) {
|
|
167
167
|
let progressTimeout;
|
|
168
|
-
const progressInterval = options.progressInterval ??
|
|
168
|
+
const progressInterval = options.progressInterval ?? 30_000;
|
|
169
169
|
async function progressRutine() {
|
|
170
170
|
try {
|
|
171
171
|
const total_bytes = await (0, fs_1.fastFolderSizeAsync)(options.target);
|
package/lib/utils/string.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare function snakeCase(value: string, char?: string): string;
|
|
2
|
+
export declare function camelize(input: string): string;
|
|
2
3
|
export declare function render(subject: string, data: Record<string, string | undefined>): string;
|
|
3
4
|
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
4
|
-
export declare function parseStringList<T>(value: string | undefined, validValues?: T[], defaultsValues?: NoInfer<T>[] | true): T[];
|
|
5
|
+
export declare function parseStringList<T = string>(value: string | undefined, validValues?: T[], defaultsValues?: NoInfer<T>[] | true): T[];
|
|
5
6
|
export type Uri = {
|
|
6
7
|
protocol?: "http" | "https";
|
|
7
8
|
host?: string;
|
package/lib/utils/string.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareJsons = exports.undefIfEmpty = exports.endsWith = exports.createPatternFilter = exports.match = exports.splitPatterns = exports.formatUri = exports.parseStringList = exports.render = exports.snakeCase = void 0;
|
|
3
|
+
exports.compareJsons = exports.undefIfEmpty = exports.endsWith = exports.createPatternFilter = exports.match = exports.splitPatterns = exports.formatUri = exports.parseStringList = exports.render = exports.camelize = exports.snakeCase = void 0;
|
|
4
4
|
const error_1 = require("./error");
|
|
5
5
|
const micromatch_1 = require("micromatch");
|
|
6
6
|
function snakeCase(value, char = "_") {
|
|
7
7
|
return value.replace(/[A-Z]/g, (letter) => `${char}${letter.toLowerCase()}`);
|
|
8
8
|
}
|
|
9
9
|
exports.snakeCase = snakeCase;
|
|
10
|
+
function camelize(input) {
|
|
11
|
+
return input.replace(/-./g, (x) => x[1].toUpperCase());
|
|
12
|
+
}
|
|
13
|
+
exports.camelize = camelize;
|
|
10
14
|
function render(subject, data) {
|
|
11
15
|
return subject.replace(/{([\w\./]*)}/g, function (match, name) {
|
|
12
16
|
if (!name.length) {
|
package/lib/utils/watcher.js
CHANGED
|
@@ -22,7 +22,7 @@ function createWatcher(options) {
|
|
|
22
22
|
start: () => {
|
|
23
23
|
clearInterval(interval);
|
|
24
24
|
rutine(true).finally(() => {
|
|
25
|
-
interval = setInterval(rutine, options.interval ??
|
|
25
|
+
interval = setInterval(rutine, options.interval ?? 5_000);
|
|
26
26
|
});
|
|
27
27
|
},
|
|
28
28
|
stop: () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datatruck/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Tool for creating and managing backups",
|
|
5
5
|
"homepage": "https://github.com/swordev/datatruck#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"config.schema.json"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@supercharge/promise-pool": "^3.
|
|
29
|
+
"@supercharge/promise-pool": "^3.2.0",
|
|
30
30
|
"ajv": "^8.12.0",
|
|
31
31
|
"async": "^3.2.5",
|
|
32
32
|
"chalk": "^4.1.2",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"fast-glob": "^3.3.2",
|
|
38
38
|
"listr2": "^8.0.2",
|
|
39
39
|
"micromatch": "^4.0.5",
|
|
40
|
-
"mysql2": "^3.9.
|
|
40
|
+
"mysql2": "^3.9.3",
|
|
41
41
|
"tty-table": "^4.2.3",
|
|
42
|
-
"yaml": "^2.
|
|
42
|
+
"yaml": "^2.4.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/async": "^3.2.24",
|