@datatruck/cli 0.6.0 → 0.8.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/BackupAction.d.ts +1 -0
- package/Action/BackupAction.js +4 -1
- package/Action/RestoreAction.d.ts +1 -0
- package/Action/RestoreAction.js +1 -0
- package/Action/SnapshotsAction.d.ts +1 -0
- package/CHANGELOG.md +32 -0
- package/Command/BackupCommand.d.ts +1 -0
- package/Command/BackupCommand.js +8 -2
- package/Command/BackupSessionsCommand.js +1 -1
- package/Command/ConfigCommand.d.ts +1 -0
- package/Command/ConfigCommand.js +7 -1
- package/Command/InitCommand.js +1 -1
- package/Command/PruneCommand.js +2 -2
- package/Command/RestoreCommand.d.ts +1 -0
- package/Command/RestoreCommand.js +8 -2
- package/Command/RestoreSessionsCommand.js +1 -1
- package/Command/SnapshotsCommand.d.ts +1 -0
- package/Command/SnapshotsCommand.js +16 -2
- package/Repository/GitRepository.js +5 -0
- package/Repository/LocalRepository.d.ts +1 -0
- package/Repository/LocalRepository.js +5 -0
- package/Repository/RepositoryAbstract.d.ts +4 -1
- package/Repository/RepositoryAbstract.js +1 -0
- package/Repository/ResticRepository.d.ts +2 -2
- package/Repository/ResticRepository.js +26 -3
- package/SessionDriver/ConsoleSessionDriver.d.ts +6 -2
- package/SessionDriver/ConsoleSessionDriver.js +19 -29
- package/SessionDriver/SessionDriverAbstract.d.ts +1 -1
- package/SessionDriver/SessionDriverAbstract.js +1 -1
- package/SessionManager/BackupSessionManager.d.ts +1 -1
- package/SessionManager/BackupSessionManager.js +2 -2
- package/Task/MariadbTask.js +1 -1
- package/Task/MysqlDumpTask.d.ts +1 -1
- package/Task/MysqlDumpTask.js +4 -2
- package/Task/PostgresqlDumpTask.d.ts +1 -1
- package/Task/PostgresqlDumpTask.js +2 -4
- package/Task/SqlDumpTaskAbstract.d.ts +1 -2
- package/Task/SqlDumpTaskAbstract.js +60 -17
- package/package.json +1 -1
- package/util/ResticUtil.d.ts +1 -1
- package/util/ResticUtil.js +2 -2
- package/util/cli-util.d.ts +1 -0
- package/util/cli-util.js +13 -1
- package/util/datatruck/config-util.d.ts +1 -0
- package/util/datatruck/config-util.js +3 -0
- package/util/date-util.d.ts +4 -0
- package/util/date-util.js +17 -1
- package/util/process-util.d.ts +2 -2
- package/util/process-util.js +6 -6
- package/util/string-util.d.ts +1 -0
- package/util/string-util.js +21 -1
- package/util/zip-util.d.ts +2 -2
- package/util/zip-util.js +9 -9
|
@@ -27,7 +27,7 @@ export declare class BackupSessionManager {
|
|
|
27
27
|
repositoryName: string;
|
|
28
28
|
}): number;
|
|
29
29
|
initDrivers(): Promise<void>;
|
|
30
|
-
endDrivers(): Promise<void>;
|
|
30
|
+
endDrivers(data?: Record<string, any>): Promise<void>;
|
|
31
31
|
protected alter(data: WriteDataType): Promise<number>;
|
|
32
32
|
readAll(options: BackupSessionsActionOptionsType): Promise<import("../SessionDriver/SessionDriverAbstract").ReadResultType[]>;
|
|
33
33
|
init(input: Pick<BackupSessionEntity, "packageName" | "snapshotId" | "tags">): Promise<number>;
|
|
@@ -27,10 +27,10 @@ class BackupSessionManager {
|
|
|
27
27
|
await driver.onInit();
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
async endDrivers() {
|
|
30
|
+
async endDrivers(data) {
|
|
31
31
|
const drivers = [this.options.driver, ...(this.options.altDrivers ?? [])];
|
|
32
32
|
for (const driver of drivers) {
|
|
33
|
-
await driver.onEnd();
|
|
33
|
+
await driver.onEnd(data);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async alter(data) {
|
package/Task/MariadbTask.js
CHANGED
|
@@ -129,7 +129,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
|
|
|
129
129
|
});
|
|
130
130
|
await (0, process_util_1.exec)(command, [`--prepare`, `--target-dir=${targetPath}`], undefined, {
|
|
131
131
|
log: this.verbose,
|
|
132
|
-
stderr: { onData:
|
|
132
|
+
stderr: { onData: () => { } },
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
async onRestore(data) {
|
package/Task/MysqlDumpTask.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class MysqlDumpTask extends SqlDumpTaskAbstract<MysqlDumpTaskConf
|
|
|
8
8
|
onDatabaseIsEmpty(name: string): Promise<boolean>;
|
|
9
9
|
onCreateDatabase(database: TargetDatabaseType): Promise<void>;
|
|
10
10
|
onExecQuery(query: string): Promise<import("../util/process-util").ExecResultType>;
|
|
11
|
-
onFetchTableNames(): Promise<string[]>;
|
|
11
|
+
onFetchTableNames(database: string): Promise<string[]>;
|
|
12
12
|
onExport(tableNames: string[], output: string): Promise<void>;
|
|
13
13
|
onImport(path: string, database: string): Promise<void>;
|
|
14
14
|
}
|
package/Task/MysqlDumpTask.js
CHANGED
|
@@ -17,6 +17,7 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
|
|
|
17
17
|
const password = await this.fetchPassword();
|
|
18
18
|
return [
|
|
19
19
|
`--host=${this.config.hostname}`,
|
|
20
|
+
...(this.config.port ? [`--port=${this.config.port}`] : []),
|
|
20
21
|
`--user=${this.config.username}`,
|
|
21
22
|
`--password=${password ?? ""}`,
|
|
22
23
|
...(database && this.config.database ? [this.config.database] : []),
|
|
@@ -57,14 +58,14 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
|
|
|
57
58
|
},
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
|
-
async onFetchTableNames() {
|
|
61
|
+
async onFetchTableNames(database) {
|
|
61
62
|
return await this.fetchValues(`
|
|
62
63
|
SELECT
|
|
63
64
|
table_name
|
|
64
65
|
FROM
|
|
65
66
|
information_schema.tables
|
|
66
67
|
WHERE
|
|
67
|
-
table_schema = '${
|
|
68
|
+
table_schema = '${database}'
|
|
68
69
|
`);
|
|
69
70
|
}
|
|
70
71
|
async onExport(tableNames, output) {
|
|
@@ -77,6 +78,7 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
|
|
|
77
78
|
await (0, process_util_1.exec)("mysqldump", [
|
|
78
79
|
...(await this.buildConnectionArgs()),
|
|
79
80
|
"--lock-tables=false",
|
|
81
|
+
"--skip-add-drop-table=false",
|
|
80
82
|
...tableNames,
|
|
81
83
|
], null, {
|
|
82
84
|
pipe: { stream: stream },
|
|
@@ -8,7 +8,7 @@ export declare class PostgresqlDumpTask extends SqlDumpTaskAbstract<PostgresqlDu
|
|
|
8
8
|
onDatabaseIsEmpty(name: string): Promise<boolean>;
|
|
9
9
|
onCreateDatabase(database: TargetDatabaseType): Promise<void>;
|
|
10
10
|
onExecQuery(query: string): Promise<import("../util/process-util").ExecResultType>;
|
|
11
|
-
onFetchTableNames(): Promise<string[]>;
|
|
11
|
+
onFetchTableNames(database: string): Promise<string[]>;
|
|
12
12
|
onExport(tableNames: string[], output: string): Promise<void>;
|
|
13
13
|
onImport(path: string, database: string): Promise<void>;
|
|
14
14
|
}
|
|
@@ -60,14 +60,14 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async onFetchTableNames() {
|
|
63
|
+
async onFetchTableNames(database) {
|
|
64
64
|
return await this.fetchValues(`
|
|
65
65
|
SELECT
|
|
66
66
|
CONCAT(table_schema, '.', table_name)
|
|
67
67
|
FROM
|
|
68
68
|
information_schema.tables
|
|
69
69
|
WHERE
|
|
70
|
-
table_catalog = '${
|
|
70
|
+
table_catalog = '${database}' AND
|
|
71
71
|
table_schema NOT IN ('pg_catalog', 'information_schema')
|
|
72
72
|
`);
|
|
73
73
|
}
|
|
@@ -80,8 +80,6 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
|
|
|
80
80
|
}),
|
|
81
81
|
(0, process_util_1.exec)("pg_dump", [
|
|
82
82
|
...(await this.buildConnectionArgs()),
|
|
83
|
-
"--clean",
|
|
84
|
-
"--if-exists",
|
|
85
83
|
...(tableNames?.flatMap((v) => ["-t", v]) ?? []),
|
|
86
84
|
], null, {
|
|
87
85
|
pipe: { stream: stream },
|
|
@@ -26,11 +26,10 @@ export declare abstract class SqlDumpTaskAbstract<TConfig extends SqlDumpTaskCon
|
|
|
26
26
|
fetchValues(query: string): Promise<string[]>;
|
|
27
27
|
abstract onCreateDatabase(database: TargetDatabaseType): Promise<void>;
|
|
28
28
|
abstract onDatabaseIsEmpty(databaseName: string): Promise<boolean>;
|
|
29
|
-
abstract onFetchTableNames(): Promise<string[]>;
|
|
29
|
+
abstract onFetchTableNames(database: string): Promise<string[]>;
|
|
30
30
|
abstract onExecQuery(query: string): ReturnType<typeof exec>;
|
|
31
31
|
abstract onExport(tableNames: string[], output: string): Promise<void>;
|
|
32
32
|
abstract onImport(path: string, database: string): Promise<void>;
|
|
33
|
-
fetchTableNames(): Promise<string[]>;
|
|
34
33
|
onBackup(data: BackupDataType): Promise<void>;
|
|
35
34
|
onRestore(data: RestoreDataType): Promise<void>;
|
|
36
35
|
}
|
|
@@ -49,6 +49,39 @@ exports.sqlDumpTaskDefinition = {
|
|
|
49
49
|
oneFileByTable: { type: "boolean" },
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
|
+
function serializeSqlFile(input) {
|
|
53
|
+
if (input.database && input.table) {
|
|
54
|
+
return `${input.database}.${input.table}.table.sql`;
|
|
55
|
+
}
|
|
56
|
+
else if (input.database && !input.table) {
|
|
57
|
+
return `${input.database}.database.sql`;
|
|
58
|
+
}
|
|
59
|
+
else if (!input.database && input.table) {
|
|
60
|
+
return `${input.table}.table.sql`;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new AppError_1.AppError(`Invalid sql file input: ${JSON.stringify(input)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function parseSqlFile(fileName) {
|
|
67
|
+
if (!fileName.endsWith(".sql"))
|
|
68
|
+
return;
|
|
69
|
+
const regex = /^(.+)\.(table|database)\.sql$/;
|
|
70
|
+
const matches = regex.exec(fileName);
|
|
71
|
+
if (!matches)
|
|
72
|
+
return { fileName };
|
|
73
|
+
const [, name, type] = matches;
|
|
74
|
+
const lastName = name.split(".").pop();
|
|
75
|
+
if (type === "table") {
|
|
76
|
+
return { fileName, table: lastName };
|
|
77
|
+
}
|
|
78
|
+
else if (type === "database") {
|
|
79
|
+
return { fileName, database: lastName };
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new Error(`Invalid sql file type: ${type}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
52
85
|
class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
53
86
|
async fetchPassword() {
|
|
54
87
|
if (typeof this.config.password === "string")
|
|
@@ -66,26 +99,23 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
66
99
|
return result;
|
|
67
100
|
}, []);
|
|
68
101
|
}
|
|
69
|
-
async
|
|
70
|
-
|
|
102
|
+
async onBackup(data) {
|
|
103
|
+
this.verbose = data.options.verbose;
|
|
71
104
|
const config = this.config;
|
|
72
|
-
|
|
105
|
+
const outputPath = data.package.path;
|
|
106
|
+
const allTableNames = await this.onFetchTableNames(this.config.database);
|
|
107
|
+
const tableNames = allTableNames.filter((tableName) => {
|
|
73
108
|
if (config.includeTables && !(0, micromatch_1.isMatch)(tableName, config.includeTables))
|
|
74
109
|
return false;
|
|
75
110
|
if (config.excludeTables && (0, micromatch_1.isMatch)(tableName, config.excludeTables))
|
|
76
111
|
return false;
|
|
77
112
|
return true;
|
|
78
113
|
});
|
|
79
|
-
}
|
|
80
|
-
async onBackup(data) {
|
|
81
|
-
this.verbose = data.options.verbose;
|
|
82
|
-
const outputPath = data.package.path;
|
|
83
|
-
const tableNames = await this.fetchTableNames();
|
|
84
114
|
(0, assert_1.ok)(typeof outputPath === "string");
|
|
85
115
|
if (!(await (0, fs_util_1.checkDir)(outputPath)))
|
|
86
116
|
await (0, promises_1.mkdir)(outputPath, { recursive: true });
|
|
87
117
|
if (!this.config.oneFileByTable) {
|
|
88
|
-
const outPath = (0, path_1.join)(outputPath, this.config.database)
|
|
118
|
+
const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ database: this.config.database }));
|
|
89
119
|
await this.onExport(tableNames, outPath);
|
|
90
120
|
}
|
|
91
121
|
else {
|
|
@@ -98,7 +128,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
98
128
|
step: tableName,
|
|
99
129
|
});
|
|
100
130
|
current++;
|
|
101
|
-
const outPath = (0, path_1.join)(outputPath, tableName)
|
|
131
|
+
const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ table: tableName }));
|
|
102
132
|
await this.onExport([tableName], outPath);
|
|
103
133
|
}
|
|
104
134
|
}
|
|
@@ -125,20 +155,33 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
125
155
|
database: database.name,
|
|
126
156
|
});
|
|
127
157
|
}
|
|
128
|
-
|
|
158
|
+
const items = (await (0, promises_1.readdir)(restorePath))
|
|
159
|
+
.map(parseSqlFile)
|
|
160
|
+
.filter((v) => !!v);
|
|
161
|
+
// Database check
|
|
162
|
+
const databaseItems = items.filter((v) => v.database);
|
|
163
|
+
if (databaseItems.length && !(await this.onDatabaseIsEmpty(database.name)))
|
|
129
164
|
throw new AppError_1.AppError(`Target database is not empty: ${database.name}`);
|
|
165
|
+
// Table check
|
|
166
|
+
const restoreTables = items
|
|
167
|
+
.filter((v) => v.table)
|
|
168
|
+
.map((v) => v.table);
|
|
169
|
+
const serverTables = await this.onFetchTableNames(database.name);
|
|
170
|
+
const errorTables = restoreTables.filter((v) => serverTables.includes(v));
|
|
171
|
+
if (errorTables.length) {
|
|
172
|
+
throw new AppError_1.AppError(`Target table already exists: ${errorTables.join(", ")}`);
|
|
173
|
+
}
|
|
130
174
|
await this.onCreateDatabase(database);
|
|
131
175
|
if (this.verbose)
|
|
132
176
|
(0, cli_util_1.logExec)("readdir", [restorePath]);
|
|
133
|
-
const files = (await (0, promises_1.readdir)(restorePath)).filter((name) => /\.sql$/i.test(name));
|
|
134
177
|
let current = 0;
|
|
135
|
-
for (const
|
|
136
|
-
const path = (0, path_1.join)(restorePath,
|
|
178
|
+
for (const item of items) {
|
|
179
|
+
const path = (0, path_1.join)(restorePath, item.fileName);
|
|
137
180
|
data.onProgress({
|
|
138
|
-
total:
|
|
181
|
+
total: items.length,
|
|
139
182
|
current: current,
|
|
140
|
-
percent: (0, math_util_1.progressPercent)(
|
|
141
|
-
step:
|
|
183
|
+
percent: (0, math_util_1.progressPercent)(items.length, current),
|
|
184
|
+
step: item.fileName,
|
|
142
185
|
});
|
|
143
186
|
current++;
|
|
144
187
|
await this.onImport(path, database.name);
|
package/package.json
CHANGED
package/util/ResticUtil.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare class ResticUtil {
|
|
|
84
84
|
excludeFile?: string[];
|
|
85
85
|
parent?: string;
|
|
86
86
|
allowEmptySnapshot?: boolean;
|
|
87
|
-
onStream?: (data: BackupStreamType) =>
|
|
87
|
+
onStream?: (data: BackupStreamType) => void;
|
|
88
88
|
}): Promise<ExecResultType>;
|
|
89
89
|
restore(options: {
|
|
90
90
|
id: string;
|
package/util/ResticUtil.js
CHANGED
|
@@ -115,7 +115,7 @@ class ResticUtil {
|
|
|
115
115
|
},
|
|
116
116
|
stdout: {
|
|
117
117
|
...(options.onStream && {
|
|
118
|
-
onData:
|
|
118
|
+
onData: (data) => {
|
|
119
119
|
for (const rawLine of data.split("\n")) {
|
|
120
120
|
const line = rawLine.trim();
|
|
121
121
|
if (line.startsWith("{") && line.endsWith("}")) {
|
|
@@ -125,7 +125,7 @@ class ResticUtil {
|
|
|
125
125
|
}
|
|
126
126
|
catch (error) { }
|
|
127
127
|
if (parsedLine)
|
|
128
|
-
|
|
128
|
+
options.onStream?.(parsedLine);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
},
|
package/util/cli-util.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const clearCommand = "\r\u001B[K";
|
|
|
6
6
|
export declare const hideCursorCommand = "\u001B[?25l";
|
|
7
7
|
export declare function renderSpinner(counter: number): string;
|
|
8
8
|
export declare function renderProgressBar(progress: number, size?: number): string;
|
|
9
|
+
export declare function logVars(data: Record<string, any>): void;
|
|
9
10
|
export declare function logExec(command: string, argv?: string[], env?: NodeJS.ProcessEnv, logToStderr?: boolean): void;
|
|
10
11
|
export declare function resultColumn(error: Error | null | string, state?: "started" | "ended"): "❌" | " ? " | "✅";
|
|
11
12
|
export declare function errorColumn(error: Error | null | string, verbose: number): string;
|
package/util/cli-util.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.confirm = exports.truncate = exports.parseOptions = exports.errorColumn = exports.resultColumn = exports.logExec = exports.renderProgressBar = exports.renderSpinner = exports.hideCursorCommand = exports.clearCommand = exports.showCursorCommand = exports.spinnerChars = exports.clearLastLine = void 0;
|
|
6
|
+
exports.confirm = exports.truncate = exports.parseOptions = exports.errorColumn = exports.resultColumn = exports.logExec = exports.logVars = exports.renderProgressBar = exports.renderSpinner = exports.hideCursorCommand = exports.clearCommand = exports.showCursorCommand = exports.spinnerChars = exports.clearLastLine = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const chalk_2 = require("chalk");
|
|
9
9
|
const readline_1 = require("readline");
|
|
@@ -28,6 +28,18 @@ function renderProgressBar(progress, size = 10) {
|
|
|
28
28
|
return completeChar.repeat(completedSize) + incompleteChar.repeat(restSize);
|
|
29
29
|
}
|
|
30
30
|
exports.renderProgressBar = renderProgressBar;
|
|
31
|
+
function logVars(data) {
|
|
32
|
+
let first = true;
|
|
33
|
+
for (const key in data) {
|
|
34
|
+
if (first) {
|
|
35
|
+
console.log();
|
|
36
|
+
first = false;
|
|
37
|
+
}
|
|
38
|
+
const value = data[key];
|
|
39
|
+
console.log(`${chalk_1.default.cyan(key)}${chalk_1.default.grey(":")} ${chalk_1.default.white(value ?? "")}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.logVars = logVars;
|
|
31
43
|
function logExec(command, argv = [], env, logToStderr) {
|
|
32
44
|
const envText = env
|
|
33
45
|
? Object.keys(env)
|
|
@@ -5,6 +5,7 @@ export declare function findRepositoryOrFail(config: ConfigType, repositoryName:
|
|
|
5
5
|
export declare function filterRepository(repository: RepositoryConfigType, action?: RepositoryConfigEnabledActionType): boolean;
|
|
6
6
|
export declare function filterPackages(config: ConfigType, options: {
|
|
7
7
|
packageNames?: string[];
|
|
8
|
+
packageTaskNames?: string[];
|
|
8
9
|
repositoryNames?: string[];
|
|
9
10
|
repositoryTypes?: string[];
|
|
10
11
|
sourceAction?: RepositoryConfigEnabledActionType;
|
|
@@ -22,6 +22,7 @@ function filterRepository(repository, action) {
|
|
|
22
22
|
exports.filterRepository = filterRepository;
|
|
23
23
|
function filterPackages(config, options) {
|
|
24
24
|
const packagePatterns = (0, string_util_1.makePathPatterns)(options.packageNames);
|
|
25
|
+
const taskNamePatterns = (0, string_util_1.makePathPatterns)(options.packageTaskNames);
|
|
25
26
|
return config.packages
|
|
26
27
|
.map((pkg) => {
|
|
27
28
|
pkg = Object.assign({}, pkg);
|
|
@@ -37,6 +38,8 @@ function filterPackages(config, options) {
|
|
|
37
38
|
return pkg;
|
|
38
39
|
})
|
|
39
40
|
.filter((pkg) => {
|
|
41
|
+
if (taskNamePatterns && !(0, micromatch_1.isMatch)(pkg.task?.name ?? "", taskNamePatterns))
|
|
42
|
+
return false;
|
|
40
43
|
return ((typeof pkg.enabled !== "boolean" || pkg.enabled) &&
|
|
41
44
|
!!pkg.repositoryNames?.length &&
|
|
42
45
|
(!packagePatterns || (0, micromatch_1.isMatch)(pkg.name, packagePatterns)));
|
package/util/date-util.d.ts
CHANGED
|
@@ -10,3 +10,7 @@ export declare type FilterByLastOptionsType = {
|
|
|
10
10
|
export declare function filterByLast<TItem extends {
|
|
11
11
|
date: string;
|
|
12
12
|
}>(items: TItem[], options: FilterByLastOptionsType, reasons?: Record<number, string[]>): TItem[];
|
|
13
|
+
export declare function createChron(): {
|
|
14
|
+
start: () => number;
|
|
15
|
+
elapsed: (formatted?: boolean | undefined) => string | number;
|
|
16
|
+
};
|
package/util/date-util.js
CHANGED
|
@@ -3,7 +3,8 @@ 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.filterByLast = void 0;
|
|
6
|
+
exports.createChron = exports.filterByLast = void 0;
|
|
7
|
+
const string_util_1 = require("./string-util");
|
|
7
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
9
|
const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
|
|
9
10
|
const isoWeek_1 = __importDefault(require("dayjs/plugin/isoWeek"));
|
|
@@ -72,3 +73,18 @@ function filterByLast(items, options, reasons) {
|
|
|
72
73
|
return items.filter((item) => validItems.includes(item));
|
|
73
74
|
}
|
|
74
75
|
exports.filterByLast = filterByLast;
|
|
76
|
+
function createChron() {
|
|
77
|
+
let startTime;
|
|
78
|
+
return {
|
|
79
|
+
start: () => (startTime = Date.now()),
|
|
80
|
+
elapsed: (formatted) => {
|
|
81
|
+
if (!startTime)
|
|
82
|
+
throw new Error(`Chron was not started`);
|
|
83
|
+
const seconds = (Date.now() - startTime) / 1000;
|
|
84
|
+
if (formatted)
|
|
85
|
+
return (0, string_util_1.formatSeconds)(seconds);
|
|
86
|
+
return seconds;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.createChron = createChron;
|
package/util/process-util.d.ts
CHANGED
|
@@ -23,11 +23,11 @@ export interface ExecSettingsInterface {
|
|
|
23
23
|
onSpawn?: (p: ChildProcess) => void;
|
|
24
24
|
stdout?: {
|
|
25
25
|
save?: boolean;
|
|
26
|
-
onData?: (data: string) =>
|
|
26
|
+
onData?: (data: string) => void;
|
|
27
27
|
};
|
|
28
28
|
stderr?: {
|
|
29
29
|
save?: boolean;
|
|
30
|
-
onData?: (data: string) =>
|
|
30
|
+
onData?: (data: string) => void;
|
|
31
31
|
toExitCode?: boolean;
|
|
32
32
|
};
|
|
33
33
|
onExitCodeError?: (data: ExecResultType, error: Error) => Error | false;
|
package/util/process-util.js
CHANGED
|
@@ -68,10 +68,10 @@ async function exec(command, argv = [], options = null, settings = {}) {
|
|
|
68
68
|
stderr: "",
|
|
69
69
|
exitCode: 0,
|
|
70
70
|
};
|
|
71
|
-
let
|
|
71
|
+
let finishListeners = pipe?.stream instanceof fs_1.WriteStream ? 2 : 1;
|
|
72
72
|
let streamError;
|
|
73
73
|
const tryFinish = () => {
|
|
74
|
-
if (!--
|
|
74
|
+
if (!--finishListeners)
|
|
75
75
|
finish();
|
|
76
76
|
};
|
|
77
77
|
const finish = () => {
|
|
@@ -127,7 +127,7 @@ async function exec(command, argv = [], options = null, settings = {}) {
|
|
|
127
127
|
if (log.stdout || settings.stdout) {
|
|
128
128
|
if (!p.stdout)
|
|
129
129
|
throw new Error(`stdout is not defined`);
|
|
130
|
-
p.stdout.on("data",
|
|
130
|
+
p.stdout.on("data", (data) => {
|
|
131
131
|
if (log.stdout)
|
|
132
132
|
logExecStdout({
|
|
133
133
|
data: data.toString(),
|
|
@@ -137,13 +137,13 @@ async function exec(command, argv = [], options = null, settings = {}) {
|
|
|
137
137
|
if (settings.stdout?.save)
|
|
138
138
|
spawnData.stdout += data.toString();
|
|
139
139
|
if (settings.stdout?.onData)
|
|
140
|
-
|
|
140
|
+
settings.stdout.onData(data.toString());
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
if (log.stderr || settings.stderr) {
|
|
144
144
|
if (!p.stderr)
|
|
145
145
|
throw new Error(`stderr is not defined`);
|
|
146
|
-
p.stderr.on("data",
|
|
146
|
+
p.stderr.on("data", (data) => {
|
|
147
147
|
if (log.stderr)
|
|
148
148
|
logExecStdout({
|
|
149
149
|
data: data.toString(),
|
|
@@ -153,7 +153,7 @@ async function exec(command, argv = [], options = null, settings = {}) {
|
|
|
153
153
|
if (settings.stderr?.save || settings.stderr?.toExitCode)
|
|
154
154
|
spawnData.stderr += data.toString();
|
|
155
155
|
if (settings.stderr?.onData)
|
|
156
|
-
|
|
156
|
+
settings.stderr.onData(data.toString());
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
p.on("error", (error) => (spawnError = error)).on("close", (exitCode) => {
|
package/util/string-util.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ export declare type UriType = {
|
|
|
13
13
|
path?: string;
|
|
14
14
|
};
|
|
15
15
|
export declare function formatUri(input: UriType, hidePassword?: boolean): string;
|
|
16
|
+
export declare function formatSeconds(seconds: number): string;
|
|
16
17
|
export declare function makePathPatterns(values: string[] | undefined): string[] | undefined;
|
|
17
18
|
export declare function formatDateTime(datetime: string): string;
|
package/util/string-util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatDateTime = exports.makePathPatterns = exports.formatUri = exports.parseStringList = exports.render = exports.snakeCase = exports.lcfirst = exports.ucfirst = exports.serialize = void 0;
|
|
3
|
+
exports.formatDateTime = exports.makePathPatterns = exports.formatSeconds = exports.formatUri = exports.parseStringList = exports.render = exports.snakeCase = exports.lcfirst = exports.ucfirst = exports.serialize = void 0;
|
|
4
4
|
const AppError_1 = require("../Error/AppError");
|
|
5
5
|
function serialize(message, data) {
|
|
6
6
|
if (data)
|
|
@@ -67,6 +67,26 @@ function formatUri(input, hidePassword) {
|
|
|
67
67
|
return uri;
|
|
68
68
|
}
|
|
69
69
|
exports.formatUri = formatUri;
|
|
70
|
+
function formatSeconds(seconds) {
|
|
71
|
+
let unit;
|
|
72
|
+
let value;
|
|
73
|
+
if (seconds > 60 * 60) {
|
|
74
|
+
value = seconds / 60 / 60;
|
|
75
|
+
unit = `hour`;
|
|
76
|
+
}
|
|
77
|
+
else if (seconds > 60) {
|
|
78
|
+
value = seconds / 60;
|
|
79
|
+
unit = `minute`;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
value = seconds;
|
|
83
|
+
unit = `second`;
|
|
84
|
+
}
|
|
85
|
+
if (value !== 1)
|
|
86
|
+
unit += `s`;
|
|
87
|
+
return `${value.toFixed(2)} ${unit}`;
|
|
88
|
+
}
|
|
89
|
+
exports.formatSeconds = formatSeconds;
|
|
70
90
|
function makePathPatterns(values) {
|
|
71
91
|
return values?.flatMap((v) => [v, `${v}/**`]);
|
|
72
92
|
}
|
package/util/zip-util.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface ZipDataType {
|
|
|
26
26
|
includeList?: string;
|
|
27
27
|
excludeList?: string;
|
|
28
28
|
verbose?: boolean;
|
|
29
|
-
onStream?: (data: ZipStreamDataType) =>
|
|
29
|
+
onStream?: (data: ZipStreamDataType) => void;
|
|
30
30
|
}
|
|
31
31
|
export interface UnzipDataType {
|
|
32
32
|
command?: string;
|
|
@@ -34,7 +34,7 @@ export interface UnzipDataType {
|
|
|
34
34
|
files?: (ZipDataFilterType | string)[];
|
|
35
35
|
output: string;
|
|
36
36
|
verbose?: boolean;
|
|
37
|
-
onStream?: (data: UnzipStreamDataType) =>
|
|
37
|
+
onStream?: (data: UnzipStreamDataType) => void;
|
|
38
38
|
}
|
|
39
39
|
export declare type UnzipStreamDataType = {
|
|
40
40
|
type: "progress";
|
package/util/zip-util.js
CHANGED
|
@@ -30,7 +30,7 @@ function buildArguments(filters) {
|
|
|
30
30
|
return args;
|
|
31
31
|
}
|
|
32
32
|
exports.buildArguments = buildArguments;
|
|
33
|
-
|
|
33
|
+
function parseZipStream(chunk, buffer, cb) {
|
|
34
34
|
const lines = chunk.trim().split(/\r?\n/g);
|
|
35
35
|
for (const line of lines) {
|
|
36
36
|
let matches = null;
|
|
@@ -42,7 +42,7 @@ async function parseZipStream(chunk, buffer, cb) {
|
|
|
42
42
|
if (path !== buffer.lastPath)
|
|
43
43
|
buffer.currentPaths++;
|
|
44
44
|
buffer.lastPath = path;
|
|
45
|
-
|
|
45
|
+
cb({
|
|
46
46
|
type: "progress",
|
|
47
47
|
data: { progress, path, files: buffer.currentPaths },
|
|
48
48
|
});
|
|
@@ -50,7 +50,7 @@ async function parseZipStream(chunk, buffer, cb) {
|
|
|
50
50
|
else if (line.startsWith("Add new data to archive:")) {
|
|
51
51
|
const [, folders] = /(\d+) folders?/i.exec(line) || [, 0];
|
|
52
52
|
const [, files] = /(\d+) files?/i.exec(line) || [, 0];
|
|
53
|
-
|
|
53
|
+
cb({
|
|
54
54
|
type: "summary",
|
|
55
55
|
data: {
|
|
56
56
|
folders: Number(folders),
|
|
@@ -83,9 +83,9 @@ async function zip(data) {
|
|
|
83
83
|
toExitCode: true,
|
|
84
84
|
},
|
|
85
85
|
stdout: {
|
|
86
|
-
onData:
|
|
87
|
-
parseZipStream(chunk, buffer,
|
|
88
|
-
|
|
86
|
+
onData: (chunk) => {
|
|
87
|
+
parseZipStream(chunk, buffer, (stream) => {
|
|
88
|
+
data.onStream?.(stream);
|
|
89
89
|
if (stream.type === "summary")
|
|
90
90
|
result = stream.data;
|
|
91
91
|
});
|
|
@@ -95,7 +95,7 @@ async function zip(data) {
|
|
|
95
95
|
return result;
|
|
96
96
|
}
|
|
97
97
|
exports.zip = zip;
|
|
98
|
-
|
|
98
|
+
function parseUnzipStream(chunk, cb) {
|
|
99
99
|
const lines = chunk.trim().split(/\r?\n/g);
|
|
100
100
|
for (const line of lines) {
|
|
101
101
|
let matches = null;
|
|
@@ -103,7 +103,7 @@ async function parseUnzipStream(chunk, cb) {
|
|
|
103
103
|
const progress = Number(matches[1]);
|
|
104
104
|
const files = Number(matches[2]);
|
|
105
105
|
const path = line.slice(line.indexOf("-") + 1).trim();
|
|
106
|
-
|
|
106
|
+
cb({
|
|
107
107
|
type: "progress",
|
|
108
108
|
data: { progress, path, files },
|
|
109
109
|
});
|
|
@@ -124,7 +124,7 @@ async function unzip(data) {
|
|
|
124
124
|
stderr: { toExitCode: true },
|
|
125
125
|
stdout: {
|
|
126
126
|
...(data.onStream && {
|
|
127
|
-
onData:
|
|
127
|
+
onData: (chunk) => {
|
|
128
128
|
if (data.onStream)
|
|
129
129
|
parseUnzipStream(chunk, data.onStream);
|
|
130
130
|
},
|