@datatruck/cli 0.23.3 → 0.25.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/Action/RestoreAction.d.ts +1 -2
- package/Action/RestoreAction.js +10 -14
- package/Command/BackupCommand.d.ts +1 -1
- package/Command/RestoreCommand.d.ts +1 -1
- package/Config/PackageConfig.d.ts +3 -8
- package/Config/PackageConfig.js +10 -29
- package/Factory/CommandFactory.d.ts +7 -0
- package/Factory/CommandFactory.js +39 -1
- package/JsonSchema/DefinitionEnum.d.ts +0 -1
- package/JsonSchema/DefinitionEnum.js +0 -1
- package/JsonSchema/JsonSchema.js +0 -1
- package/Repository/DatatruckRepository.js +8 -8
- package/Repository/GitRepository.js +7 -7
- package/Repository/ResticRepository.js +9 -12
- package/Task/ScriptTask.d.ts +25 -25
- package/Task/ScriptTask.js +44 -66
- package/Task/TaskAbstract.d.ts +7 -6
- package/Task/TaskAbstract.js +2 -6
- package/config.schema.json +8 -40
- package/package.json +1 -1
- package/utils/datatruck/config.d.ts +6 -6
- package/utils/datatruck/paths.d.ts +18 -2
- package/utils/datatruck/paths.js +21 -12
- package/utils/steps.d.ts +32 -0
- package/utils/steps.js +71 -0
- package/utils/string.d.ts +3 -1
- package/utils/string.js +3 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ConfigType } from "../Config/Config";
|
|
2
2
|
import { PackageConfigType } from "../Config/PackageConfig";
|
|
3
3
|
import { RepositoryConfigType } from "../Config/RepositoryConfig";
|
|
4
|
-
import { AppError } from "../Error/AppError";
|
|
5
4
|
import { SnapshotResultType } from "../Repository/RepositoryAbstract";
|
|
6
5
|
import { RestoreSessionManager } from "../SessionManager/RestoreSessionManager";
|
|
7
6
|
import { TaskAbstract } from "../Task/TaskAbstract";
|
|
@@ -38,7 +37,7 @@ export declare class RestoreAction<TRequired extends boolean = true> {
|
|
|
38
37
|
error: boolean;
|
|
39
38
|
tmpDirs: string[];
|
|
40
39
|
}>;
|
|
41
|
-
protected getError(pkg: PackageConfigType):
|
|
40
|
+
protected getError(pkg: PackageConfigType): Error | undefined;
|
|
42
41
|
exec(session: RestoreSessionManager): Promise<{
|
|
43
42
|
errors: Error[];
|
|
44
43
|
}>;
|
package/Action/RestoreAction.js
CHANGED
|
@@ -190,20 +190,16 @@ class RestoreAction {
|
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
getError(pkg) {
|
|
193
|
-
const taskErrors = this.taskErrors[pkg.name]
|
|
194
|
-
const repoErrors = this.repoErrors[pkg.name]
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
193
|
+
const taskErrors = this.taskErrors[pkg.name] || [];
|
|
194
|
+
const repoErrors = this.repoErrors[pkg.name] || [];
|
|
195
|
+
const errors = [...taskErrors, ...repoErrors];
|
|
196
|
+
if (!errors.length)
|
|
197
|
+
return;
|
|
198
|
+
return AppError_1.AppError.create(taskErrors.length && repoErrors.length
|
|
199
|
+
? "Task and repository failed"
|
|
200
|
+
: taskErrors.length && !repoErrors.length
|
|
201
|
+
? "Task failed"
|
|
202
|
+
: "Repository failed", errors);
|
|
207
203
|
}
|
|
208
204
|
async exec(session) {
|
|
209
205
|
if (!this.options.snapshotId)
|
|
@@ -12,5 +12,5 @@ export type BackupCommandOptionsType<TResolved = false> = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare class BackupCommand extends CommandAbstract<BackupCommandOptionsType<false>, BackupCommandOptionsType<true>> {
|
|
14
14
|
onOptions(): import("../utils/cli").OptionsType<BackupCommandOptionsType<false>, BackupCommandOptionsType<true>>;
|
|
15
|
-
onExec(): Promise<
|
|
15
|
+
onExec(): Promise<0 | 1>;
|
|
16
16
|
}
|
|
@@ -12,5 +12,5 @@ export type RestoreCommandOptionsType<TResolved = false> = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare class RestoreCommand extends CommandAbstract<RestoreCommandOptionsType<false>, RestoreCommandOptionsType<true>> {
|
|
14
14
|
onOptions(): import("../utils/cli").OptionsType<RestoreCommandOptionsType<false>, RestoreCommandOptionsType<true>>;
|
|
15
|
-
onExec(): Promise<
|
|
15
|
+
onExec(): Promise<0 | 1>;
|
|
16
16
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
+
import { Step } from "../utils/steps";
|
|
1
2
|
import { PackageRepositoryConfigType } from "./PackageRepositoryConfig";
|
|
2
3
|
import { PrunePolicyConfigType } from "./PrunePolicyConfig";
|
|
3
4
|
import type { TaskConfigType } from "./TaskConfig";
|
|
4
5
|
import { JSONSchema7 } from "json-schema";
|
|
5
6
|
export declare const packageConfigDefinition: JSONSchema7;
|
|
6
|
-
export declare const pathsObjectDefinition: JSONSchema7;
|
|
7
|
-
export type PathsObjectType = {
|
|
8
|
-
type: "spawn";
|
|
9
|
-
command: string;
|
|
10
|
-
args?: string[];
|
|
11
|
-
};
|
|
12
7
|
export type PackageConfigType = {
|
|
13
8
|
name: string;
|
|
14
9
|
enabled?: boolean;
|
|
@@ -19,8 +14,8 @@ export type PackageConfigType = {
|
|
|
19
14
|
uid: string | number;
|
|
20
15
|
gid: string | number;
|
|
21
16
|
};
|
|
22
|
-
include?: (string |
|
|
23
|
-
exclude?: (string |
|
|
17
|
+
include?: (string | Step)[];
|
|
18
|
+
exclude?: (string | Step)[];
|
|
24
19
|
repositoryNames?: string[];
|
|
25
20
|
prunePolicy?: PrunePolicyConfigType;
|
|
26
21
|
repositoryConfigs?: PackageRepositoryConfigType[];
|
package/Config/PackageConfig.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.packageConfigDefinition = void 0;
|
|
4
4
|
const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
|
|
5
|
+
const ScriptTask_1 = require("../Task/ScriptTask");
|
|
5
6
|
exports.packageConfigDefinition = {
|
|
6
7
|
type: "object",
|
|
7
8
|
required: ["name"],
|
|
@@ -24,13 +25,19 @@ exports.packageConfigDefinition = {
|
|
|
24
25
|
include: {
|
|
25
26
|
type: "array",
|
|
26
27
|
items: {
|
|
27
|
-
anyOf: [
|
|
28
|
+
anyOf: [
|
|
29
|
+
{ type: "string" },
|
|
30
|
+
(0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.scriptTask, ScriptTask_1.ScriptTaskDefinitionEnum.step),
|
|
31
|
+
],
|
|
28
32
|
},
|
|
29
33
|
},
|
|
30
34
|
exclude: {
|
|
31
35
|
type: "array",
|
|
32
36
|
items: {
|
|
33
|
-
anyOf: [
|
|
37
|
+
anyOf: [
|
|
38
|
+
{ type: "string" },
|
|
39
|
+
(0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.scriptTask, ScriptTask_1.ScriptTaskDefinitionEnum.step),
|
|
40
|
+
],
|
|
34
41
|
},
|
|
35
42
|
},
|
|
36
43
|
repositoryNames: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
|
|
@@ -41,29 +48,3 @@ exports.packageConfigDefinition = {
|
|
|
41
48
|
prunePolicy: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.prunePolicy),
|
|
42
49
|
},
|
|
43
50
|
};
|
|
44
|
-
exports.pathsObjectDefinition = {
|
|
45
|
-
type: "object",
|
|
46
|
-
required: ["type"],
|
|
47
|
-
properties: {
|
|
48
|
-
type: { type: "string" },
|
|
49
|
-
},
|
|
50
|
-
anyOf: [
|
|
51
|
-
{
|
|
52
|
-
if: {
|
|
53
|
-
type: "object",
|
|
54
|
-
properties: {
|
|
55
|
-
type: { const: "spawn" },
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
then: {
|
|
59
|
-
type: "object",
|
|
60
|
-
required: ["command"],
|
|
61
|
-
properties: {
|
|
62
|
-
command: { type: "string" },
|
|
63
|
-
args: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
else: false,
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
@@ -38,5 +38,12 @@ export type LogMapType = {
|
|
|
38
38
|
};
|
|
39
39
|
export declare function CommandFactory<TCommand extends keyof OptionsMapType>(type: TCommand, globalOptions: GlobalOptionsType<false>, options: OptionsMapType[TCommand]): CleanCacheCommand;
|
|
40
40
|
export declare function exec<TCommand extends keyof OptionsMapType>(type: TCommand, globalOptions: GlobalOptionsType<false>, options: OptionsMapType[TCommand]): Promise<number>;
|
|
41
|
+
export declare function createActionInterface(globalOptions: GlobalOptionsType<false>): {
|
|
42
|
+
[K in keyof OptionsMapType as `${K}`]: (options: OptionsMapType[K]) => Promise<K extends keyof LogMapType ? LogMapType[K] : never>;
|
|
43
|
+
};
|
|
44
|
+
export declare function runAndParse<TCommand extends keyof LogMapType>(type: TCommand, run: () => Promise<any>): Promise<{
|
|
45
|
+
exitCode: any;
|
|
46
|
+
log: LogMapType[TCommand];
|
|
47
|
+
}>;
|
|
41
48
|
export declare function makeParseLog<TCommand extends keyof LogMapType>(type: TCommand): () => LogMapType[TCommand];
|
|
42
49
|
export declare function CommandConstructorFactory(type: CommandEnum): typeof CleanCacheCommand;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandConstructorFactory = exports.makeParseLog = exports.exec = exports.CommandFactory = exports.CommandEnum = void 0;
|
|
3
|
+
exports.CommandConstructorFactory = exports.makeParseLog = exports.runAndParse = exports.createActionInterface = exports.exec = exports.CommandFactory = exports.CommandEnum = void 0;
|
|
4
4
|
const BackupCommand_1 = require("../Command/BackupCommand");
|
|
5
5
|
const BackupSessionsCommand_1 = require("../Command/BackupSessionsCommand");
|
|
6
6
|
const CleanCacheCommand_1 = require("../Command/CleanCacheCommand");
|
|
@@ -32,6 +32,44 @@ async function exec(type, globalOptions, options) {
|
|
|
32
32
|
return await CommandFactory(type, globalOptions, options).onExec();
|
|
33
33
|
}
|
|
34
34
|
exports.exec = exec;
|
|
35
|
+
function createActionInterface(globalOptions) {
|
|
36
|
+
const object = {};
|
|
37
|
+
for (const type of Object.values(CommandEnum)) {
|
|
38
|
+
object[type] = async (options) => {
|
|
39
|
+
const run = () => exec(type, { ...globalOptions, outputFormat: "json", verbose: 1 }, options);
|
|
40
|
+
let exitCode;
|
|
41
|
+
let log;
|
|
42
|
+
if (["config", "init", "snapshots"].includes(type)) {
|
|
43
|
+
const parsed = await runAndParse(type, run);
|
|
44
|
+
exitCode = parsed.exitCode;
|
|
45
|
+
log = parsed.log;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
exitCode = await run();
|
|
49
|
+
}
|
|
50
|
+
if (exitCode !== 0)
|
|
51
|
+
throw new Error(`Invalid exit code: ${exitCode}`);
|
|
52
|
+
return log;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return object;
|
|
56
|
+
}
|
|
57
|
+
exports.createActionInterface = createActionInterface;
|
|
58
|
+
async function runAndParse(type, run) {
|
|
59
|
+
const parseLog = makeParseLog(type);
|
|
60
|
+
try {
|
|
61
|
+
const exitCode = await run();
|
|
62
|
+
return { exitCode, log: parseLog() };
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
try {
|
|
66
|
+
parseLog();
|
|
67
|
+
}
|
|
68
|
+
catch (_) { }
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.runAndParse = runAndParse;
|
|
35
73
|
function makeParseLog(type) {
|
|
36
74
|
const data = [];
|
|
37
75
|
const consoleLog = console.log;
|
|
@@ -19,7 +19,6 @@ export declare enum DefinitionEnum {
|
|
|
19
19
|
sqlDumpTask = "sqldump-task",
|
|
20
20
|
stringListUtil = "stringlist-util",
|
|
21
21
|
prunePolicy = "prune-policy",
|
|
22
|
-
pathsObject = "paths-object",
|
|
23
22
|
compressUtil = "compress-util"
|
|
24
23
|
}
|
|
25
24
|
export declare function makeRef(type: DefinitionEnum, subType?: string): {
|
|
@@ -23,7 +23,6 @@ var DefinitionEnum;
|
|
|
23
23
|
DefinitionEnum["sqlDumpTask"] = "sqldump-task";
|
|
24
24
|
DefinitionEnum["stringListUtil"] = "stringlist-util";
|
|
25
25
|
DefinitionEnum["prunePolicy"] = "prune-policy";
|
|
26
|
-
DefinitionEnum["pathsObject"] = "paths-object";
|
|
27
26
|
DefinitionEnum["compressUtil"] = "compress-util";
|
|
28
27
|
})(DefinitionEnum || (exports.DefinitionEnum = DefinitionEnum = {}));
|
|
29
28
|
function makeRef(type, subType) {
|
package/JsonSchema/JsonSchema.js
CHANGED
|
@@ -45,7 +45,6 @@ exports.definitions = {
|
|
|
45
45
|
[DefinitionEnum_1.DefinitionEnum.postgresqlDumpTask]: PostgresqlDumpTask_1.postgresqlDumpTaskDefinition,
|
|
46
46
|
[DefinitionEnum_1.DefinitionEnum.config]: Config_1.configDefinition,
|
|
47
47
|
[DefinitionEnum_1.DefinitionEnum.prunePolicy]: PrunePolicyConfig_1.prunePolicyConfigDefinition,
|
|
48
|
-
[DefinitionEnum_1.DefinitionEnum.pathsObject]: PackageConfig_1.pathsObjectDefinition,
|
|
49
48
|
[DefinitionEnum_1.DefinitionEnum.compressUtil]: tar_1.compressDefinition,
|
|
50
49
|
};
|
|
51
50
|
for (const key in exports.definitions) {
|
|
@@ -159,20 +159,20 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
159
159
|
const sourcePath = data.targetPath ?? pkg.path;
|
|
160
160
|
(0, assert_1.ok)(sourcePath);
|
|
161
161
|
await (0, promises_1.mkdir)(outPath, { recursive: true });
|
|
162
|
+
const backupPathsOptions = {
|
|
163
|
+
package: data.package,
|
|
164
|
+
snapshot: data.snapshot,
|
|
165
|
+
targetPath: sourcePath,
|
|
166
|
+
verbose: data.options.verbose,
|
|
167
|
+
};
|
|
162
168
|
const scanner = await (0, fs_1.createFileScanner)({
|
|
163
169
|
onProgress: data.onProgress,
|
|
164
170
|
glob: {
|
|
165
171
|
cwd: sourcePath,
|
|
166
172
|
onlyFiles: false,
|
|
167
|
-
include: await (0, paths_1.
|
|
168
|
-
cwd: sourcePath,
|
|
169
|
-
verbose: data.options.verbose,
|
|
170
|
-
}),
|
|
173
|
+
include: await (0, paths_1.parseBackupPaths)(pkg.include ?? ["**"], backupPathsOptions),
|
|
171
174
|
ignore: pkg.exclude
|
|
172
|
-
? await (0, paths_1.
|
|
173
|
-
cwd: sourcePath,
|
|
174
|
-
verbose: data.options.verbose,
|
|
175
|
-
})
|
|
175
|
+
? await (0, paths_1.parseBackupPaths)(pkg.exclude, backupPathsOptions)
|
|
176
176
|
: undefined,
|
|
177
177
|
},
|
|
178
178
|
});
|
|
@@ -166,15 +166,15 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
166
166
|
});
|
|
167
167
|
await git.removeAll();
|
|
168
168
|
const createdPaths = [];
|
|
169
|
-
const
|
|
170
|
-
|
|
169
|
+
const backupPathsOptions = {
|
|
170
|
+
package: data.package,
|
|
171
|
+
snapshot: data.snapshot,
|
|
172
|
+
targetPath: sourcePath,
|
|
171
173
|
verbose: data.options.verbose,
|
|
172
|
-
}
|
|
174
|
+
};
|
|
175
|
+
const include = await (0, paths_1.parseBackupPaths)(pkg.include ?? ["**"], backupPathsOptions);
|
|
173
176
|
const exclude = pkg.exclude
|
|
174
|
-
? await (0, paths_1.
|
|
175
|
-
cwd: sourcePath,
|
|
176
|
-
verbose: data.options.verbose,
|
|
177
|
-
})
|
|
177
|
+
? await (0, paths_1.parseBackupPaths)(pkg.exclude, backupPathsOptions)
|
|
178
178
|
: undefined;
|
|
179
179
|
const stream = await (0, fast_glob_1.default)(include, {
|
|
180
180
|
cwd: sourcePath,
|
|
@@ -191,11 +191,14 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
191
191
|
const sourcePath = data.targetPath ?? data.package.path;
|
|
192
192
|
(0, assert_1.ok)(sourcePath);
|
|
193
193
|
let gitignorePath;
|
|
194
|
+
const backupPathsOptions = {
|
|
195
|
+
package: data.package,
|
|
196
|
+
snapshot: data.snapshot,
|
|
197
|
+
targetPath: sourcePath,
|
|
198
|
+
verbose: data.options.verbose,
|
|
199
|
+
};
|
|
194
200
|
if (!pkg.include && pkg.exclude) {
|
|
195
|
-
const exclude = await (0, paths_1.
|
|
196
|
-
cwd: sourcePath,
|
|
197
|
-
verbose: data.options.verbose,
|
|
198
|
-
});
|
|
201
|
+
const exclude = await (0, paths_1.parseBackupPaths)(pkg.exclude, backupPathsOptions);
|
|
199
202
|
await data.onProgress({
|
|
200
203
|
relative: {
|
|
201
204
|
description: "Writing excluded paths list",
|
|
@@ -207,15 +210,9 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
207
210
|
await (0, promises_1.writeFile)(gitignorePath, ignoredContents);
|
|
208
211
|
}
|
|
209
212
|
else if (pkg.include || pkg.exclude) {
|
|
210
|
-
const include = await (0, paths_1.
|
|
211
|
-
cwd: sourcePath,
|
|
212
|
-
verbose: data.options.verbose,
|
|
213
|
-
});
|
|
213
|
+
const include = await (0, paths_1.parseBackupPaths)(pkg.include ?? ["**"], backupPathsOptions);
|
|
214
214
|
const exclude = pkg.exclude
|
|
215
|
-
? await (0, paths_1.
|
|
216
|
-
cwd: sourcePath,
|
|
217
|
-
verbose: data.options.verbose,
|
|
218
|
-
})
|
|
215
|
+
? await (0, paths_1.parseBackupPaths)(pkg.exclude, backupPathsOptions)
|
|
219
216
|
: undefined;
|
|
220
217
|
const stream = fast_glob_1.default.stream(include, {
|
|
221
218
|
cwd: sourcePath,
|
package/Task/ScriptTask.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Step } from "../utils/steps";
|
|
2
|
+
import { BackupDataType, BeforeBackupDataType, BeforeRestoreDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
|
|
2
3
|
import { JSONSchema7 } from "json-schema";
|
|
3
|
-
export type ProcessStepConfig = {
|
|
4
|
-
command: string;
|
|
5
|
-
env?: Record<string, string>;
|
|
6
|
-
args?: string[];
|
|
7
|
-
};
|
|
8
|
-
export type NodeStepConfig = {
|
|
9
|
-
env?: Record<string, string>;
|
|
10
|
-
code: string | string[];
|
|
11
|
-
};
|
|
12
|
-
export type Step = {
|
|
13
|
-
type: "process";
|
|
14
|
-
config: ProcessStepConfig;
|
|
15
|
-
} | {
|
|
16
|
-
type: "node";
|
|
17
|
-
config: NodeStepConfig;
|
|
18
|
-
};
|
|
19
4
|
export type ScriptTaskConfigType = {
|
|
20
5
|
env?: Record<string, string | undefined>;
|
|
21
6
|
backupSteps: Step[];
|
|
22
7
|
restoreSteps: Step[];
|
|
23
8
|
};
|
|
9
|
+
export declare enum ScriptTaskDefinitionEnum {
|
|
10
|
+
step = "step",
|
|
11
|
+
processStepConfig = "processStepConfig",
|
|
12
|
+
nodeStepConfig = "nodeStepConfig"
|
|
13
|
+
}
|
|
24
14
|
export declare const scriptTaskName = "script";
|
|
25
15
|
export declare const scriptTaskDefinition: JSONSchema7;
|
|
26
16
|
export declare class ScriptTask extends TaskAbstract<ScriptTaskConfigType> {
|
|
27
17
|
protected verbose?: boolean;
|
|
28
|
-
onBeforeBackup(): Promise<{
|
|
18
|
+
onBeforeBackup(data: BeforeBackupDataType): Promise<{
|
|
29
19
|
targetPath: string;
|
|
30
20
|
}>;
|
|
31
|
-
protected getVars(data: BackupDataType | RestoreDataType):
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
protected getVars(data: BackupDataType | RestoreDataType): {
|
|
22
|
+
process: {
|
|
23
|
+
DTT_SNAPSHOT_ID: string;
|
|
24
|
+
DTT_SNAPSHOT_DATE: string;
|
|
25
|
+
DTT_PACKAGE_NAME: string;
|
|
26
|
+
DTT_PACKAGE_PATH: string | undefined;
|
|
27
|
+
DTT_TARGET_PATH: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
node: {
|
|
30
|
+
dtt: {
|
|
31
|
+
snapshot: import("../Repository/RepositoryAbstract").SnapshotType;
|
|
32
|
+
package: import("../Config/PackageConfig").PackageConfigType;
|
|
33
|
+
targetPath: string | undefined;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
37
|
onBackup(data: BackupDataType): Promise<void>;
|
|
38
|
-
onBeforeRestore(): Promise<{
|
|
38
|
+
onBeforeRestore(data: BeforeRestoreDataType): Promise<{
|
|
39
39
|
targetPath: string;
|
|
40
40
|
}>;
|
|
41
41
|
onRestore(data: RestoreDataType): Promise<void>;
|
package/Task/ScriptTask.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = void 0;
|
|
3
|
+
exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = exports.ScriptTaskDefinitionEnum = void 0;
|
|
4
4
|
const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
|
|
5
5
|
const fs_1 = require("../utils/fs");
|
|
6
|
-
const
|
|
7
|
-
const string_1 = require("../utils/string");
|
|
6
|
+
const steps_1 = require("../utils/steps");
|
|
8
7
|
const TaskAbstract_1 = require("./TaskAbstract");
|
|
9
8
|
const assert_1 = require("assert");
|
|
10
|
-
const promises_1 = require("fs/promises");
|
|
11
|
-
const path_1 = require("path");
|
|
12
9
|
var ScriptTaskDefinitionEnum;
|
|
13
10
|
(function (ScriptTaskDefinitionEnum) {
|
|
14
11
|
ScriptTaskDefinitionEnum["step"] = "step";
|
|
15
12
|
ScriptTaskDefinitionEnum["processStepConfig"] = "processStepConfig";
|
|
16
13
|
ScriptTaskDefinitionEnum["nodeStepConfig"] = "nodeStepConfig";
|
|
17
|
-
})(ScriptTaskDefinitionEnum || (ScriptTaskDefinitionEnum = {}));
|
|
14
|
+
})(ScriptTaskDefinitionEnum || (exports.ScriptTaskDefinitionEnum = ScriptTaskDefinitionEnum = {}));
|
|
18
15
|
const stepTypes = {
|
|
19
16
|
process: ScriptTaskDefinitionEnum.processStepConfig,
|
|
20
17
|
node: ScriptTaskDefinitionEnum.nodeStepConfig,
|
|
@@ -64,6 +61,10 @@ exports.scriptTaskDefinition = {
|
|
|
64
61
|
code: {
|
|
65
62
|
anyOf: [{ type: "string" }, (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil)],
|
|
66
63
|
},
|
|
64
|
+
vars: {
|
|
65
|
+
type: "object",
|
|
66
|
+
patternProperties: { ".+": {} },
|
|
67
|
+
},
|
|
67
68
|
env: {
|
|
68
69
|
type: "object",
|
|
69
70
|
patternProperties: { ".+": { type: "string" } },
|
|
@@ -93,88 +94,65 @@ exports.scriptTaskDefinition = {
|
|
|
93
94
|
};
|
|
94
95
|
class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
95
96
|
verbose;
|
|
96
|
-
async onBeforeBackup() {
|
|
97
|
+
async onBeforeBackup(data) {
|
|
97
98
|
return {
|
|
98
|
-
targetPath: await this.mkTmpDir(
|
|
99
|
+
targetPath: data.package.path ?? (await this.mkTmpDir(`script-task_backup_target`)),
|
|
99
100
|
};
|
|
100
101
|
}
|
|
101
102
|
getVars(data) {
|
|
102
103
|
return {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
process: {
|
|
105
|
+
DTT_SNAPSHOT_ID: data.snapshot.id,
|
|
106
|
+
DTT_SNAPSHOT_DATE: data.snapshot.date,
|
|
107
|
+
DTT_PACKAGE_NAME: data.package.name,
|
|
108
|
+
DTT_PACKAGE_PATH: data.package.path,
|
|
109
|
+
DTT_TARGET_PATH: data.targetPath,
|
|
110
|
+
},
|
|
111
|
+
node: {
|
|
112
|
+
dtt: {
|
|
113
|
+
snapshot: data.snapshot,
|
|
114
|
+
package: data.package,
|
|
115
|
+
targetPath: data.targetPath,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
108
118
|
};
|
|
109
119
|
}
|
|
110
|
-
async processSteps(input, options) {
|
|
111
|
-
const steps = Array.isArray(input) ? input : [input];
|
|
112
|
-
for (const step of steps) {
|
|
113
|
-
if (step.type === "process") {
|
|
114
|
-
await (0, process_1.exec)(step.config.command, (step.config.args || []).map((v) => (0, string_1.render)(v, options.vars)), {
|
|
115
|
-
env: {
|
|
116
|
-
...process.env,
|
|
117
|
-
...options.vars,
|
|
118
|
-
...options.env,
|
|
119
|
-
...step.config.env,
|
|
120
|
-
},
|
|
121
|
-
}, {
|
|
122
|
-
log: options.verbose,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
else if (step.type === "node") {
|
|
126
|
-
const tempDir = await this.mkTmpDir("script-task-node-step");
|
|
127
|
-
const scriptPath = (0, path_1.join)(tempDir, "script.js");
|
|
128
|
-
await (0, promises_1.writeFile)(scriptPath, Array.isArray(step.config.code)
|
|
129
|
-
? step.config.code.join("\n")
|
|
130
|
-
: step.config.code);
|
|
131
|
-
await (0, process_1.exec)("node", [scriptPath], {
|
|
132
|
-
env: {
|
|
133
|
-
...process.env,
|
|
134
|
-
...options.vars,
|
|
135
|
-
...options.env,
|
|
136
|
-
...step.config.env,
|
|
137
|
-
},
|
|
138
|
-
}, {
|
|
139
|
-
log: options.verbose,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
throw new Error(`Invalid step type: ${step.type}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
120
|
async onBackup(data) {
|
|
148
|
-
this.verbose = data.options.verbose;
|
|
149
121
|
const config = this.config;
|
|
150
|
-
const path = data.package.path;
|
|
151
122
|
const targetPath = data.targetPath;
|
|
152
|
-
(0, assert_1.ok)(typeof path === "string");
|
|
153
123
|
(0, assert_1.ok)(typeof targetPath === "string");
|
|
154
|
-
|
|
124
|
+
const vars = this.getVars(data);
|
|
125
|
+
await (0, fs_1.mkdirIfNotExists)(targetPath);
|
|
126
|
+
await (0, steps_1.runSteps)(config.backupSteps, {
|
|
155
127
|
env: config.env,
|
|
156
|
-
|
|
157
|
-
|
|
128
|
+
verbose: data.options.verbose,
|
|
129
|
+
process: { vars: vars.process },
|
|
130
|
+
node: {
|
|
131
|
+
tempDir: () => this.mkTmpDir("script-task_backup_node-step"),
|
|
132
|
+
vars: vars.node,
|
|
133
|
+
},
|
|
158
134
|
});
|
|
159
135
|
}
|
|
160
|
-
async onBeforeRestore() {
|
|
136
|
+
async onBeforeRestore(data) {
|
|
161
137
|
return {
|
|
162
|
-
targetPath:
|
|
138
|
+
targetPath: data.package.restorePath ??
|
|
139
|
+
(await this.mkTmpDir(`script-task_restore_target`)),
|
|
163
140
|
};
|
|
164
141
|
}
|
|
165
142
|
async onRestore(data) {
|
|
166
|
-
this.verbose = data.options.verbose;
|
|
167
143
|
const config = this.config;
|
|
168
|
-
const restorePath = data.package.restorePath;
|
|
169
144
|
const targetPath = data.targetPath;
|
|
170
|
-
(0, assert_1.ok)(typeof restorePath === "string");
|
|
171
145
|
(0, assert_1.ok)(typeof targetPath === "string");
|
|
172
|
-
await (0, fs_1.mkdirIfNotExists)(
|
|
173
|
-
|
|
174
|
-
await
|
|
146
|
+
await (0, fs_1.mkdirIfNotExists)(targetPath);
|
|
147
|
+
const vars = this.getVars(data);
|
|
148
|
+
await (0, steps_1.runSteps)(config.restoreSteps, {
|
|
175
149
|
env: config.env,
|
|
176
|
-
|
|
177
|
-
|
|
150
|
+
verbose: data.options.verbose,
|
|
151
|
+
process: { vars: vars.process },
|
|
152
|
+
node: {
|
|
153
|
+
tempDir: () => this.mkTmpDir("script-task_restore_node-step"),
|
|
154
|
+
vars: vars.node,
|
|
155
|
+
},
|
|
178
156
|
});
|
|
179
157
|
}
|
|
180
158
|
}
|
package/Task/TaskAbstract.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type BackupDataType = {
|
|
|
10
10
|
targetPath: string | undefined;
|
|
11
11
|
snapshot: SnapshotType;
|
|
12
12
|
};
|
|
13
|
+
export type BeforeBackupDataType = Omit<BackupDataType, "onProgress" | "targetPath">;
|
|
13
14
|
export type RestoreDataType = {
|
|
14
15
|
onProgress: (data: Progress) => Promise<void>;
|
|
15
16
|
options: RestoreActionOptionsType;
|
|
@@ -17,17 +18,17 @@ export type RestoreDataType = {
|
|
|
17
18
|
targetPath: string | undefined;
|
|
18
19
|
snapshot: SnapshotType;
|
|
19
20
|
};
|
|
21
|
+
export type BeforeRestoreDataType = Omit<RestoreDataType, "onProgress" | "targetPath">;
|
|
22
|
+
export type BeforeReturn = Promise<{
|
|
23
|
+
targetPath?: string;
|
|
24
|
+
} | undefined | void>;
|
|
20
25
|
export declare abstract class TaskAbstract<TConfig = any> {
|
|
21
26
|
readonly config: TConfig;
|
|
22
27
|
readonly tmpDirs: string[];
|
|
23
28
|
constructor(config: TConfig);
|
|
24
29
|
mkTmpDir(prefix: string, id?: string): Promise<string>;
|
|
25
|
-
onBeforeBackup(data:
|
|
26
|
-
targetPath?: string;
|
|
27
|
-
} | undefined>;
|
|
30
|
+
onBeforeBackup(data: BeforeBackupDataType): BeforeReturn;
|
|
28
31
|
onBackup(data: BackupDataType): Promise<void>;
|
|
29
|
-
onBeforeRestore(data:
|
|
30
|
-
targetPath?: string;
|
|
31
|
-
} | undefined>;
|
|
32
|
+
onBeforeRestore(data: BeforeRestoreDataType): BeforeReturn;
|
|
32
33
|
onRestore(data: RestoreDataType): Promise<void>;
|
|
33
34
|
}
|
package/Task/TaskAbstract.js
CHANGED
|
@@ -13,13 +13,9 @@ class TaskAbstract {
|
|
|
13
13
|
this.tmpDirs.push(dir);
|
|
14
14
|
return dir;
|
|
15
15
|
}
|
|
16
|
-
async onBeforeBackup(data) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
16
|
+
async onBeforeBackup(data) { }
|
|
19
17
|
async onBackup(data) { }
|
|
20
|
-
async onBeforeRestore(data) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
18
|
+
async onBeforeRestore(data) { }
|
|
23
19
|
async onRestore(data) { }
|
|
24
20
|
}
|
|
25
21
|
exports.TaskAbstract = TaskAbstract;
|
package/config.schema.json
CHANGED
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
"type": "string"
|
|
177
177
|
},
|
|
178
178
|
{
|
|
179
|
-
"$ref": "#/definitions/
|
|
179
|
+
"$ref": "#/definitions/script-task_step"
|
|
180
180
|
}
|
|
181
181
|
]
|
|
182
182
|
}
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"type": "string"
|
|
190
190
|
},
|
|
191
191
|
{
|
|
192
|
-
"$ref": "#/definitions/
|
|
192
|
+
"$ref": "#/definitions/script-task_step"
|
|
193
193
|
}
|
|
194
194
|
]
|
|
195
195
|
}
|
|
@@ -1036,44 +1036,6 @@
|
|
|
1036
1036
|
}
|
|
1037
1037
|
}
|
|
1038
1038
|
},
|
|
1039
|
-
"paths-object": {
|
|
1040
|
-
"type": "object",
|
|
1041
|
-
"required": [
|
|
1042
|
-
"type"
|
|
1043
|
-
],
|
|
1044
|
-
"properties": {
|
|
1045
|
-
"type": {
|
|
1046
|
-
"type": "string"
|
|
1047
|
-
}
|
|
1048
|
-
},
|
|
1049
|
-
"anyOf": [
|
|
1050
|
-
{
|
|
1051
|
-
"if": {
|
|
1052
|
-
"type": "object",
|
|
1053
|
-
"properties": {
|
|
1054
|
-
"type": {
|
|
1055
|
-
"const": "spawn"
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
},
|
|
1059
|
-
"then": {
|
|
1060
|
-
"type": "object",
|
|
1061
|
-
"required": [
|
|
1062
|
-
"command"
|
|
1063
|
-
],
|
|
1064
|
-
"properties": {
|
|
1065
|
-
"command": {
|
|
1066
|
-
"type": "string"
|
|
1067
|
-
},
|
|
1068
|
-
"args": {
|
|
1069
|
-
"$ref": "#/definitions/stringlist-util"
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
},
|
|
1073
|
-
"else": false
|
|
1074
|
-
}
|
|
1075
|
-
]
|
|
1076
|
-
},
|
|
1077
1039
|
"compress-util": {
|
|
1078
1040
|
"type": "object",
|
|
1079
1041
|
"additionalProperties": false,
|
|
@@ -1194,6 +1156,12 @@
|
|
|
1194
1156
|
}
|
|
1195
1157
|
]
|
|
1196
1158
|
},
|
|
1159
|
+
"vars": {
|
|
1160
|
+
"type": "object",
|
|
1161
|
+
"patternProperties": {
|
|
1162
|
+
".+": {}
|
|
1163
|
+
}
|
|
1164
|
+
},
|
|
1197
1165
|
"env": {
|
|
1198
1166
|
"type": "object",
|
|
1199
1167
|
"patternProperties": {
|
package/package.json
CHANGED
|
@@ -32,15 +32,15 @@ export declare const pkgPathParams: {
|
|
|
32
32
|
};
|
|
33
33
|
export declare const pkgIncludeParams: {
|
|
34
34
|
packageName: string;
|
|
35
|
-
snapshotId: string;
|
|
36
35
|
temp: string;
|
|
36
|
+
snapshotId: string;
|
|
37
37
|
snapshotDate: string;
|
|
38
38
|
action: string;
|
|
39
39
|
};
|
|
40
40
|
export declare const pkgExcludeParams: {
|
|
41
41
|
packageName: string;
|
|
42
|
-
snapshotId: string;
|
|
43
42
|
temp: string;
|
|
43
|
+
snapshotId: string;
|
|
44
44
|
snapshotDate: string;
|
|
45
45
|
action: string;
|
|
46
46
|
};
|
|
@@ -53,30 +53,30 @@ export declare const dbNameParams: {
|
|
|
53
53
|
export declare const params: {
|
|
54
54
|
pkgPath: {
|
|
55
55
|
packageName: string;
|
|
56
|
-
snapshotId: string;
|
|
57
56
|
temp: string;
|
|
57
|
+
snapshotId: string;
|
|
58
58
|
snapshotDate: string;
|
|
59
59
|
action: string;
|
|
60
60
|
};
|
|
61
61
|
pkgRestorePath: {
|
|
62
62
|
path: string;
|
|
63
63
|
packageName: string;
|
|
64
|
-
snapshotId: string;
|
|
65
64
|
temp: string;
|
|
65
|
+
snapshotId: string;
|
|
66
66
|
snapshotDate: string;
|
|
67
67
|
action: string;
|
|
68
68
|
};
|
|
69
69
|
pkgInclude: {
|
|
70
70
|
packageName: string;
|
|
71
|
-
snapshotId: string;
|
|
72
71
|
temp: string;
|
|
72
|
+
snapshotId: string;
|
|
73
73
|
snapshotDate: string;
|
|
74
74
|
action: string;
|
|
75
75
|
};
|
|
76
76
|
pkgExclude: {
|
|
77
77
|
packageName: string;
|
|
78
|
-
snapshotId: string;
|
|
79
78
|
temp: string;
|
|
79
|
+
snapshotId: string;
|
|
80
80
|
snapshotDate: string;
|
|
81
81
|
action: string;
|
|
82
82
|
};
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { PackageConfigType } from "../../Config/PackageConfig";
|
|
2
|
+
import { SnapshotType } from "../../Repository/RepositoryAbstract";
|
|
3
|
+
import { Step } from "../steps";
|
|
4
|
+
export type ParsePathsOptions = {
|
|
3
5
|
cwd?: string;
|
|
4
6
|
verbose?: boolean;
|
|
7
|
+
vars?: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export declare function parsePaths(values: (string | Step)[], options: {
|
|
10
|
+
cwd?: string;
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
vars?: Record<string, any>;
|
|
13
|
+
tempDir?: () => Promise<string>;
|
|
5
14
|
}): Promise<string[]>;
|
|
15
|
+
export type BackupPathsOptions = {
|
|
16
|
+
package: PackageConfigType;
|
|
17
|
+
snapshot: SnapshotType;
|
|
18
|
+
targetPath: string;
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare function parseBackupPaths(paths: (string | Step)[], options: BackupPathsOptions): Promise<string[]>;
|
package/utils/datatruck/paths.js
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePaths = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.parseBackupPaths = exports.parsePaths = void 0;
|
|
4
|
+
const steps_1 = require("../steps");
|
|
5
5
|
async function parsePaths(values, options) {
|
|
6
6
|
let paths = [];
|
|
7
7
|
for (const value of values) {
|
|
8
8
|
if (typeof value === "string") {
|
|
9
9
|
paths.push(value);
|
|
10
10
|
}
|
|
11
|
-
else
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
else {
|
|
12
|
+
await (0, steps_1.runSteps)(value, {
|
|
13
|
+
node: { tempDir: options.tempDir },
|
|
14
|
+
verbose: options.verbose,
|
|
15
|
+
onLine: (path) => paths.push(path),
|
|
16
16
|
});
|
|
17
|
-
const spawnFiles = [spawnResult.stderr, spawnResult.stdout].flatMap((text) => text
|
|
18
|
-
.split(/\r?\n/)
|
|
19
|
-
.map((v) => v.trim())
|
|
20
|
-
.filter((v) => !!v.length));
|
|
21
|
-
paths.push(...spawnFiles);
|
|
22
17
|
}
|
|
23
18
|
}
|
|
24
19
|
return paths;
|
|
25
20
|
}
|
|
26
21
|
exports.parsePaths = parsePaths;
|
|
22
|
+
async function parseBackupPaths(paths, options) {
|
|
23
|
+
return parsePaths(paths, {
|
|
24
|
+
cwd: options.targetPath,
|
|
25
|
+
verbose: options.verbose,
|
|
26
|
+
vars: {
|
|
27
|
+
dtt: {
|
|
28
|
+
package: options.package,
|
|
29
|
+
snapshot: options.snapshot,
|
|
30
|
+
targetPath: options.targetPath,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.parseBackupPaths = parseBackupPaths;
|
package/utils/steps.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type StepEnv = Record<string, string>;
|
|
2
|
+
export type ProcessStepConfig = {
|
|
3
|
+
command: string;
|
|
4
|
+
env?: StepEnv;
|
|
5
|
+
args?: string[];
|
|
6
|
+
};
|
|
7
|
+
export type NodeStepConfig = {
|
|
8
|
+
env?: StepEnv;
|
|
9
|
+
vars?: Record<string, any>;
|
|
10
|
+
code: string | string[];
|
|
11
|
+
};
|
|
12
|
+
export type Step = {
|
|
13
|
+
type: "process";
|
|
14
|
+
config: ProcessStepConfig;
|
|
15
|
+
} | {
|
|
16
|
+
type: "node";
|
|
17
|
+
config: NodeStepConfig;
|
|
18
|
+
};
|
|
19
|
+
export type StepOptions = {
|
|
20
|
+
env?: Record<string, string | undefined>;
|
|
21
|
+
process?: {
|
|
22
|
+
vars?: Record<string, string | undefined>;
|
|
23
|
+
};
|
|
24
|
+
node?: {
|
|
25
|
+
vars?: Record<string, any>;
|
|
26
|
+
tempDir?: () => Promise<string>;
|
|
27
|
+
};
|
|
28
|
+
cwd?: string;
|
|
29
|
+
onLine?: (p: string) => any;
|
|
30
|
+
verbose?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare function runSteps(input: Step[] | Step, options: StepOptions): Promise<void>;
|
package/utils/steps.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSteps = void 0;
|
|
4
|
+
const fs_1 = require("./fs");
|
|
5
|
+
const process_1 = require("./process");
|
|
6
|
+
const string_1 = require("./string");
|
|
7
|
+
const promises_1 = require("fs/promises");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
async function runSteps(input, options) {
|
|
10
|
+
const steps = Array.isArray(input) ? input : [input];
|
|
11
|
+
for (const step of steps) {
|
|
12
|
+
if (step.type === "process") {
|
|
13
|
+
await (0, process_1.exec)(step.config.command, (step.config.args || []).map((v) => (0, string_1.render)(v, options.process?.vars || {})), {
|
|
14
|
+
cwd: options.cwd,
|
|
15
|
+
env: {
|
|
16
|
+
...process.env,
|
|
17
|
+
...options.env,
|
|
18
|
+
...step.config.env,
|
|
19
|
+
},
|
|
20
|
+
}, {
|
|
21
|
+
log: options.verbose,
|
|
22
|
+
...(options.onLine && {
|
|
23
|
+
stdout: {
|
|
24
|
+
parseLines: "skip-empty",
|
|
25
|
+
onData: (line) => options.onLine(line),
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if (step.type === "node") {
|
|
31
|
+
let tempDir;
|
|
32
|
+
if (options.node?.tempDir) {
|
|
33
|
+
tempDir = await options.node.tempDir();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
tempDir = await (0, fs_1.mkTmpDir)("node-step");
|
|
37
|
+
}
|
|
38
|
+
const scriptPath = (0, path_1.join)(tempDir, "script.js");
|
|
39
|
+
const vars = Object.entries({
|
|
40
|
+
...step.config.vars,
|
|
41
|
+
...options.node?.vars,
|
|
42
|
+
}).reduce((items, [name, value]) => {
|
|
43
|
+
items.push(`let ${name} = ${JSON.stringify(value)}`);
|
|
44
|
+
return items;
|
|
45
|
+
}, []);
|
|
46
|
+
await (0, promises_1.writeFile)(scriptPath, Array.isArray(step.config.code)
|
|
47
|
+
? [...vars, ...step.config.code].join(";\n")
|
|
48
|
+
: `${vars.join(";\n")}\n${step.config.code}`);
|
|
49
|
+
await (0, process_1.exec)("node", [scriptPath], {
|
|
50
|
+
cwd: options.cwd,
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
...options.env,
|
|
54
|
+
...step.config.env,
|
|
55
|
+
},
|
|
56
|
+
}, {
|
|
57
|
+
log: options.verbose,
|
|
58
|
+
...(options.onLine && {
|
|
59
|
+
stdout: {
|
|
60
|
+
parseLines: "skip-empty",
|
|
61
|
+
onData: (line) => options.onLine(line),
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Invalid step type: ${step.type}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.runSteps = runSteps;
|
package/utils/string.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare function serialize(message: string, data?: Object): string;
|
|
2
2
|
export declare function snakeCase(value: string, char?: string): string;
|
|
3
3
|
export declare function render(subject: string, vars: Record<string, string | undefined>): string;
|
|
4
|
-
|
|
4
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
5
|
+
export declare function parseStringList<T>(value: string | undefined, validValues?: T[], defaultsValues?: NoInfer<T>[] | true): T[];
|
|
5
6
|
export type UriType = {
|
|
6
7
|
protocol?: "http" | "https";
|
|
7
8
|
host?: string;
|
|
@@ -20,3 +21,4 @@ export declare function checkMatch(subject: string | undefined, patterns: string
|
|
|
20
21
|
export declare function formatDateTime(datetime: string): string;
|
|
21
22
|
export declare function splitLines(input: string, satinize?: boolean): string[];
|
|
22
23
|
export declare function undefIfEmpty(input: string): string | undefined;
|
|
24
|
+
export {};
|
package/utils/string.js
CHANGED
|
@@ -28,11 +28,12 @@ function render(subject, vars) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
exports.render = render;
|
|
31
|
-
function parseStringList(value, validValues) {
|
|
31
|
+
function parseStringList(value, validValues, defaultsValues) {
|
|
32
|
+
const resultFallback = (defaultsValues === true ? validValues : defaultsValues) ?? [];
|
|
32
33
|
const result = value
|
|
33
34
|
?.split(",")
|
|
34
35
|
.map((v) => v.trim())
|
|
35
|
-
.filter((v) => !!v.length) ??
|
|
36
|
+
.filter((v) => !!v.length) ?? resultFallback;
|
|
36
37
|
if (validValues)
|
|
37
38
|
for (const v of result)
|
|
38
39
|
if (!validValues.includes(v))
|