@datatruck/cli 0.34.1 → 0.34.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/config.schema.json +337 -72
- package/lib/actions/BackupAction.d.ts +4 -4
- package/lib/actions/BackupAction.js +2 -2
- package/lib/actions/CopyAction.d.ts +3 -3
- package/lib/actions/CopyAction.js +2 -2
- package/lib/actions/RestoreAction.d.ts +4 -4
- package/lib/actions/RestoreAction.js +5 -5
- package/lib/commands/CleanCacheCommand.js +2 -2
- package/lib/commands/CommandAbstract.d.ts +4 -4
- package/lib/commands/CommandAbstract.js +1 -1
- package/lib/commands/ConfigCommand.js +2 -2
- package/lib/commands/InitCommand.js +2 -2
- package/lib/commands/PruneCommand.js +2 -2
- package/lib/commands/SnapshotsCommand.js +2 -2
- package/lib/repositories/GitRepository.js +6 -6
- package/lib/repositories/ResticRepository.d.ts +1 -1
- package/lib/repositories/ResticRepository.js +9 -9
- package/lib/tasks/GitTask.js +2 -1
- package/lib/utils/async-process.js +18 -13
- package/lib/utils/{DataFormat.d.ts → data-format.d.ts} +4 -4
- package/lib/utils/{DataFormat.js → data-format.js} +1 -1
- package/lib/utils/datatruck/command.d.ts +2 -2
- package/lib/utils/datatruck/config-type.d.ts +1 -1
- package/lib/utils/fs.d.ts +0 -6
- package/lib/utils/fs.js +3 -9
- package/lib/utils/list.d.ts +4 -4
- package/lib/utils/list.js +1 -1
- package/lib/utils/stream.d.ts +8 -2
- package/lib/utils/stream.js +10 -3
- package/package.json +2 -2
- /package/lib/utils/{Git.d.ts → git.d.ts} +0 -0
- /package/lib/utils/{Git.js → git.js} +0 -0
- /package/lib/utils/{Restic.d.ts → restic.d.ts} +0 -0
- /package/lib/utils/{Restic.js → restic.js} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PreSnapshot } from "../repositories/RepositoryAbstract";
|
|
2
|
-
import { DataFormat } from "../utils/
|
|
2
|
+
import { DataFormat } from "../utils/data-format";
|
|
3
3
|
import type { Config, PackageConfig, 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 { Progress, ProgressMode } from "../utils/progress";
|
|
7
|
-
import {
|
|
7
|
+
import { StdStreams } from "../utils/stream";
|
|
8
8
|
import { IfRequireKeys } from "../utils/ts";
|
|
9
9
|
export type BackupActionOptions = {
|
|
10
10
|
repositoryNames?: string[];
|
|
@@ -17,7 +17,7 @@ export type BackupActionOptions = {
|
|
|
17
17
|
date?: string;
|
|
18
18
|
tty?: "auto" | boolean;
|
|
19
19
|
progress?: ProgressMode;
|
|
20
|
-
streams?:
|
|
20
|
+
streams?: StdStreams;
|
|
21
21
|
prune?: boolean;
|
|
22
22
|
};
|
|
23
23
|
type Context = {
|
|
@@ -75,7 +75,7 @@ export declare class BackupAction<TRequired extends boolean = true> {
|
|
|
75
75
|
bytes: number;
|
|
76
76
|
}>;
|
|
77
77
|
dataFormat(result: Listr3TaskResultEnd<Context>[], options?: {
|
|
78
|
-
streams?:
|
|
78
|
+
streams?: StdStreams;
|
|
79
79
|
verbose?: number;
|
|
80
80
|
}): DataFormat;
|
|
81
81
|
exec(): Promise<(import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<Context>)[]>;
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BackupAction = void 0;
|
|
7
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
8
7
|
const bytes_1 = require("../utils/bytes");
|
|
9
8
|
const cli_1 = require("../utils/cli");
|
|
9
|
+
const data_format_1 = require("../utils/data-format");
|
|
10
10
|
const config_1 = require("../utils/datatruck/config");
|
|
11
11
|
const report_list_1 = require("../utils/datatruck/report-list");
|
|
12
12
|
const repository_1 = require("../utils/datatruck/repository");
|
|
@@ -132,7 +132,7 @@ class BackupAction {
|
|
|
132
132
|
}),
|
|
133
133
|
});
|
|
134
134
|
};
|
|
135
|
-
return new
|
|
135
|
+
return new data_format_1.DataFormat({
|
|
136
136
|
streams: options.streams,
|
|
137
137
|
json: result,
|
|
138
138
|
list: () => result
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RepositoryAbstract, Snapshot } from "../repositories/RepositoryAbstract";
|
|
2
|
-
import { DataFormat } from "../utils/
|
|
2
|
+
import { DataFormat } from "../utils/data-format";
|
|
3
3
|
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
7
|
import { Progress, ProgressMode } from "../utils/progress";
|
|
8
|
-
import {
|
|
8
|
+
import { StdStreams } from "../utils/stream";
|
|
9
9
|
import { IfRequireKeys } from "../utils/ts";
|
|
10
10
|
export type CopyActionOptions = {
|
|
11
11
|
ids?: string[];
|
|
@@ -39,7 +39,7 @@ export declare class CopyAction<TRequired extends boolean = true> {
|
|
|
39
39
|
readonly options: IfRequireKeys<TRequired, CopyActionOptions>;
|
|
40
40
|
constructor(config: Config, options: IfRequireKeys<TRequired, CopyActionOptions>);
|
|
41
41
|
dataFormat(result: Listr3TaskResultEnd<Context>[], options?: {
|
|
42
|
-
streams?:
|
|
42
|
+
streams?: StdStreams;
|
|
43
43
|
verbose?: number;
|
|
44
44
|
}): DataFormat;
|
|
45
45
|
protected fetchSnapshots(repo: RepositoryAbstract<any>): Promise<Snapshot[]>;
|
|
@@ -49,9 +49,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
exports.CopyAction = void 0;
|
|
52
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
53
52
|
const bytes_1 = require("../utils/bytes");
|
|
54
53
|
const cli_1 = require("../utils/cli");
|
|
54
|
+
const data_format_1 = require("../utils/data-format");
|
|
55
55
|
const config_1 = require("../utils/datatruck/config");
|
|
56
56
|
const report_list_1 = require("../utils/datatruck/report-list");
|
|
57
57
|
const repository_1 = require("../utils/datatruck/repository");
|
|
@@ -95,7 +95,7 @@ class CopyAction {
|
|
|
95
95
|
}),
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
|
-
return new
|
|
98
|
+
return new data_format_1.DataFormat({
|
|
99
99
|
streams: options.streams,
|
|
100
100
|
json: result,
|
|
101
101
|
table: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Snapshot } from "../repositories/RepositoryAbstract";
|
|
2
2
|
import { TaskAbstract } from "../tasks/TaskAbstract";
|
|
3
|
-
import { DataFormat } from "../utils/
|
|
3
|
+
import { DataFormat } from "../utils/data-format";
|
|
4
4
|
import type { Config, PackageConfig } from "../utils/datatruck/config-type";
|
|
5
5
|
import { Listr3TaskResultEnd } from "../utils/list";
|
|
6
6
|
import { Progress, ProgressMode } from "../utils/progress";
|
|
7
|
-
import {
|
|
7
|
+
import { StdStreams } from "../utils/stream";
|
|
8
8
|
import { GargabeCollector } from "../utils/temp";
|
|
9
9
|
import { IfRequireKeys } from "../utils/ts";
|
|
10
10
|
export type RestoreActionOptions = {
|
|
@@ -19,7 +19,7 @@ export type RestoreActionOptions = {
|
|
|
19
19
|
initial?: boolean;
|
|
20
20
|
tty?: "auto" | boolean;
|
|
21
21
|
progress?: ProgressMode;
|
|
22
|
-
streams?:
|
|
22
|
+
streams?: StdStreams;
|
|
23
23
|
};
|
|
24
24
|
type RestoreSnapshot = Snapshot & {
|
|
25
25
|
repositoryName: string;
|
|
@@ -53,7 +53,7 @@ export declare class RestoreAction<TRequired extends boolean = true> {
|
|
|
53
53
|
snapshotPath: string | undefined;
|
|
54
54
|
}>;
|
|
55
55
|
dataFormat(result: Listr3TaskResultEnd<Context>[], options?: {
|
|
56
|
-
streams?:
|
|
56
|
+
streams?: StdStreams;
|
|
57
57
|
verbose?: number;
|
|
58
58
|
}): DataFormat;
|
|
59
59
|
exec(): Promise<(import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<Context>)[]>;
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RestoreAction = void 0;
|
|
7
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
8
7
|
const cli_1 = require("../utils/cli");
|
|
8
|
+
const data_format_1 = require("../utils/data-format");
|
|
9
9
|
const config_1 = require("../utils/datatruck/config");
|
|
10
10
|
const repository_1 = require("../utils/datatruck/repository");
|
|
11
11
|
const task_1 = require("../utils/datatruck/task");
|
|
@@ -69,8 +69,6 @@ class RestoreAction {
|
|
|
69
69
|
let { snapshot, pkg, task } = data;
|
|
70
70
|
const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
|
|
71
71
|
const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
|
|
72
|
-
if (this.options.initial)
|
|
73
|
-
pkg = { ...pkg, restorePath: pkg.path };
|
|
74
72
|
let snapshotPath = pkg.restorePath ?? pkg.path;
|
|
75
73
|
await data.gc.cleanupIfFail(async () => {
|
|
76
74
|
if (task) {
|
|
@@ -117,7 +115,7 @@ class RestoreAction {
|
|
|
117
115
|
}),
|
|
118
116
|
});
|
|
119
117
|
};
|
|
120
|
-
return new
|
|
118
|
+
return new data_format_1.DataFormat({
|
|
121
119
|
streams: options.streams,
|
|
122
120
|
json: result,
|
|
123
121
|
table: {
|
|
@@ -185,11 +183,13 @@ class RestoreAction {
|
|
|
185
183
|
},
|
|
186
184
|
exitOnError: false,
|
|
187
185
|
run: async (listTask) => {
|
|
188
|
-
|
|
186
|
+
let pkg = (0, config_1.resolvePackage)((0, config_1.findPackageOrFail)(this.config, snapshot.packageName), {
|
|
189
187
|
snapshotId: options.snapshotId,
|
|
190
188
|
snapshotDate: snapshot.date,
|
|
191
189
|
action: "restore",
|
|
192
190
|
});
|
|
191
|
+
if (this.options.initial)
|
|
192
|
+
pkg = { ...pkg, restorePath: pkg.path };
|
|
193
193
|
const gc = new temp_1.GargabeCollector();
|
|
194
194
|
const task = pkg.task ? (0, task_1.createTask)(pkg.task) : undefined;
|
|
195
195
|
const restore = await this.restore({
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CleanCacheCommand = void 0;
|
|
4
4
|
const CleanCacheAction_1 = require("../actions/CleanCacheAction");
|
|
5
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
6
5
|
const bytes_1 = require("../utils/bytes");
|
|
6
|
+
const data_format_1 = require("../utils/data-format");
|
|
7
7
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
8
8
|
class CleanCacheCommand extends CommandAbstract_1.CommandAbstract {
|
|
9
9
|
optionsConfig() {
|
|
@@ -14,7 +14,7 @@ class CleanCacheCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
14
14
|
verbose: !!this.globalOptions.verbose,
|
|
15
15
|
});
|
|
16
16
|
const result = await cleanCache.exec();
|
|
17
|
-
const dataFormat = new
|
|
17
|
+
const dataFormat = new data_format_1.DataFormat({
|
|
18
18
|
streams: this.streams,
|
|
19
19
|
json: result,
|
|
20
20
|
table: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DataFormatType } from "../utils/DataFormat";
|
|
2
1
|
import { OptionsConfig } from "../utils/cli";
|
|
2
|
+
import { DataFormatType } from "../utils/data-format";
|
|
3
3
|
import type { Config } from "../utils/datatruck/config-type";
|
|
4
4
|
import { ProgressMode } from "../utils/progress";
|
|
5
|
-
import {
|
|
5
|
+
import { StdStreams } from "../utils/stream";
|
|
6
6
|
import { If, SimilarObject } from "../utils/ts";
|
|
7
7
|
export type GlobalOptions<TResolved = false> = {
|
|
8
8
|
config: string | Config;
|
|
@@ -19,8 +19,8 @@ export declare abstract class CommandAbstract<TUnresolvedOptions, TOptions exten
|
|
|
19
19
|
readonly inputOptions: TUnresolvedOptions;
|
|
20
20
|
readonly configPath?: string | undefined;
|
|
21
21
|
readonly options: TOptions;
|
|
22
|
-
readonly streams:
|
|
23
|
-
constructor(globalOptions: GlobalOptions<true>, inputOptions: TUnresolvedOptions, streams?: Partial<
|
|
22
|
+
readonly streams: StdStreams;
|
|
23
|
+
constructor(globalOptions: GlobalOptions<true>, inputOptions: TUnresolvedOptions, streams?: Partial<StdStreams>, configPath?: string | undefined);
|
|
24
24
|
abstract optionsConfig(): OptionsConfig<TUnresolvedOptions, TOptions>;
|
|
25
25
|
protected castOptionsConfig(options: OptionsConfig<TUnresolvedOptions, TOptions>): OptionsConfig<TUnresolvedOptions, TOptions>;
|
|
26
26
|
abstract exec(): Promise<{
|
|
@@ -14,7 +14,7 @@ class CommandAbstract {
|
|
|
14
14
|
this.inputOptions = inputOptions;
|
|
15
15
|
this.configPath = configPath;
|
|
16
16
|
this.options = (0, cli_1.parseOptions)(inputOptions, this.optionsConfig());
|
|
17
|
-
this.streams = (0, stream_1.
|
|
17
|
+
this.streams = (0, stream_1.createStdStreams)(streams);
|
|
18
18
|
}
|
|
19
19
|
castOptionsConfig(options) {
|
|
20
20
|
return options;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfigCommand = void 0;
|
|
4
4
|
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
|
-
const
|
|
5
|
+
const data_format_1 = require("../utils/data-format");
|
|
6
6
|
const config_1 = require("../utils/datatruck/config");
|
|
7
7
|
const string_1 = require("../utils/string");
|
|
8
8
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
@@ -44,7 +44,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
44
44
|
repositoryNames: pkg.repositoryNames ?? [],
|
|
45
45
|
taskName: pkg.task?.name,
|
|
46
46
|
}));
|
|
47
|
-
const dataFormat = new
|
|
47
|
+
const dataFormat = new data_format_1.DataFormat({
|
|
48
48
|
streams: this.streams,
|
|
49
49
|
json: result,
|
|
50
50
|
table: {
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InitCommand = void 0;
|
|
4
4
|
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
5
|
const InitAction_1 = require("../actions/InitAction");
|
|
6
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
7
6
|
const cli_1 = require("../utils/cli");
|
|
7
|
+
const data_format_1 = require("../utils/data-format");
|
|
8
8
|
const string_1 = require("../utils/string");
|
|
9
9
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
10
10
|
class InitCommand extends CommandAbstract_1.CommandAbstract {
|
|
@@ -31,7 +31,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
31
31
|
verbose: verbose > 0,
|
|
32
32
|
});
|
|
33
33
|
const result = await init.exec();
|
|
34
|
-
const dataFormat = new
|
|
34
|
+
const dataFormat = new data_format_1.DataFormat({
|
|
35
35
|
streams: this.streams,
|
|
36
36
|
json: result,
|
|
37
37
|
table: {
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PruneCommand = void 0;
|
|
4
4
|
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
5
|
const PruneAction_1 = require("../actions/PruneAction");
|
|
6
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
7
6
|
const cli_1 = require("../utils/cli");
|
|
7
|
+
const data_format_1 = require("../utils/data-format");
|
|
8
8
|
const string_1 = require("../utils/string");
|
|
9
9
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
10
10
|
class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
@@ -122,7 +122,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
122
122
|
returnsAll: this.options.showAll,
|
|
123
123
|
});
|
|
124
124
|
const result = await prune.exec();
|
|
125
|
-
const dataFormat = new
|
|
125
|
+
const dataFormat = new data_format_1.DataFormat({
|
|
126
126
|
streams: this.streams,
|
|
127
127
|
json: result,
|
|
128
128
|
table: {
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SnapshotsCommand = void 0;
|
|
4
4
|
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
5
|
const SnapshotsAction_1 = require("../actions/SnapshotsAction");
|
|
6
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
7
6
|
const bytes_1 = require("../utils/bytes");
|
|
7
|
+
const data_format_1 = require("../utils/data-format");
|
|
8
8
|
const string_1 = require("../utils/string");
|
|
9
9
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
10
10
|
class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
@@ -118,7 +118,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
118
118
|
tags: this.options.tag,
|
|
119
119
|
});
|
|
120
120
|
const result = await snapshots.exec();
|
|
121
|
-
const dataFormat = new
|
|
121
|
+
const dataFormat = new data_format_1.DataFormat({
|
|
122
122
|
streams: this.streams,
|
|
123
123
|
json: result,
|
|
124
124
|
table: {
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GitRepository = exports.gitRepositoryName = void 0;
|
|
7
|
-
const Git_1 = require("../utils/Git");
|
|
8
7
|
const cli_1 = require("../utils/cli");
|
|
9
8
|
const paths_1 = require("../utils/datatruck/paths");
|
|
10
9
|
const fs_1 = require("../utils/fs");
|
|
10
|
+
const git_1 = require("../utils/git");
|
|
11
11
|
const string_1 = require("../utils/string");
|
|
12
12
|
const temp_1 = require("../utils/temp");
|
|
13
13
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
@@ -46,7 +46,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
46
46
|
return `${GitRepository.refPrefix}/${packageName}`;
|
|
47
47
|
}
|
|
48
48
|
async init(data) {
|
|
49
|
-
const git = new
|
|
49
|
+
const git = new git_1.Git({
|
|
50
50
|
dir: (0, temp_1.tmpDir)(exports.gitRepositoryName, "repository", "init"),
|
|
51
51
|
log: data.options.verbose,
|
|
52
52
|
});
|
|
@@ -73,7 +73,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async prune(data) {
|
|
76
|
-
const git = new
|
|
76
|
+
const git = new git_1.Git({
|
|
77
77
|
dir: await (0, temp_1.mkTmpDir)(exports.gitRepositoryName, "repo", "prune"),
|
|
78
78
|
log: data.options.verbose,
|
|
79
79
|
});
|
|
@@ -96,7 +96,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
96
96
|
await git.exec(["push", "--delete", "origin", data.snapshot.originalId]);
|
|
97
97
|
}
|
|
98
98
|
async fetchSnapshots(data) {
|
|
99
|
-
const git = new
|
|
99
|
+
const git = new git_1.Git({
|
|
100
100
|
dir: await (0, temp_1.mkTmpDir)(exports.gitRepositoryName, "repo", "snapshots"),
|
|
101
101
|
log: data.options.verbose,
|
|
102
102
|
});
|
|
@@ -137,7 +137,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
137
137
|
const path = pkg.path;
|
|
138
138
|
const tmpPath = await (0, temp_1.mkTmpDir)(exports.gitRepositoryName, "repo", "backup");
|
|
139
139
|
const branchName = GitRepository.buildBranchName(data.package.name);
|
|
140
|
-
const git = new
|
|
140
|
+
const git = new git_1.Git({
|
|
141
141
|
dir: tmpPath,
|
|
142
142
|
log: data.options.verbose,
|
|
143
143
|
});
|
|
@@ -217,7 +217,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
217
217
|
id: data.snapshot.id,
|
|
218
218
|
package: data.package.name,
|
|
219
219
|
});
|
|
220
|
-
const git = new
|
|
220
|
+
const git = new git_1.Git({
|
|
221
221
|
dir: restorePath,
|
|
222
222
|
log: data.options.verbose,
|
|
223
223
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResticRepositoryUri } from "../utils/
|
|
1
|
+
import { ResticRepositoryUri } from "../utils/restic";
|
|
2
2
|
import { RepositoryAbstract, RepoBackupData, RepoInitData, RepoRestoreData, RepoFetchSnapshotsData, Snapshot, SnapshotTagObject, SnapshotTagEnum, RepoPruneData, RepoCopyData } from "./RepositoryAbstract";
|
|
3
3
|
export type ResticRepositoryConfig = {
|
|
4
4
|
password: string | {
|
|
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ResticRepository = exports.resticRepositoryName = void 0;
|
|
7
|
-
const Restic_1 = require("../utils/Restic");
|
|
8
7
|
const cli_1 = require("../utils/cli");
|
|
9
8
|
const error_1 = require("../utils/datatruck/error");
|
|
10
9
|
const paths_1 = require("../utils/datatruck/paths");
|
|
11
10
|
const fs_1 = require("../utils/fs");
|
|
12
11
|
const math_1 = require("../utils/math");
|
|
12
|
+
const restic_1 = require("../utils/restic");
|
|
13
13
|
const string_1 = require("../utils/string");
|
|
14
14
|
const temp_1 = require("../utils/temp");
|
|
15
15
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
@@ -28,7 +28,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
28
28
|
...(typeof this.config.password === "string"
|
|
29
29
|
? { RESTIC_PASSWORD: this.config.password }
|
|
30
30
|
: { RESTIC_PASSWORD_FILE: (0, path_1.resolve)(this.config.password.path) }),
|
|
31
|
-
RESTIC_REPOSITORY: await
|
|
31
|
+
RESTIC_REPOSITORY: await restic_1.Restic.formatRepository(this.config.repository),
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
static buildSnapshotTag(name, value) {
|
|
@@ -69,7 +69,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
69
69
|
return (0, fs_1.fetchDiskStats)(config.repository.path);
|
|
70
70
|
}
|
|
71
71
|
async init(data) {
|
|
72
|
-
const restic = new
|
|
72
|
+
const restic = new restic_1.Restic({
|
|
73
73
|
env: await this.buildEnv(),
|
|
74
74
|
log: data.options.verbose,
|
|
75
75
|
});
|
|
@@ -79,7 +79,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
79
79
|
await restic.exec(["init"]);
|
|
80
80
|
}
|
|
81
81
|
async fetchSnapshots(data) {
|
|
82
|
-
const restic = new
|
|
82
|
+
const restic = new restic_1.Restic({
|
|
83
83
|
env: await this.buildEnv(),
|
|
84
84
|
log: data.options.verbose,
|
|
85
85
|
});
|
|
@@ -115,7 +115,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
115
115
|
}, []);
|
|
116
116
|
}
|
|
117
117
|
async prune(data) {
|
|
118
|
-
const restic = new
|
|
118
|
+
const restic = new restic_1.Restic({
|
|
119
119
|
env: await this.buildEnv(),
|
|
120
120
|
log: data.options.verbose,
|
|
121
121
|
});
|
|
@@ -125,7 +125,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
async backup(data) {
|
|
128
|
-
const restic = new
|
|
128
|
+
const restic = new restic_1.Restic({
|
|
129
129
|
env: await this.buildEnv(),
|
|
130
130
|
log: data.options.verbose,
|
|
131
131
|
});
|
|
@@ -278,13 +278,13 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
278
278
|
});
|
|
279
279
|
if (!snapshot)
|
|
280
280
|
throw new error_1.AppError(`Snapshot not found`);
|
|
281
|
-
const restic = new
|
|
281
|
+
const restic = new restic_1.Restic({
|
|
282
282
|
env: {
|
|
283
283
|
...(await this.buildEnv()),
|
|
284
284
|
...(typeof config.password === "string"
|
|
285
285
|
? { RESTIC_PASSWORD2: config.password }
|
|
286
286
|
: { RESTIC_PASSWORD_FILE2: (0, path_1.resolve)(config.password.path) }),
|
|
287
|
-
RESTIC_REPOSITORY2: await
|
|
287
|
+
RESTIC_REPOSITORY2: await restic_1.Restic.formatRepository(config.repository),
|
|
288
288
|
},
|
|
289
289
|
log: data.options.verbose,
|
|
290
290
|
});
|
|
@@ -301,7 +301,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
301
301
|
}
|
|
302
302
|
async restore(data) {
|
|
303
303
|
const restorePath = data.snapshotPath;
|
|
304
|
-
const restic = new
|
|
304
|
+
const restic = new restic_1.Restic({
|
|
305
305
|
env: await this.buildEnv(),
|
|
306
306
|
log: data.options.verbose,
|
|
307
307
|
});
|
package/lib/tasks/GitTask.js
CHANGED
|
@@ -5,6 +5,7 @@ const async_process_1 = require("../utils/async-process");
|
|
|
5
5
|
const cli_1 = require("../utils/cli");
|
|
6
6
|
const fs_1 = require("../utils/fs");
|
|
7
7
|
const math_1 = require("../utils/math");
|
|
8
|
+
const stream_1 = require("../utils/stream");
|
|
8
9
|
const temp_1 = require("../utils/temp");
|
|
9
10
|
const TaskAbstract_1 = require("./TaskAbstract");
|
|
10
11
|
const assert_1 = require("assert");
|
|
@@ -93,7 +94,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
93
94
|
}
|
|
94
95
|
}),
|
|
95
96
|
p.child.on("close", () => stream.end()),
|
|
96
|
-
(0,
|
|
97
|
+
(0, stream_1.waitForClose)(stream),
|
|
97
98
|
]);
|
|
98
99
|
}
|
|
99
100
|
// Copy
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncProcess = void 0;
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
|
-
const fs_1 = require("./fs");
|
|
6
5
|
const math_1 = require("./math");
|
|
7
6
|
const process_1 = require("./process");
|
|
7
|
+
const stream_1 = require("./stream");
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
|
-
const
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
10
|
const promises_1 = require("fs/promises");
|
|
11
11
|
const readline_1 = require("readline");
|
|
12
12
|
function resolveLogOptions(log) {
|
|
@@ -18,7 +18,7 @@ function ensureDir(cwd) {
|
|
|
18
18
|
if (typeof cwd === "string") {
|
|
19
19
|
let isDir = false;
|
|
20
20
|
try {
|
|
21
|
-
isDir = (0,
|
|
21
|
+
isDir = (0, fs_1.statSync)(cwd).isDirectory();
|
|
22
22
|
}
|
|
23
23
|
catch (error) { }
|
|
24
24
|
if (!isDir)
|
|
@@ -34,14 +34,14 @@ class StdIn {
|
|
|
34
34
|
}
|
|
35
35
|
async pipe(source, onProgress) {
|
|
36
36
|
if (this.process["log"]?.exec) {
|
|
37
|
-
const path = source instanceof
|
|
37
|
+
const path = source instanceof fs_1.ReadStream
|
|
38
38
|
? "path" in source
|
|
39
39
|
? source.path
|
|
40
40
|
: "&readableStream"
|
|
41
41
|
: source;
|
|
42
42
|
(0, cli_1.logExec)(`[${this.process.child.pid || 0}] < ${path}`);
|
|
43
43
|
}
|
|
44
|
-
const stream = typeof source === "string" ? (0,
|
|
44
|
+
const stream = typeof source === "string" ? (0, fs_1.createReadStream)(source) : source;
|
|
45
45
|
const streamPath = stream.path.toString();
|
|
46
46
|
if (onProgress) {
|
|
47
47
|
const fileInfo = await (0, promises_1.stat)(streamPath);
|
|
@@ -59,8 +59,8 @@ class StdIn {
|
|
|
59
59
|
stream.pipe(this.writable);
|
|
60
60
|
await Promise.all([
|
|
61
61
|
this.process.waitForClose(),
|
|
62
|
-
(0,
|
|
63
|
-
(0,
|
|
62
|
+
(0, stream_1.waitForClose)(stream),
|
|
63
|
+
(0, stream_1.waitForClose)(this.writable),
|
|
64
64
|
]);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -90,7 +90,7 @@ class Std {
|
|
|
90
90
|
if (line.length)
|
|
91
91
|
cb(line, ++total);
|
|
92
92
|
});
|
|
93
|
-
await Promise.all([this.process.waitForClose(), (0,
|
|
93
|
+
await Promise.all([this.process.waitForClose(), (0, stream_1.waitForClose)(parser)]);
|
|
94
94
|
return total;
|
|
95
95
|
}
|
|
96
96
|
async pipe(out, onProgress) {
|
|
@@ -114,7 +114,7 @@ class Std {
|
|
|
114
114
|
const stream = out instanceof StdIn
|
|
115
115
|
? out.writable
|
|
116
116
|
: typeof out === "string"
|
|
117
|
-
? (0,
|
|
117
|
+
? (0, fs_1.createWriteStream)(out)
|
|
118
118
|
: out;
|
|
119
119
|
this.readable.pipe(stream);
|
|
120
120
|
await Promise.all([
|
|
@@ -123,8 +123,8 @@ class Std {
|
|
|
123
123
|
stream.destroy();
|
|
124
124
|
return Promise.reject(error);
|
|
125
125
|
}),
|
|
126
|
-
(0,
|
|
127
|
-
(0,
|
|
126
|
+
(0, stream_1.waitForClose)(stream),
|
|
127
|
+
(0, stream_1.waitForClose)(this.readable),
|
|
128
128
|
]);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -194,8 +194,13 @@ class AsyncProcess {
|
|
|
194
194
|
let exitCode = inExitCode ?? 32;
|
|
195
195
|
if (!exitCode)
|
|
196
196
|
return exitCode;
|
|
197
|
+
const lastStdError = this.lastStdError?.toString().trim().slice(0, 255);
|
|
197
198
|
let result = this.options.$exitCode ?? true;
|
|
198
|
-
let message = inExitCode === null
|
|
199
|
+
let message = (inExitCode === null
|
|
200
|
+
? [`Process killed: ${this.command}`, lastStdError]
|
|
201
|
+
: [`Process exit code: ${exitCode} (${this.command})`, lastStdError])
|
|
202
|
+
.filter((v) => typeof v === "string" && v.length)
|
|
203
|
+
.join(" | ");
|
|
199
204
|
if (typeof result === "function")
|
|
200
205
|
result = result(exitCode);
|
|
201
206
|
if (typeof result === "string") {
|
|
@@ -215,7 +220,7 @@ class AsyncProcess {
|
|
|
215
220
|
command: this.command,
|
|
216
221
|
argv: this.argv,
|
|
217
222
|
exitCode,
|
|
218
|
-
lastStdError
|
|
223
|
+
lastStdError,
|
|
219
224
|
},
|
|
220
225
|
});
|
|
221
226
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StdStreams } from "./stream";
|
|
2
2
|
import { Header } from "tty-table";
|
|
3
3
|
export type DataFormatType = "json" | "list" | "pjson" | "table" | "yaml" | "custom" | "tpl";
|
|
4
4
|
export declare const dataFormats: DataFormatType[];
|
|
5
5
|
export declare class DataFormat {
|
|
6
6
|
readonly options: {
|
|
7
|
-
streams?: Partial<
|
|
7
|
+
streams?: Partial<StdStreams>;
|
|
8
8
|
json: any;
|
|
9
9
|
list?: () => string[];
|
|
10
10
|
table?: {
|
|
@@ -12,9 +12,9 @@ export declare class DataFormat {
|
|
|
12
12
|
rows: () => (string | number | null | undefined)[][];
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
protected streams:
|
|
15
|
+
protected streams: StdStreams;
|
|
16
16
|
constructor(options: {
|
|
17
|
-
streams?: Partial<
|
|
17
|
+
streams?: Partial<StdStreams>;
|
|
18
18
|
json: any;
|
|
19
19
|
list?: () => string[];
|
|
20
20
|
table?: {
|
|
@@ -24,7 +24,7 @@ class DataFormat {
|
|
|
24
24
|
streams;
|
|
25
25
|
constructor(options) {
|
|
26
26
|
this.options = options;
|
|
27
|
-
this.streams = (0, stream_1.
|
|
27
|
+
this.streams = (0, stream_1.createStdStreams)(options.streams);
|
|
28
28
|
}
|
|
29
29
|
getJson() {
|
|
30
30
|
return this.options.json;
|
|
@@ -8,7 +8,7 @@ import { PruneCommand } from "../../commands/PruneCommand";
|
|
|
8
8
|
import { RestoreCommand } from "../../commands/RestoreCommand";
|
|
9
9
|
import { SnapshotsCommand } from "../../commands/SnapshotsCommand";
|
|
10
10
|
import { StartServerCommand } from "../../commands/StartServerCommand";
|
|
11
|
-
import {
|
|
11
|
+
import { StdStreams } from "../stream";
|
|
12
12
|
export declare const datatruckCommandMap: {
|
|
13
13
|
config: typeof ConfigCommand;
|
|
14
14
|
init: typeof InitCommand;
|
|
@@ -23,7 +23,7 @@ export declare const datatruckCommandMap: {
|
|
|
23
23
|
export type DatatruckCommandMap = typeof datatruckCommandMap;
|
|
24
24
|
export type InferDatatruckCommandOptions<T extends keyof DatatruckCommandMap> = InstanceType<DatatruckCommandMap[T]>["inputOptions"];
|
|
25
25
|
export type InferDatatruckCommandResult<T extends keyof DatatruckCommandMap, R = Awaited<ReturnType<InstanceType<DatatruckCommandMap[T]>["exec"]>>> = "result" extends keyof R ? R["result"] : undefined;
|
|
26
|
-
export declare function createCommand<T extends keyof DatatruckCommandMap>(name: T, globalOptions: GlobalOptions<true>, options: InferDatatruckCommandOptions<T>, streams?: Partial<
|
|
26
|
+
export declare function createCommand<T extends keyof DatatruckCommandMap>(name: T, globalOptions: GlobalOptions<true>, options: InferDatatruckCommandOptions<T>, streams?: Partial<StdStreams>, configPath?: string): BackupCommand | CopyCommand | PruneCommand | CleanCacheCommand | ConfigCommand | InitCommand | RestoreCommand | SnapshotsCommand | StartServerCommand;
|
|
27
27
|
export declare function createCommands(globalOptions: GlobalOptions<true>): {
|
|
28
28
|
[K in keyof DatatruckCommandMap as `${K}`]: (options: InferDatatruckCommandOptions<K>) => Promise<InferDatatruckCommandResult<K>>;
|
|
29
29
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PruneActionsOptions } from "../../actions/PruneAction";
|
|
2
|
-
import type { DataFormatType } from "../
|
|
2
|
+
import type { DataFormatType } from "../data-format";
|
|
3
3
|
import type { ReportStep } from "../reportSteps";
|
|
4
4
|
import type { SpawnStep } from "../spawnSteps";
|
|
5
5
|
import type { PackageRepositoryConfig, RepositoryConfigEnabledAction, RepositoryConfig } from "./config-repository-type";
|
package/lib/utils/fs.d.ts
CHANGED
|
@@ -38,12 +38,6 @@ export declare function writeGitIgnoreList(options: {
|
|
|
38
38
|
paths: NodeJS.ReadableStream | string[];
|
|
39
39
|
outDir: string;
|
|
40
40
|
}): Promise<string>;
|
|
41
|
-
export declare function waitForClose(stream: {
|
|
42
|
-
on(event: "close", cb: (...args: any[]) => any): any;
|
|
43
|
-
} | {
|
|
44
|
-
on(event: "close", cb: (...args: any[]) => any): any;
|
|
45
|
-
on(event: "error", cb: (...args: any[]) => any): any;
|
|
46
|
-
}): Promise<void>;
|
|
47
41
|
export declare function copyFileWithStreams(source: string, target: string): Promise<unknown>;
|
|
48
42
|
export declare function updateFileStats(path: string, fileInfo: Stats): Promise<void>;
|
|
49
43
|
export declare function isNotFoundError(error: unknown): boolean;
|