@datatruck/cli 0.34.0 → 0.34.2
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 +2 -2
- 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 +10 -10
- package/lib/tasks/GitTask.js +33 -50
- package/lib/tasks/MariadbTask.js +43 -56
- package/lib/tasks/MssqlTask.js +5 -11
- package/lib/tasks/MysqlDumpTask.js +4 -4
- package/lib/tasks/PostgresqlDumpTask.d.ts +1 -1
- package/lib/tasks/PostgresqlDumpTask.js +9 -32
- package/lib/tasks/SqlDumpTaskAbstract.d.ts +1 -2
- package/lib/tasks/SqlDumpTaskAbstract.js +1 -1
- package/lib/utils/async-process.d.ts +66 -0
- package/lib/utils/async-process.js +242 -0
- package/lib/utils/async.d.ts +3 -5
- package/lib/utils/async.js +2 -2
- 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/datatruck/cron-server.js +2 -2
- package/lib/utils/fs.d.ts +1 -2
- package/lib/utils/fs.js +3 -10
- package/lib/utils/{Git.d.ts → git.d.ts} +9 -7
- package/lib/utils/{Git.js → git.js} +30 -29
- package/lib/utils/list.d.ts +4 -4
- package/lib/utils/list.js +1 -1
- package/lib/utils/mysql.d.ts +8 -10
- package/lib/utils/mysql.js +60 -79
- package/lib/utils/process.d.ts +3 -92
- package/lib/utils/process.js +7 -311
- package/lib/utils/{Restic.d.ts → restic.d.ts} +10 -9
- package/lib/utils/{Restic.js → restic.js} +72 -82
- package/lib/utils/spawnSteps.js +9 -10
- package/lib/utils/stream.d.ts +8 -2
- package/lib/utils/stream.js +10 -3
- package/lib/utils/tar.js +29 -49
- package/package.json +2 -2
package/lib/utils/async.js
CHANGED
|
@@ -9,7 +9,7 @@ async function runParallel(options) {
|
|
|
9
9
|
await promise_pool_1.PromisePool.for(options.items)
|
|
10
10
|
.withConcurrency(options.concurrency)
|
|
11
11
|
.process(async (item, index, pool) => {
|
|
12
|
-
const controller =
|
|
12
|
+
const controller = new AbortController();
|
|
13
13
|
buffer.set(item, controller);
|
|
14
14
|
try {
|
|
15
15
|
await options.onChange({
|
|
@@ -29,7 +29,7 @@ async function runParallel(options) {
|
|
|
29
29
|
pool.stop();
|
|
30
30
|
for (const [, $controller] of buffer.entries())
|
|
31
31
|
try {
|
|
32
|
-
$controller.
|
|
32
|
+
$controller.abort();
|
|
33
33
|
}
|
|
34
34
|
catch (_) { }
|
|
35
35
|
}
|
|
@@ -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";
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCronServer = void 0;
|
|
4
4
|
const ConfigAction_1 = require("../../actions/ConfigAction");
|
|
5
|
+
const async_process_1 = require("../async-process");
|
|
5
6
|
const cli_1 = require("../cli");
|
|
6
7
|
const cron_1 = require("../cron");
|
|
7
|
-
const process_1 = require("../process");
|
|
8
8
|
const string_1 = require("../string");
|
|
9
9
|
const watcher_1 = require("../watcher");
|
|
10
10
|
const command_1 = require("./command");
|
|
@@ -33,7 +33,7 @@ function createCronServer(options, config) {
|
|
|
33
33
|
const command = new Command({ config: { packages: [], repositories: [] } }, {});
|
|
34
34
|
const cliOptions = (0, cli_1.stringifyOptions)(command.optionsConfig(), action.options);
|
|
35
35
|
const [node, bin] = process.argv;
|
|
36
|
-
await
|
|
36
|
+
await async_process_1.AsyncProcess.exec(node, [bin, "-c", config.configPath, action.name, ...cliOptions], { $log: config.verbose });
|
|
37
37
|
if (config.log)
|
|
38
38
|
console.info(`< [job] ${index} - ${action.name}`);
|
|
39
39
|
}
|
package/lib/utils/fs.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { Progress } from "./progress";
|
|
5
5
|
import { Entry, Options } from "fast-glob";
|
|
6
|
-
import {
|
|
6
|
+
import { Stats } from "fs";
|
|
7
7
|
import { WriteStream } from "fs";
|
|
8
8
|
import { Interface } from "readline";
|
|
9
9
|
export declare const isWSLSystem: boolean;
|
|
@@ -38,7 +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: WriteStream | ReadStream): Promise<void>;
|
|
42
41
|
export declare function copyFileWithStreams(source: string, target: string): Promise<unknown>;
|
|
43
42
|
export declare function updateFileStats(path: string, fileInfo: Stats): Promise<void>;
|
|
44
43
|
export declare function isNotFoundError(error: unknown): boolean;
|
package/lib/utils/fs.js
CHANGED
|
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.asFile = exports.groupFiles = exports.ensureFreeDiskSpace = exports.checkFreeDiskSpace = exports.fetchDiskStats = exports.initEmptyDir = exports.tryRm = exports.safeRename = exports.fetchData = exports.countFileLines = exports.createWriteStreamPool = exports.createFileScanner = exports.createProgress = exports.cpy = exports.readTextFile = exports.isNotFoundError = exports.updateFileStats = exports.copyFileWithStreams = exports.
|
|
6
|
+
exports.asFile = exports.groupFiles = exports.ensureFreeDiskSpace = exports.checkFreeDiskSpace = exports.fetchDiskStats = exports.initEmptyDir = exports.tryRm = exports.safeRename = exports.fetchData = exports.countFileLines = exports.createWriteStreamPool = exports.createFileScanner = exports.createProgress = exports.cpy = exports.readTextFile = exports.isNotFoundError = exports.updateFileStats = exports.copyFileWithStreams = exports.writeGitIgnoreList = exports.fastglobToGitIgnore = exports.forEachFile = exports.readDir = exports.readPartialFile = exports.fastFolderSizeAsync = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.include = exports.parseFileExtensions = exports.writeJSONFile = exports.existsFile = exports.existsDir = exports.safeStat = exports.ensureExistsDir = exports.ensureSingleFile = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isLocalDir = exports.isEmptyDir = exports.isWSLSystem = void 0;
|
|
7
7
|
const pkg_1 = require("../pkg");
|
|
8
8
|
const bytes_1 = require("./bytes");
|
|
9
9
|
const math_1 = require("./math");
|
|
10
|
+
const stream_1 = require("./stream");
|
|
10
11
|
const string_1 = require("./string");
|
|
11
12
|
const temp_1 = require("./temp");
|
|
12
13
|
const async_1 = require("async");
|
|
@@ -246,14 +247,6 @@ async function writeGitIgnoreList(options) {
|
|
|
246
247
|
return path;
|
|
247
248
|
}
|
|
248
249
|
exports.writeGitIgnoreList = writeGitIgnoreList;
|
|
249
|
-
async function waitForClose(stream) {
|
|
250
|
-
return new Promise((resolve, reject) => {
|
|
251
|
-
stream.on("close", resolve);
|
|
252
|
-
stream.on("error", reject);
|
|
253
|
-
return stream;
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
exports.waitForClose = waitForClose;
|
|
257
250
|
async function copyFileWithStreams(source, target) {
|
|
258
251
|
const r = (0, fs_1.createReadStream)(source);
|
|
259
252
|
const w = (0, fs_2.createWriteStream)(target);
|
|
@@ -520,7 +513,7 @@ function createWriteStreamPool(options) {
|
|
|
520
513
|
}
|
|
521
514
|
await Promise.all(items
|
|
522
515
|
.filter((item) => !item.finished)
|
|
523
|
-
.map((item) => waitForClose(item.stream)));
|
|
516
|
+
.map((item) => (0, stream_1.waitForClose)(item.stream)));
|
|
524
517
|
},
|
|
525
518
|
};
|
|
526
519
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncProcessOptions } from "./async-process";
|
|
2
2
|
export declare class Git {
|
|
3
3
|
readonly options: {
|
|
4
4
|
dir: string;
|
|
@@ -8,22 +8,24 @@ export declare class Git {
|
|
|
8
8
|
dir: string;
|
|
9
9
|
log?: boolean;
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
private createProcess;
|
|
12
|
+
exec(args: string[], options?: AsyncProcessOptions): Promise<number>;
|
|
13
|
+
private stdout;
|
|
12
14
|
canBeInit(repo: string): Promise<boolean>;
|
|
13
15
|
clone(options: {
|
|
14
16
|
repo: string;
|
|
15
17
|
branch?: string;
|
|
16
18
|
orphan?: boolean;
|
|
17
|
-
}): Promise<
|
|
19
|
+
}): Promise<void>;
|
|
18
20
|
checkout(options: {
|
|
19
21
|
branchName: string;
|
|
20
22
|
orphan?: boolean;
|
|
21
|
-
}): Promise<
|
|
23
|
+
}): Promise<void>;
|
|
22
24
|
checkBranch(options: {
|
|
23
25
|
name: string;
|
|
24
26
|
repo?: string;
|
|
25
27
|
}): Promise<boolean>;
|
|
26
|
-
removeAll(): Promise<
|
|
28
|
+
removeAll(): Promise<void>;
|
|
27
29
|
haveChanges(): Promise<boolean>;
|
|
28
30
|
fetchCommitId(tag: string): Promise<string>;
|
|
29
31
|
getTags(names?: string[]): Promise<{
|
|
@@ -31,8 +33,8 @@ export declare class Git {
|
|
|
31
33
|
message?: string | undefined;
|
|
32
34
|
}[]>;
|
|
33
35
|
addTag(name: string, message?: string): Promise<void>;
|
|
34
|
-
pushTags(): Promise<
|
|
36
|
+
pushTags(): Promise<void>;
|
|
35
37
|
push(options: {
|
|
36
38
|
branchName: string;
|
|
37
|
-
}): Promise<
|
|
39
|
+
}): Promise<void>;
|
|
38
40
|
}
|
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Git = void 0;
|
|
4
|
+
const async_process_1 = require("./async-process");
|
|
4
5
|
const fs_1 = require("./fs");
|
|
5
|
-
const process_1 = require("./process");
|
|
6
6
|
class Git {
|
|
7
7
|
options;
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.options = options;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
log: this.options.log,
|
|
14
|
-
|
|
11
|
+
createProcess(args, options = {}) {
|
|
12
|
+
return new async_process_1.AsyncProcess("git", args, {
|
|
13
|
+
$log: this.options.log,
|
|
14
|
+
cwd: this.options.dir,
|
|
15
|
+
...options,
|
|
15
16
|
});
|
|
16
17
|
}
|
|
18
|
+
async exec(args, options) {
|
|
19
|
+
return await this.createProcess(args, options).waitForClose();
|
|
20
|
+
}
|
|
21
|
+
async stdout(args, options) {
|
|
22
|
+
return await this.createProcess(args, options).stdout.fetch();
|
|
23
|
+
}
|
|
17
24
|
async canBeInit(repo) {
|
|
18
25
|
return ((0, fs_1.isLocalDir)(repo) &&
|
|
19
26
|
(!(await (0, fs_1.existsDir)(repo)) || !(await (0, fs_1.readDir)(repo)).length));
|
|
20
27
|
}
|
|
21
28
|
async clone(options) {
|
|
22
|
-
|
|
29
|
+
await this.exec([
|
|
23
30
|
"clone",
|
|
24
31
|
...(/^\w+\:\/\//.test(options.repo) ? ["--depth=1"] : []),
|
|
25
32
|
...(options.orphan ? ["--orphan"] : []),
|
|
@@ -31,42 +38,41 @@ class Git {
|
|
|
31
38
|
]);
|
|
32
39
|
}
|
|
33
40
|
async checkout(options) {
|
|
34
|
-
|
|
41
|
+
await this.exec([
|
|
35
42
|
"checkout",
|
|
36
43
|
...(options.orphan ? ["--orphan"] : []),
|
|
37
44
|
options.branchName,
|
|
38
45
|
]);
|
|
39
46
|
}
|
|
40
47
|
async checkBranch(options) {
|
|
41
|
-
const
|
|
48
|
+
const stdout = await this.stdout([
|
|
42
49
|
"ls-remote",
|
|
43
50
|
"--exit-code",
|
|
44
51
|
...(options.repo ? [options.repo] : ["--heads", "origin"]),
|
|
45
52
|
], {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
...(options.repo && {
|
|
54
|
+
cwd: undefined,
|
|
55
|
+
}),
|
|
56
|
+
cwd: options.repo ? undefined : this.options.dir,
|
|
57
|
+
$exitCode: false,
|
|
58
|
+
});
|
|
59
|
+
return stdout
|
|
50
60
|
.split(/\r?\n/g)
|
|
51
61
|
.some((line) => line.endsWith(`refs/heads/${options.name}`));
|
|
52
62
|
}
|
|
53
63
|
async removeAll() {
|
|
54
|
-
|
|
64
|
+
await this.exec(["rm", "--force", "--ignore-unmatch", "*"]);
|
|
55
65
|
}
|
|
56
66
|
async haveChanges() {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
return !!statusResult.stdout.trim().length;
|
|
67
|
+
const stdout = await this.stdout(["status", "-s"]);
|
|
68
|
+
return !!stdout.trim().length;
|
|
61
69
|
}
|
|
62
70
|
async fetchCommitId(tag) {
|
|
63
|
-
return (await this.
|
|
71
|
+
return (await this.stdout(["rev-list", "-n", "1", tag])).trim();
|
|
64
72
|
}
|
|
65
73
|
async getTags(names) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
return result.stdout.split(/\r?\n/).reduce((result, value) => {
|
|
74
|
+
const stdout = await this.stdout(["tag", "-n", ...(names ?? [])]);
|
|
75
|
+
return stdout.split(/\r?\n/).reduce((result, value) => {
|
|
70
76
|
value = value.trim();
|
|
71
77
|
if (!value.length)
|
|
72
78
|
return result;
|
|
@@ -91,15 +97,10 @@ class Git {
|
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
async pushTags() {
|
|
94
|
-
|
|
100
|
+
await this.exec(["push", "--tags"]);
|
|
95
101
|
}
|
|
96
102
|
async push(options) {
|
|
97
|
-
|
|
98
|
-
"push",
|
|
99
|
-
"--progress",
|
|
100
|
-
"origin",
|
|
101
|
-
options.branchName,
|
|
102
|
-
]);
|
|
103
|
+
await this.exec(["push", "--progress", "origin", options.branchName]);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
exports.Git = Git;
|
package/lib/utils/list.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Timer } from "./date";
|
|
2
2
|
import { ProgressManager } from "./progress";
|
|
3
|
-
import {
|
|
3
|
+
import { StdStreams } from "./stream";
|
|
4
4
|
import { Listr, ListrGetRendererClassFromValue, ListrLogger, ListrTask, ListrTaskWrapper } from "listr2";
|
|
5
5
|
export declare class List3Logger<Levels extends string = string> extends ListrLogger<Levels> {
|
|
6
6
|
constructor(options?: {
|
|
7
|
-
streams?: Partial<
|
|
7
|
+
streams?: Partial<StdStreams>;
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
export type Listr3Context = Record<string, Record<string, any>>;
|
|
@@ -41,7 +41,7 @@ export type Listr3TaskResult<T extends Listr3Context> = {
|
|
|
41
41
|
export type Listr3TaskResultEnd<T extends Listr3Context> = Listr3TaskResult<T> | List3SummaryResult;
|
|
42
42
|
export declare class Listr3<T extends Listr3Context> extends Listr<void, "default", "simple"> {
|
|
43
43
|
readonly $options: {
|
|
44
|
-
streams?:
|
|
44
|
+
streams?: StdStreams;
|
|
45
45
|
progressManager?: ProgressManager;
|
|
46
46
|
};
|
|
47
47
|
readonly resultMap: Record<string, Listr3TaskResult<T>>;
|
|
@@ -49,7 +49,7 @@ export declare class Listr3<T extends Listr3Context> extends Listr<void, "defaul
|
|
|
49
49
|
readonly logger: List3Logger;
|
|
50
50
|
protected execTimer: Timer;
|
|
51
51
|
constructor($options: {
|
|
52
|
-
streams?:
|
|
52
|
+
streams?: StdStreams;
|
|
53
53
|
progressManager?: ProgressManager;
|
|
54
54
|
});
|
|
55
55
|
private serializeKeyIndex;
|
package/lib/utils/list.js
CHANGED
|
@@ -7,7 +7,7 @@ const stream_1 = require("./stream");
|
|
|
7
7
|
const listr2_1 = require("listr2");
|
|
8
8
|
class List3Logger extends listr2_1.ListrLogger {
|
|
9
9
|
constructor(options = {}) {
|
|
10
|
-
const streams = (0, stream_1.
|
|
10
|
+
const streams = (0, stream_1.createStdStreams)(options.streams);
|
|
11
11
|
super({
|
|
12
12
|
processOutput: new listr2_1.ProcessOutput(streams.stdout, streams.stderr),
|
|
13
13
|
});
|
package/lib/utils/mysql.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ChildProcess } from "child_process";
|
|
3
2
|
export type MysqlCliOptions = {
|
|
4
3
|
password: string | {
|
|
5
4
|
path: string;
|
|
@@ -15,7 +14,6 @@ export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
|
|
|
15
14
|
options: MysqlCliOptions;
|
|
16
15
|
initSharedDir: (sharedDir?: string) => Promise<string>;
|
|
17
16
|
args: () => Promise<string[]>;
|
|
18
|
-
run: (query: string, database?: string, extra?: string[], onSpawn?: ((p: ChildProcess) => void) | undefined) => Promise<import("./process").ExecResult>;
|
|
19
17
|
execute: (query: string, params?: any[]) => Promise<void>;
|
|
20
18
|
insert: (tableName: string, item: Record<string, any>) => Promise<void>;
|
|
21
19
|
changeDatabase: (name: string) => Promise<void>;
|
|
@@ -25,18 +23,18 @@ export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
|
|
|
25
23
|
database: string;
|
|
26
24
|
items?: string[] | undefined;
|
|
27
25
|
onlyStoredPrograms?: boolean | undefined;
|
|
28
|
-
|
|
26
|
+
controller?: AbortController | undefined;
|
|
29
27
|
onProgress?: ((data: {
|
|
30
28
|
totalBytes: number;
|
|
31
29
|
}) => void) | undefined;
|
|
32
|
-
}) => Promise<
|
|
30
|
+
}) => Promise<void>;
|
|
33
31
|
assertDumpFile: typeof assertDumpFile;
|
|
34
32
|
fetchTableNames: (database: string, include?: string[], exclude?: string[]) => Promise<string[]>;
|
|
35
33
|
importFile: (input: {
|
|
36
34
|
path: string;
|
|
37
35
|
database: string;
|
|
38
|
-
|
|
39
|
-
}) => Promise<
|
|
36
|
+
controller?: AbortController;
|
|
37
|
+
}) => Promise<void>;
|
|
40
38
|
isDatabaseEmpty: (database: string) => Promise<boolean>;
|
|
41
39
|
createDatabase: (database: {
|
|
42
40
|
name: string;
|
|
@@ -45,14 +43,14 @@ export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
|
|
|
45
43
|
csvDump: (input: {
|
|
46
44
|
database: string;
|
|
47
45
|
sharedPath: string;
|
|
48
|
-
items?: string[]
|
|
49
|
-
|
|
46
|
+
items?: string[];
|
|
47
|
+
controller?: AbortController;
|
|
50
48
|
}) => Promise<void>;
|
|
51
49
|
importCsvFile: (input: {
|
|
52
50
|
path: string;
|
|
53
51
|
database: string;
|
|
54
52
|
table: string;
|
|
55
|
-
|
|
56
|
-
}) => Promise<
|
|
53
|
+
controller?: AbortController;
|
|
54
|
+
}) => Promise<void>;
|
|
57
55
|
fetchVariable: (name: string) => Promise<string | undefined>;
|
|
58
56
|
}>;
|
package/lib/utils/mysql.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMysqlCli = exports.assertDumpFile = void 0;
|
|
4
|
+
const async_process_1 = require("./async-process");
|
|
4
5
|
const cli_1 = require("./cli");
|
|
5
6
|
const error_1 = require("./datatruck/error");
|
|
6
7
|
const fs_1 = require("./fs");
|
|
@@ -8,7 +9,6 @@ const process_1 = require("./process");
|
|
|
8
9
|
const string_1 = require("./string");
|
|
9
10
|
const temp_1 = require("./temp");
|
|
10
11
|
const crypto_1 = require("crypto");
|
|
11
|
-
const fs_2 = require("fs");
|
|
12
12
|
const promises_1 = require("fs/promises");
|
|
13
13
|
const promise_1 = require("mysql2/promise");
|
|
14
14
|
const os_1 = require("os");
|
|
@@ -68,22 +68,6 @@ async function createMysqlCli(options) {
|
|
|
68
68
|
async function args() {
|
|
69
69
|
return [`--defaults-file=${await createSqlConfig()}`];
|
|
70
70
|
}
|
|
71
|
-
async function run(query, database, extra = [], onSpawn) {
|
|
72
|
-
return await (0, process_1.exec)("mysql", [
|
|
73
|
-
...(await args()),
|
|
74
|
-
...(database ? [database] : []),
|
|
75
|
-
...(extra || []),
|
|
76
|
-
"-e",
|
|
77
|
-
flatQuery(query),
|
|
78
|
-
"-N",
|
|
79
|
-
"--silent",
|
|
80
|
-
], undefined, {
|
|
81
|
-
onSpawn,
|
|
82
|
-
log: options.verbose,
|
|
83
|
-
stderr: { toExitCode: true },
|
|
84
|
-
stdout: { save: true },
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
71
|
async function fetchAll(query, params) {
|
|
88
72
|
const [rows] = await sql.query(query, params);
|
|
89
73
|
return rows;
|
|
@@ -103,46 +87,35 @@ async function createMysqlCli(options) {
|
|
|
103
87
|
.filter((0, string_1.createMatchFilter)(include, exclude));
|
|
104
88
|
}
|
|
105
89
|
async function dump(input) {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
pipe: {
|
|
133
|
-
stream,
|
|
134
|
-
onWriteProgress: input.onProgress,
|
|
135
|
-
},
|
|
136
|
-
log: {
|
|
137
|
-
exec: options.verbose,
|
|
138
|
-
stderr: options.verbose,
|
|
139
|
-
allToStderr: true,
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
]);
|
|
90
|
+
const process = new async_process_1.AsyncProcess("mysqldump", [
|
|
91
|
+
...(await args()),
|
|
92
|
+
input.database,
|
|
93
|
+
"--lock-tables=false",
|
|
94
|
+
"--skip-add-drop-table=false",
|
|
95
|
+
...(input.onlyStoredPrograms
|
|
96
|
+
? [
|
|
97
|
+
"--routines",
|
|
98
|
+
"--events",
|
|
99
|
+
"--skip-triggers",
|
|
100
|
+
"--no-create-info",
|
|
101
|
+
"--no-data",
|
|
102
|
+
"--no-create-db",
|
|
103
|
+
"--skip-opt",
|
|
104
|
+
]
|
|
105
|
+
: []),
|
|
106
|
+
...(input.items || []),
|
|
107
|
+
], {
|
|
108
|
+
$controller: input.controller,
|
|
109
|
+
$log: {
|
|
110
|
+
exec: options.verbose,
|
|
111
|
+
stderr: options.verbose,
|
|
112
|
+
allToStderr: true,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
await process.stdout.pipe(input.output, input.onProgress);
|
|
143
116
|
}
|
|
144
117
|
async function csvDump(input) {
|
|
145
|
-
|
|
118
|
+
const process = new async_process_1.AsyncProcess("mysqldump", [
|
|
146
119
|
...(await args()),
|
|
147
120
|
input.database,
|
|
148
121
|
"--lock-tables=false",
|
|
@@ -152,18 +125,18 @@ async function createMysqlCli(options) {
|
|
|
152
125
|
"-T",
|
|
153
126
|
input.sharedPath,
|
|
154
127
|
...(input.items || []),
|
|
155
|
-
],
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
log: {
|
|
128
|
+
], {
|
|
129
|
+
$controller: input.controller,
|
|
130
|
+
$log: {
|
|
159
131
|
exec: options.verbose,
|
|
160
132
|
stderr: options.verbose,
|
|
161
133
|
allToStderr: true,
|
|
162
134
|
},
|
|
163
135
|
});
|
|
136
|
+
await process.waitForClose();
|
|
164
137
|
}
|
|
165
138
|
async function importFile(input) {
|
|
166
|
-
|
|
139
|
+
const process = new async_process_1.AsyncProcess("mysql", [
|
|
167
140
|
...(await args()),
|
|
168
141
|
`--init-command=SET ${[
|
|
169
142
|
"autocommit=0",
|
|
@@ -171,30 +144,39 @@ async function createMysqlCli(options) {
|
|
|
171
144
|
"foreign_key_checks=0",
|
|
172
145
|
].join(",")};`,
|
|
173
146
|
input.database,
|
|
174
|
-
],
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
stream: (0, fs_2.createReadStream)(input.path),
|
|
178
|
-
onReadProgress: (data) => {
|
|
179
|
-
if (options.verbose)
|
|
180
|
-
(0, process_1.logExecStdout)({
|
|
181
|
-
data: JSON.stringify(data),
|
|
182
|
-
colorize: true,
|
|
183
|
-
stderr: true,
|
|
184
|
-
lineSalt: true,
|
|
185
|
-
});
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
stderr: { toExitCode: true },
|
|
189
|
-
log: options.verbose,
|
|
147
|
+
], {
|
|
148
|
+
$log: options.verbose,
|
|
149
|
+
$controller: input.controller,
|
|
190
150
|
});
|
|
151
|
+
await process.stdin.pipe(input.path, options.verbose
|
|
152
|
+
? (data) => (0, process_1.logStdout)({
|
|
153
|
+
data: JSON.stringify(data),
|
|
154
|
+
colorize: true,
|
|
155
|
+
stderr: true,
|
|
156
|
+
lineSalt: true,
|
|
157
|
+
})
|
|
158
|
+
: undefined);
|
|
191
159
|
}
|
|
192
160
|
async function importCsvFile(input) {
|
|
193
|
-
|
|
161
|
+
const query = `
|
|
194
162
|
LOAD DATA LOCAL INFILE ${JSON.stringify(input.path.replaceAll("\\", "/"))}
|
|
195
163
|
INTO TABLE ${input.table}
|
|
196
164
|
FIELDS TERMINATED BY '\\t'
|
|
197
|
-
LINES TERMINATED BY '\\n'
|
|
165
|
+
LINES TERMINATED BY '\\n'
|
|
166
|
+
`;
|
|
167
|
+
const process = new async_process_1.AsyncProcess("mysql", [
|
|
168
|
+
...(await args()),
|
|
169
|
+
input.database,
|
|
170
|
+
"--local-infile",
|
|
171
|
+
"-e",
|
|
172
|
+
flatQuery(query),
|
|
173
|
+
"-N",
|
|
174
|
+
"--silent",
|
|
175
|
+
], {
|
|
176
|
+
$controller: input.controller,
|
|
177
|
+
$log: options.verbose,
|
|
178
|
+
});
|
|
179
|
+
await process.waitForClose();
|
|
198
180
|
}
|
|
199
181
|
async function isDatabaseEmpty(database) {
|
|
200
182
|
const [row] = await fetchAll(`
|
|
@@ -278,7 +260,6 @@ async function createMysqlCli(options) {
|
|
|
278
260
|
options,
|
|
279
261
|
initSharedDir,
|
|
280
262
|
args,
|
|
281
|
-
run,
|
|
282
263
|
execute,
|
|
283
264
|
insert,
|
|
284
265
|
changeDatabase,
|