@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
|
@@ -4,16 +4,42 @@ import type { Config, RepositoryConfig } from "../utils/datatruck/config-type";
|
|
|
4
4
|
import { ReportListTaskContext } from "../utils/datatruck/report-list";
|
|
5
5
|
import { Listr3TaskResultEnd } from "../utils/list";
|
|
6
6
|
import { StrictMap } from "../utils/object";
|
|
7
|
+
import { InferOptions } from "../utils/options";
|
|
7
8
|
import { Progress, ProgressMode } from "../utils/progress";
|
|
8
9
|
import { StdStreams } from "../utils/stream";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export declare const copyActionOptions: {
|
|
11
|
+
repositoryNames2: {
|
|
12
|
+
description: string;
|
|
13
|
+
shortFlag: string;
|
|
14
|
+
value: "array";
|
|
15
|
+
};
|
|
16
|
+
packageNames: {
|
|
17
|
+
description: string;
|
|
18
|
+
shortFlag: string;
|
|
19
|
+
value: "array";
|
|
20
|
+
};
|
|
21
|
+
packageTaskNames: {
|
|
22
|
+
description: string;
|
|
23
|
+
shortFlag: string;
|
|
24
|
+
value: "array";
|
|
25
|
+
};
|
|
26
|
+
ids: {
|
|
27
|
+
description: string;
|
|
28
|
+
shortFlag: string;
|
|
29
|
+
value: "array";
|
|
30
|
+
};
|
|
31
|
+
last: {
|
|
32
|
+
description: string;
|
|
33
|
+
shortFlag: string;
|
|
34
|
+
value: "number";
|
|
35
|
+
};
|
|
36
|
+
repositoryName: {
|
|
37
|
+
description: string;
|
|
38
|
+
shortFlag: string;
|
|
39
|
+
required: true;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export type CopyActionOptions = InferOptions<typeof copyActionOptions> & {
|
|
17
43
|
verbose?: boolean;
|
|
18
44
|
tty?: "auto" | boolean;
|
|
19
45
|
progress?: ProgressMode;
|
|
@@ -34,13 +60,14 @@ export type Context = {
|
|
|
34
60
|
bytes: number;
|
|
35
61
|
};
|
|
36
62
|
} & ReportListTaskContext;
|
|
37
|
-
export declare class CopyAction
|
|
63
|
+
export declare class CopyAction {
|
|
38
64
|
readonly config: Config;
|
|
39
|
-
readonly options:
|
|
40
|
-
constructor(config: Config, options:
|
|
65
|
+
readonly options: CopyActionOptions;
|
|
66
|
+
constructor(config: Config, options: CopyActionOptions);
|
|
41
67
|
dataFormat(result: Listr3TaskResultEnd<Context>[], options?: {
|
|
42
68
|
streams?: StdStreams;
|
|
43
69
|
verbose?: number;
|
|
70
|
+
errors?: Error[];
|
|
44
71
|
}): DataFormat;
|
|
45
72
|
protected fetchSnapshots(repo: RepositoryAbstract<any>): Promise<Snapshot[]>;
|
|
46
73
|
protected createSourceRepoMap(): StrictMap<[Pick<Snapshot, "packageName" | "id">, Pick<RepositoryConfig, "type">], RepositoryAbstract<any>>;
|
|
@@ -54,5 +81,9 @@ export declare class CopyAction<TRequired extends boolean = true> {
|
|
|
54
81
|
}): Promise<{
|
|
55
82
|
bytes: number;
|
|
56
83
|
}>;
|
|
57
|
-
exec(): Promise<
|
|
84
|
+
exec(): Promise<{
|
|
85
|
+
result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<Context>)[];
|
|
86
|
+
exitCode: number;
|
|
87
|
+
errors: Error[];
|
|
88
|
+
}>;
|
|
58
89
|
}
|
|
@@ -48,7 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.CopyAction = void 0;
|
|
51
|
+
exports.CopyAction = exports.copyActionOptions = void 0;
|
|
52
52
|
const bytes_1 = require("../utils/bytes");
|
|
53
53
|
const cli_1 = require("../utils/cli");
|
|
54
54
|
const data_format_1 = require("../utils/data-format");
|
|
@@ -62,8 +62,35 @@ const list_1 = require("../utils/list");
|
|
|
62
62
|
const object_1 = require("../utils/object");
|
|
63
63
|
const progress_1 = require("../utils/progress");
|
|
64
64
|
const temp_1 = require("../utils/temp");
|
|
65
|
+
const SnapshotsAction_1 = require("./SnapshotsAction");
|
|
65
66
|
const chalk_1 = __importDefault(require("chalk"));
|
|
66
67
|
const os_1 = require("os");
|
|
68
|
+
exports.copyActionOptions = {
|
|
69
|
+
ids: {
|
|
70
|
+
description: "Filter by identifiers",
|
|
71
|
+
shortFlag: "i",
|
|
72
|
+
value: "array",
|
|
73
|
+
},
|
|
74
|
+
last: {
|
|
75
|
+
description: "Last snapshots",
|
|
76
|
+
shortFlag: "l",
|
|
77
|
+
value: "number",
|
|
78
|
+
},
|
|
79
|
+
repositoryName: {
|
|
80
|
+
description: "Filter by repository name",
|
|
81
|
+
shortFlag: "r",
|
|
82
|
+
required: true,
|
|
83
|
+
},
|
|
84
|
+
...(0, object_1.pickProps)(SnapshotsAction_1.snapshotsActionOptions, {
|
|
85
|
+
packageNames: true,
|
|
86
|
+
packageTaskNames: true,
|
|
87
|
+
}),
|
|
88
|
+
repositoryNames2: {
|
|
89
|
+
description: "Filter by repository names",
|
|
90
|
+
shortFlag: "r2",
|
|
91
|
+
value: "array",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
67
94
|
class CopyAction {
|
|
68
95
|
config;
|
|
69
96
|
options;
|
|
@@ -122,7 +149,7 @@ class CopyAction {
|
|
|
122
149
|
renderTitle(item, true),
|
|
123
150
|
renderData(item, result, "table"),
|
|
124
151
|
(0, date_1.duration)(item.elapsed),
|
|
125
|
-
(0, cli_1.renderError)(item.error, options.
|
|
152
|
+
(0, cli_1.renderError)(item.error, options.errors?.indexOf(item.error)),
|
|
126
153
|
]),
|
|
127
154
|
},
|
|
128
155
|
});
|
|
@@ -156,7 +183,7 @@ class CopyAction {
|
|
|
156
183
|
await repo.restore({
|
|
157
184
|
options: {
|
|
158
185
|
verbose: this.options.verbose,
|
|
159
|
-
|
|
186
|
+
id: snapshot.id,
|
|
160
187
|
},
|
|
161
188
|
snapshot: { id: snapshot.id, date: snapshot.date },
|
|
162
189
|
package: { name: snapshot.packageName },
|
|
@@ -330,7 +357,7 @@ class CopyAction {
|
|
|
330
357
|
},
|
|
331
358
|
}),
|
|
332
359
|
])
|
|
333
|
-
.
|
|
360
|
+
.execAndParse(this.options.verbose);
|
|
334
361
|
}
|
|
335
362
|
}
|
|
336
363
|
exports.CopyAction = CopyAction;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DataFormat } from "../utils/data-format";
|
|
2
|
+
import type { Config } from "../utils/datatruck/config-type";
|
|
3
|
+
import { Listr3TaskResultEnd } from "../utils/list";
|
|
4
|
+
import { InferOptions } from "../utils/options";
|
|
5
|
+
import { Progress, ProgressMode } from "../utils/progress";
|
|
6
|
+
import { StdStreams } from "../utils/stream";
|
|
7
|
+
import { ExtendedSnapshot } from "./SnapshotsAction";
|
|
8
|
+
export declare const exportActionOptions: {
|
|
9
|
+
repositoryNames: {
|
|
10
|
+
description: string;
|
|
11
|
+
shortFlag: string;
|
|
12
|
+
value: "array";
|
|
13
|
+
};
|
|
14
|
+
repositoryTypes: {
|
|
15
|
+
description: string;
|
|
16
|
+
shortFlag: string;
|
|
17
|
+
value: "array";
|
|
18
|
+
};
|
|
19
|
+
packageNames: {
|
|
20
|
+
description: string;
|
|
21
|
+
shortFlag: string;
|
|
22
|
+
value: "array";
|
|
23
|
+
};
|
|
24
|
+
packageTaskNames: {
|
|
25
|
+
description: string;
|
|
26
|
+
shortFlag: string;
|
|
27
|
+
value: "array";
|
|
28
|
+
};
|
|
29
|
+
tags: {
|
|
30
|
+
description: string;
|
|
31
|
+
shortFlag: string;
|
|
32
|
+
value: "array";
|
|
33
|
+
};
|
|
34
|
+
packageConfig: {
|
|
35
|
+
description: string;
|
|
36
|
+
shortFlag: string;
|
|
37
|
+
};
|
|
38
|
+
id: {
|
|
39
|
+
description: string;
|
|
40
|
+
shortFlag: string;
|
|
41
|
+
required: true;
|
|
42
|
+
};
|
|
43
|
+
outPath: {
|
|
44
|
+
description: string;
|
|
45
|
+
required: true;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type ExportActionOptions = InferOptions<typeof exportActionOptions> & {
|
|
49
|
+
verbose?: boolean;
|
|
50
|
+
};
|
|
51
|
+
type Context = {
|
|
52
|
+
snapshots: {
|
|
53
|
+
id: string;
|
|
54
|
+
packages: number;
|
|
55
|
+
};
|
|
56
|
+
task: {
|
|
57
|
+
taskName: string;
|
|
58
|
+
packageName: string;
|
|
59
|
+
};
|
|
60
|
+
export: ExtendedSnapshot;
|
|
61
|
+
};
|
|
62
|
+
export declare class ExportAction {
|
|
63
|
+
readonly config: Config;
|
|
64
|
+
readonly options: ExportActionOptions;
|
|
65
|
+
readonly settings: {
|
|
66
|
+
tty?: "auto" | boolean;
|
|
67
|
+
progress?: ProgressMode;
|
|
68
|
+
streams?: StdStreams;
|
|
69
|
+
};
|
|
70
|
+
constructor(config: Config, options: ExportActionOptions, settings: {
|
|
71
|
+
tty?: "auto" | boolean;
|
|
72
|
+
progress?: ProgressMode;
|
|
73
|
+
streams?: StdStreams;
|
|
74
|
+
});
|
|
75
|
+
protected restore(data: {
|
|
76
|
+
pkg: {
|
|
77
|
+
name: string;
|
|
78
|
+
};
|
|
79
|
+
snapshotPath: string;
|
|
80
|
+
snapshot: ExtendedSnapshot;
|
|
81
|
+
onProgress: (progress: Progress) => void;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
dataFormat(result: Listr3TaskResultEnd<Context>[], options?: {
|
|
84
|
+
streams?: StdStreams;
|
|
85
|
+
verbose?: number;
|
|
86
|
+
errors?: Error[];
|
|
87
|
+
}): DataFormat;
|
|
88
|
+
exec(): Promise<{
|
|
89
|
+
result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<Context>)[];
|
|
90
|
+
exitCode: number;
|
|
91
|
+
errors: Error[];
|
|
92
|
+
}>;
|
|
93
|
+
}
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
3
|
+
if (value !== null && value !== void 0) {
|
|
4
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
5
|
+
var dispose;
|
|
6
|
+
if (async) {
|
|
7
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
8
|
+
dispose = value[Symbol.asyncDispose];
|
|
9
|
+
}
|
|
10
|
+
if (dispose === void 0) {
|
|
11
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.dispose];
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
16
|
+
}
|
|
17
|
+
else if (async) {
|
|
18
|
+
env.stack.push({ async: true });
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
23
|
+
return function (env) {
|
|
24
|
+
function fail(e) {
|
|
25
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
26
|
+
env.hasError = true;
|
|
27
|
+
}
|
|
28
|
+
function next() {
|
|
29
|
+
while (env.stack.length) {
|
|
30
|
+
var rec = env.stack.pop();
|
|
31
|
+
try {
|
|
32
|
+
var result = rec.dispose && rec.dispose.call(rec.value);
|
|
33
|
+
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
fail(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (env.hasError) throw env.error;
|
|
40
|
+
}
|
|
41
|
+
return next();
|
|
42
|
+
};
|
|
43
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
+
var e = new Error(message);
|
|
45
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
+
});
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.ExportAction = exports.exportActionOptions = void 0;
|
|
52
|
+
const DatatruckRepository_1 = require("../repositories/DatatruckRepository");
|
|
53
|
+
const cli_1 = require("../utils/cli");
|
|
54
|
+
const data_format_1 = require("../utils/data-format");
|
|
55
|
+
const config_1 = require("../utils/datatruck/config");
|
|
56
|
+
const repository_1 = require("../utils/datatruck/repository");
|
|
57
|
+
const date_1 = require("../utils/date");
|
|
58
|
+
const error_1 = require("../utils/error");
|
|
59
|
+
const list_1 = require("../utils/list");
|
|
60
|
+
const object_1 = require("../utils/object");
|
|
61
|
+
const progress_1 = require("../utils/progress");
|
|
62
|
+
const temp_1 = require("../utils/temp");
|
|
63
|
+
const SnapshotsAction_1 = require("./SnapshotsAction");
|
|
64
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
65
|
+
const path_1 = require("path");
|
|
66
|
+
exports.exportActionOptions = {
|
|
67
|
+
id: {
|
|
68
|
+
description: "Filter by snapshot id",
|
|
69
|
+
shortFlag: "i",
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
outPath: {
|
|
73
|
+
description: "Out path",
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
...(0, object_1.pickProps)(SnapshotsAction_1.snapshotsActionOptions, {
|
|
77
|
+
tags: true,
|
|
78
|
+
packageNames: true,
|
|
79
|
+
packageTaskNames: true,
|
|
80
|
+
packageConfig: true,
|
|
81
|
+
repositoryNames: true,
|
|
82
|
+
repositoryTypes: true,
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
class ExportAction {
|
|
86
|
+
config;
|
|
87
|
+
options;
|
|
88
|
+
settings;
|
|
89
|
+
constructor(config, options, settings) {
|
|
90
|
+
this.config = config;
|
|
91
|
+
this.options = options;
|
|
92
|
+
this.settings = settings;
|
|
93
|
+
}
|
|
94
|
+
async restore(data) {
|
|
95
|
+
let { snapshot, snapshotPath, pkg } = data;
|
|
96
|
+
await (0, repository_1.initSnapshotPath)(snapshotPath, this.config.minFreeDiskSpace);
|
|
97
|
+
const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
|
|
98
|
+
const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
|
|
99
|
+
await repo.restore({
|
|
100
|
+
options: this.options,
|
|
101
|
+
snapshot: data.snapshot,
|
|
102
|
+
package: pkg,
|
|
103
|
+
snapshotPath: snapshotPath,
|
|
104
|
+
packageConfig: undefined,
|
|
105
|
+
onProgress: data.onProgress,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
dataFormat(result, options = {}) {
|
|
109
|
+
const renderTitle = (item, color) => {
|
|
110
|
+
let title = item.key.slice(0, 1).toUpperCase() + item.key.slice(1);
|
|
111
|
+
return item.key === "export" && color ? chalk_1.default.cyan(title) : title;
|
|
112
|
+
};
|
|
113
|
+
const renderData = (item, color, result = []) => {
|
|
114
|
+
const g = (v) => (color ? `${chalk_1.default.gray(`(${v})`)}` : `(${v})`);
|
|
115
|
+
return (0, cli_1.renderListTaskItem)(item, color, {
|
|
116
|
+
snapshots: (data) => [
|
|
117
|
+
data.id.slice(0, 8),
|
|
118
|
+
g(`${data.packages} packages`),
|
|
119
|
+
],
|
|
120
|
+
task: (data) => [data.packageName, g(data.taskName)],
|
|
121
|
+
export: (data) => [data.packageName, g(data.repositoryName)],
|
|
122
|
+
summary: (data) => ({
|
|
123
|
+
errors: data.errors,
|
|
124
|
+
exports: result.filter((r) => !r.error && r.key === "export").length,
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return new data_format_1.DataFormat({
|
|
129
|
+
streams: options.streams,
|
|
130
|
+
json: result,
|
|
131
|
+
table: {
|
|
132
|
+
headers: [
|
|
133
|
+
{ value: "", width: 3 },
|
|
134
|
+
{ value: "Title", width: 15 },
|
|
135
|
+
{ value: "Data" },
|
|
136
|
+
{ value: "Duration", width: 10 },
|
|
137
|
+
{ value: "Error", width: 50 },
|
|
138
|
+
],
|
|
139
|
+
rows: () => result.map((item) => [
|
|
140
|
+
(0, cli_1.renderResult)(item.error),
|
|
141
|
+
renderTitle(item, true),
|
|
142
|
+
renderData(item, true, result),
|
|
143
|
+
(0, date_1.duration)(item.elapsed),
|
|
144
|
+
(0, cli_1.renderError)(item.error, options.errors?.indexOf(item.error)),
|
|
145
|
+
]),
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async exec() {
|
|
150
|
+
const { options, settings } = this;
|
|
151
|
+
const gc = new temp_1.GargabeCollector();
|
|
152
|
+
const pm = new progress_1.ProgressManager({
|
|
153
|
+
verbose: options.verbose,
|
|
154
|
+
tty: settings.tty,
|
|
155
|
+
mode: settings.progress,
|
|
156
|
+
});
|
|
157
|
+
const l = new list_1.Listr3({
|
|
158
|
+
streams: settings.streams,
|
|
159
|
+
progressManager: pm,
|
|
160
|
+
gargabeCollector: gc,
|
|
161
|
+
});
|
|
162
|
+
return l
|
|
163
|
+
.add(l.$task({
|
|
164
|
+
key: "snapshots",
|
|
165
|
+
data: {
|
|
166
|
+
id: "",
|
|
167
|
+
packages: 0,
|
|
168
|
+
},
|
|
169
|
+
title: {
|
|
170
|
+
initial: "Fetch snapshots",
|
|
171
|
+
started: "Fetching snapshots",
|
|
172
|
+
completed: "Snapshots fetched",
|
|
173
|
+
failed: "Snapshot fetch failed",
|
|
174
|
+
},
|
|
175
|
+
run: async (_, data) => {
|
|
176
|
+
const { minFreeDiskSpace } = this.config;
|
|
177
|
+
if (minFreeDiskSpace)
|
|
178
|
+
await (0, temp_1.ensureFreeDiskTempSpace)(minFreeDiskSpace);
|
|
179
|
+
if (!options.id)
|
|
180
|
+
throw new error_1.AppError("Snapshot id is required");
|
|
181
|
+
const snapshots = await new SnapshotsAction_1.SnapshotsAction(this.config, {
|
|
182
|
+
ids: [this.options.id],
|
|
183
|
+
repositoryNames: this.options.repositoryNames,
|
|
184
|
+
repositoryTypes: this.options.repositoryTypes,
|
|
185
|
+
packageNames: this.options.packageNames,
|
|
186
|
+
packageTaskNames: this.options.packageTaskNames,
|
|
187
|
+
packageConfig: this.options.packageConfig,
|
|
188
|
+
tags: this.options.tags,
|
|
189
|
+
groupBy: ["packageName"],
|
|
190
|
+
}).exec("restore");
|
|
191
|
+
if (!snapshots.length)
|
|
192
|
+
throw new error_1.AppError("None snapshot found");
|
|
193
|
+
data.id = options.id;
|
|
194
|
+
data.packages = snapshots.length;
|
|
195
|
+
return snapshots.map((snapshot) => l.$task({
|
|
196
|
+
key: "export",
|
|
197
|
+
keyIndex: snapshot.packageName,
|
|
198
|
+
data: snapshot,
|
|
199
|
+
title: {
|
|
200
|
+
initial: `Export snapshot: ${snapshot.packageName} (${snapshot.repositoryName})`,
|
|
201
|
+
started: `Restoring snapshot: ${snapshot.packageName} (${snapshot.repositoryName})`,
|
|
202
|
+
completed: `Snapshot exported: ${snapshot.packageName} (${snapshot.repositoryName})`,
|
|
203
|
+
failed: `Snapshot export failed: ${snapshot.packageName} (${snapshot.repositoryName})`,
|
|
204
|
+
},
|
|
205
|
+
exitOnError: false,
|
|
206
|
+
run: async (listTask) => {
|
|
207
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
208
|
+
try {
|
|
209
|
+
const progress = __addDisposableResource(env_1, pm.create(listTask), false);
|
|
210
|
+
const _ = __addDisposableResource(env_1, gc.create().disposeOnFinish(), true);
|
|
211
|
+
await this.restore({
|
|
212
|
+
pkg: { name: snapshot.packageName },
|
|
213
|
+
snapshotPath: (0, path_1.join)(this.options.outPath, snapshot.repositoryName, DatatruckRepository_1.DatatruckRepository.createSnapshotName(snapshot, {
|
|
214
|
+
name: snapshot.packageName,
|
|
215
|
+
})),
|
|
216
|
+
snapshot: snapshot,
|
|
217
|
+
onProgress: progress.update,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
catch (e_1) {
|
|
221
|
+
env_1.error = e_1;
|
|
222
|
+
env_1.hasError = true;
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
const result_1 = __disposeResources(env_1);
|
|
226
|
+
if (result_1)
|
|
227
|
+
await result_1;
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
}));
|
|
231
|
+
},
|
|
232
|
+
}))
|
|
233
|
+
.execAndParse(this.options.verbose);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.ExportAction = ExportAction;
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import type { Config } from "../utils/datatruck/config-type";
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
repositoryNames
|
|
5
|
-
|
|
2
|
+
import { InferOptions } from "../utils/options";
|
|
3
|
+
export declare const initActionOptions: {
|
|
4
|
+
repositoryNames: {
|
|
5
|
+
description: string;
|
|
6
|
+
shortFlag: string;
|
|
7
|
+
value: "array";
|
|
8
|
+
};
|
|
9
|
+
repositoryTypes: {
|
|
10
|
+
description: string;
|
|
11
|
+
shortFlag: string;
|
|
12
|
+
value: "array";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type InitActionOptions = InferOptions<typeof initActionOptions> & {
|
|
6
16
|
verbose?: boolean;
|
|
7
17
|
};
|
|
8
|
-
export declare class InitAction
|
|
18
|
+
export declare class InitAction {
|
|
9
19
|
readonly config: Config;
|
|
10
|
-
readonly options:
|
|
11
|
-
constructor(config: Config, options:
|
|
20
|
+
readonly options: InitActionOptions;
|
|
21
|
+
constructor(config: Config, options: InitActionOptions);
|
|
12
22
|
exec(): Promise<{
|
|
13
23
|
repositoryName: string;
|
|
14
24
|
repositoryType: string;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InitAction = void 0;
|
|
3
|
+
exports.InitAction = exports.initActionOptions = void 0;
|
|
4
4
|
const config_1 = require("../utils/datatruck/config");
|
|
5
5
|
const repository_1 = require("../utils/datatruck/repository");
|
|
6
|
+
const object_1 = require("../utils/object");
|
|
6
7
|
const string_1 = require("../utils/string");
|
|
8
|
+
const SnapshotsAction_1 = require("./SnapshotsAction");
|
|
9
|
+
exports.initActionOptions = {
|
|
10
|
+
...(0, object_1.pickProps)(SnapshotsAction_1.snapshotsActionOptions, {
|
|
11
|
+
repositoryNames: true,
|
|
12
|
+
repositoryTypes: true,
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
7
15
|
class InitAction {
|
|
8
16
|
config;
|
|
9
17
|
options;
|
|
@@ -1,18 +1,77 @@
|
|
|
1
|
-
import type { Config
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { Config } from "../utils/datatruck/config-type";
|
|
2
|
+
import { InferOptions } from "../utils/options";
|
|
3
|
+
import { ExtendedSnapshot } from "./SnapshotsAction";
|
|
4
|
+
export declare const pruneActionOptions: {
|
|
5
|
+
groupBy: {
|
|
6
|
+
description: string;
|
|
7
|
+
shortFlag: string;
|
|
8
|
+
defaults: string;
|
|
9
|
+
value: (v: string) => ("packageName" | "repositoryName" | "repositoryType")[];
|
|
10
|
+
};
|
|
11
|
+
dryRun: {
|
|
12
|
+
description: string;
|
|
13
|
+
value: "boolean";
|
|
14
|
+
};
|
|
15
|
+
showAll: {
|
|
16
|
+
description: string;
|
|
17
|
+
shortFlag: string;
|
|
18
|
+
};
|
|
19
|
+
keepMinutely: {
|
|
20
|
+
description: string;
|
|
21
|
+
value: "number";
|
|
22
|
+
};
|
|
23
|
+
keepDaily: {
|
|
24
|
+
description: string;
|
|
25
|
+
value: "number";
|
|
26
|
+
};
|
|
27
|
+
keepHourly: {
|
|
28
|
+
description: string;
|
|
29
|
+
value: "number";
|
|
30
|
+
};
|
|
31
|
+
keepLast: {
|
|
32
|
+
description: string;
|
|
33
|
+
value: "number";
|
|
34
|
+
};
|
|
35
|
+
keepMonthly: {
|
|
36
|
+
description: string;
|
|
37
|
+
value: "number";
|
|
38
|
+
};
|
|
39
|
+
keepWeekly: {
|
|
40
|
+
description: string;
|
|
41
|
+
value: "number";
|
|
42
|
+
};
|
|
43
|
+
keepYearly: {
|
|
44
|
+
description: string;
|
|
45
|
+
value: "number";
|
|
46
|
+
};
|
|
47
|
+
repositoryNames: {
|
|
48
|
+
description: string;
|
|
49
|
+
shortFlag: string;
|
|
50
|
+
value: "array";
|
|
51
|
+
};
|
|
52
|
+
repositoryTypes: {
|
|
53
|
+
description: string;
|
|
54
|
+
shortFlag: string;
|
|
55
|
+
value: "array";
|
|
56
|
+
};
|
|
57
|
+
packageNames: {
|
|
58
|
+
description: string;
|
|
59
|
+
shortFlag: string;
|
|
60
|
+
value: "array";
|
|
61
|
+
};
|
|
62
|
+
tags: {
|
|
63
|
+
description: string;
|
|
64
|
+
shortFlag: string;
|
|
65
|
+
value: "array";
|
|
66
|
+
};
|
|
67
|
+
ids: {
|
|
68
|
+
description: string;
|
|
69
|
+
shortFlag: string;
|
|
70
|
+
value: "array";
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export type PruneActionsOptions = InferOptions<typeof pruneActionOptions> & {
|
|
11
74
|
verbose?: boolean;
|
|
12
|
-
groupBy?: SnapshotsActionOptions["groupBy"];
|
|
13
|
-
dryRun?: boolean;
|
|
14
|
-
longId?: boolean;
|
|
15
|
-
returnsAll?: boolean;
|
|
16
75
|
};
|
|
17
76
|
export type PruneResult = {
|
|
18
77
|
total: number;
|
|
@@ -21,10 +80,10 @@ export type PruneResult = {
|
|
|
21
80
|
exclusionReasons: string[];
|
|
22
81
|
})[];
|
|
23
82
|
};
|
|
24
|
-
export declare class PruneAction
|
|
83
|
+
export declare class PruneAction {
|
|
25
84
|
readonly config: Config;
|
|
26
|
-
readonly options:
|
|
27
|
-
constructor(config: Config, options:
|
|
85
|
+
readonly options: PruneActionsOptions;
|
|
86
|
+
constructor(config: Config, options: PruneActionsOptions);
|
|
28
87
|
confirm(snapshots: PruneResult["snapshots"]): Promise<void>;
|
|
29
88
|
exec(): Promise<PruneResult>;
|
|
30
89
|
}
|