@datatruck/cli 0.6.0 → 0.6.1
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/CHANGELOG.md +6 -0
- package/Repository/ResticRepository.js +17 -3
- package/Task/MariadbTask.js +1 -1
- package/package.json +1 -1
- package/util/ResticUtil.d.ts +1 -1
- package/util/ResticUtil.js +2 -2
- package/util/process-util.d.ts +2 -2
- package/util/process-util.js +4 -4
- package/util/zip-util.d.ts +2 -2
- package/util/zip-util.js +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @datatruck/cli
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0ba6229`](https://github.com/swordev/datatruck/commit/0ba6229348c109a59783e72242ab7c0e61f25e36) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix progress bar in restic repository
|
|
8
|
+
|
|
3
9
|
## 0.6.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -210,6 +210,8 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
210
210
|
});
|
|
211
211
|
const nodePkg = (0, fs_util_1.parsePackageFile)();
|
|
212
212
|
let lastProgress;
|
|
213
|
+
let totalFilesChanges = 0;
|
|
214
|
+
const totalFilesChangesLimit = 10;
|
|
213
215
|
await data.onProgress({
|
|
214
216
|
step: "Executing backup action...",
|
|
215
217
|
});
|
|
@@ -233,10 +235,22 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
233
235
|
],
|
|
234
236
|
onStream: async (streamData) => {
|
|
235
237
|
if (streamData.message_type === "status") {
|
|
238
|
+
let showProgressBar = false;
|
|
239
|
+
if (totalFilesChanges > totalFilesChangesLimit) {
|
|
240
|
+
showProgressBar = true;
|
|
241
|
+
}
|
|
242
|
+
else if (lastProgress?.total !== streamData.total_files) {
|
|
243
|
+
totalFilesChanges = 0;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
totalFilesChanges++;
|
|
247
|
+
}
|
|
236
248
|
await data.onProgress((lastProgress = {
|
|
237
|
-
total: streamData.total_files,
|
|
238
|
-
current: streamData.files_done ?? 0,
|
|
239
|
-
percent:
|
|
249
|
+
total: Math.max(lastProgress?.total || 0, streamData.total_files),
|
|
250
|
+
current: Math.max(lastProgress?.current || 0, streamData.files_done ?? 0),
|
|
251
|
+
percent: showProgressBar
|
|
252
|
+
? Number((streamData.percent_done * 100).toFixed(2))
|
|
253
|
+
: 0,
|
|
240
254
|
step: streamData.current_files?.join(", ") ?? "-",
|
|
241
255
|
}));
|
|
242
256
|
}
|
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/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/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
|
@@ -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/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
|
},
|