@datatruck/cli 0.3.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @datatruck/cli
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8957c3b`](https://github.com/swordev/datatruck/commit/8957c3b5846606db8b825fef357445210f2a3ac3) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix restic progress parser
8
+
9
+ * [`2989718`](https://github.com/swordev/datatruck/commit/29897185e3d6659359d51ab2212351005137f86c) Thanks [@juanrgm](https://github.com/juanrgm)! - Show closing reason
10
+
11
+ - [`b9e0843`](https://github.com/swordev/datatruck/commit/b9e0843c7970944cfd30a7d2a543f515adfa60e4) Thanks [@juanrgm](https://github.com/juanrgm)! - Show restic progress in megabytes
12
+
3
13
  ## 0.3.1
4
14
 
5
15
  ### Patch Changes
@@ -210,8 +210,10 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
210
210
  onStream: async (streamData) => {
211
211
  if (streamData.message_type === "status") {
212
212
  await data.onProgress({
213
- total: streamData.total_bytes,
214
- current: streamData.bytes_done ?? 0,
213
+ total: Number((streamData.total_bytes / 1024 / 1024).toFixed(2)),
214
+ current: streamData.bytes_done
215
+ ? Number((streamData.bytes_done / 1024 / 1024).toFixed(2))
216
+ : 0,
215
217
  percent: Number((streamData.percent_done * 100).toFixed(2)),
216
218
  step: streamData.current_files?.join(", ") ?? "-",
217
219
  });
package/cli.js CHANGED
@@ -84,10 +84,12 @@ exports.buildArgs = buildArgs;
84
84
  function parseArgs(args) {
85
85
  program.parse(args);
86
86
  const verbose = getGlobalOptions().verbose;
87
- (0, process_util_1.onExit)((eventName) => {
87
+ (0, process_util_1.onExit)((eventName, error) => {
88
88
  if (eventName !== "exit") {
89
89
  process.stdout.write(cli_util_1.showCursorCommand);
90
- console.log("\nClosing...");
90
+ console.log(`\nClosing... (reason: ${eventName})`);
91
+ if (error instanceof Error)
92
+ console.error((0, chalk_1.red)(error.stack));
91
93
  }
92
94
  if (!verbose)
93
95
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "dependencies": {
5
5
  "ajv": "^8.11.0",
6
6
  "chalk": "^4.1.2",
@@ -117,9 +117,17 @@ class ResticUtil {
117
117
  stdout: {
118
118
  ...(options.onStream && {
119
119
  onData: async (data) => {
120
- data = data.trim();
121
- if (data.startsWith("{") && data.endsWith("}")) {
122
- await options.onStream?.(JSON.parse(data));
120
+ for (const rawLine of data.split("\n")) {
121
+ const line = rawLine.trim();
122
+ if (line.startsWith("{") && line.endsWith("}")) {
123
+ let parsedLine;
124
+ try {
125
+ parsedLine = JSON.parse(line);
126
+ }
127
+ catch (error) { }
128
+ if (parsedLine)
129
+ await options.onStream?.(parsedLine);
130
+ }
123
131
  }
124
132
  },
125
133
  }),
@@ -46,5 +46,5 @@ export declare type ExecResultType = {
46
46
  };
47
47
  export declare function exec(command: string, argv?: string[], options?: SpawnOptions | null, settings?: ExecSettingsInterface): Promise<ExecResultType>;
48
48
  declare type EventNameType = "exit" | "SIGINT" | "SIGUSR1" | "SIGUSR2" | "SIGTERM" | "uncaughtException";
49
- export declare function onExit(cb: (eventName: EventNameType) => void): void;
49
+ export declare function onExit(cb: (eventName: EventNameType, ...args: any[]) => void): void;
50
50
  export {};
@@ -175,7 +175,7 @@ const eventNames = [
175
175
  ];
176
176
  function onExit(cb) {
177
177
  for (const eventName of eventNames) {
178
- process.on(eventName, cb.bind(null, eventName));
178
+ process.on(eventName, (...args) => cb(eventName, ...args));
179
179
  }
180
180
  }
181
181
  exports.onExit = onExit;