node-automator 1.4.26 → 1.4.27

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.
@@ -8,7 +8,8 @@ const { parse, stringify, processRename } = require("../utils/file_tool");
8
8
 
9
9
  class BackupCommand extends BaseCommand {
10
10
  async execute() {
11
- const { sourceFolder, backupFolder, backupCfgs, quiet } = this.selfData;
11
+ const { sourceFolder, backupFolder, backupCfgs, verbose } =
12
+ this.selfData;
12
13
 
13
14
  async function backup(bakCfg, filename) {
14
15
  const {
@@ -106,7 +107,7 @@ class BackupCommand extends BaseCommand {
106
107
  if (bakCfg) {
107
108
  backup(bakCfg, filename)
108
109
  .then(() => {
109
- !(quiet || bakCfg.quiet) &&
110
+ (verbose || bakCfg.verbose) &&
110
111
  success(`${filename} 备份成功`);
111
112
  })
112
113
  .catch((err) => {
@@ -1,25 +1,39 @@
1
1
  const _path = require("node:path");
2
+ const fs = require("node:fs");
2
3
  const { get_fst_file, get_full_path, move } = require("../utils/file_tool");
3
4
  const { BaseCommand } = require("./base");
4
- const { readFileSync } = require("node:fs");
5
+ const { default: imagemin } = require('imagemin');
6
+ const { default: imageminPngquant } = require('imagemin-pngquant');
7
+ const { default: imageminMozjpeg } = require('imagemin-mozjpeg');
5
8
 
6
9
  class CompressCommand extends BaseCommand {
7
10
  async execute() {
8
- const sharp = require("sharp");
9
11
  const data = this.selfData;
10
12
  const src = get_fst_file(data.src);
11
- const dst = get_full_path(data.dst, "FILE");
12
- let format = data.format;
13
- if (!format) {
14
- format = dst.split(".").pop();
13
+ const dstFile = get_full_path(data.dst, "FILE");
14
+ const dstDir = _path.dirname(dstFile);
15
+ const dstName = _path.basename(dstFile);
16
+ const tmpFolder = _path.join(this.shareData.AUTOMATOR_SCRATCH, "comporess");
17
+ if (!fs.existsSync(tmpFolder)) {
18
+ fs.mkdirSync(tmpFolder, { recursive: true });
15
19
  }
16
- format = format.toLowerCase();
17
- if (format === "jpg") {
18
- format = "jpeg";
19
- }
20
- const options = data.options;
21
- const fileContent = readFileSync(src);
22
- await sharp(fileContent)[format](options).toFile(dst);
20
+ const quality = data.options?.quality || 80;
21
+ await imagemin([src], {
22
+ destination: tmpFolder,
23
+ plugins: [
24
+ imageminMozjpeg({ quality: quality }), // 压缩 JPG 图片
25
+ imageminPngquant({
26
+ quality: [0.6, quality / 100],
27
+ })
28
+ ]
29
+ });
30
+ const compressedFile = _path.join(tmpFolder, _path.basename(src));
31
+ fs.copyFileSync(compressedFile, _path.join(dstDir, dstName));
32
+ fs.unlinkSync(compressedFile);
33
+ // const sharp = require("sharp");
34
+ // const options = data.options;
35
+ // const fileContent = readFileSync(src);
36
+ // await sharp(fileContent)[format](options).toFile(dst);
23
37
  }
24
38
  }
25
39
 
package/commands/loop.js CHANGED
@@ -67,7 +67,8 @@ class LoopCommand extends BaseCommand {
67
67
  if (typeof data.tip_key === "boolean") {
68
68
  tip = `[${loop_data}]`;
69
69
  } else {
70
- tip = `[${this.getDataByKey(data.tip_key)}]`;
70
+ const tipKeys = _transform_tool.toArray(data.tip_key);
71
+ tip = `[${tipKeys.map(key => this.getDataByKey(key)).join("/")}]`;
71
72
  }
72
73
  }
73
74
  if (show_progress) {
@@ -70,7 +70,7 @@ class WatchMailCommand extends BaseCommand {
70
70
  } else {
71
71
  this.shareData.mail_data = mailData;
72
72
  }
73
- if (!data.quiet) {
73
+ if (data.verbose) {
74
74
  success("");
75
75
  success(getPrint(mailData));
76
76
  }
@@ -37,7 +37,7 @@ class WebSocketCommand extends BaseCommand {
37
37
  let receivedUTF8Total = 0;
38
38
  let receivedIndex = 0;
39
39
  const timeout = this.selfData.timeout || 0;
40
- const quiet = this.selfData.quiet || false;
40
+ const quiet = !this.selfData.verbose || true;
41
41
  const _endianSuffix = little_endian ? "LE" : "BE";
42
42
 
43
43
  let rl;
package/commands/zip.js CHANGED
@@ -42,20 +42,22 @@ class ZipCommand extends BaseCommand {
42
42
  let entryName = path.join(zipPath, path.basename(file));
43
43
  entryName = processRename(entryName, data.options?.rename);
44
44
  const show_src = entryName;
45
- progress(index, files.length, {
46
- desc: `Add ${show_src}`,
47
- depth: 0,
48
- align: true,
49
- });
45
+ data.verbose &&
46
+ progress(index, files.length, {
47
+ desc: `Add ${show_src}`,
48
+ depth: 0,
49
+ align: true,
50
+ });
50
51
  // zip.addLocalFile(file, zipPath);
51
52
  zip.addFile(entryName, fs.readFileSync(file));
52
53
  }
53
54
  clearLine();
54
- progress(files.length, files.length, {
55
- desc: `压缩中...`,
56
- depth: 0,
57
- align: true,
58
- });
55
+ data.verbose &&
56
+ progress(files.length, files.length, {
57
+ desc: `压缩中...`,
58
+ depth: 0,
59
+ align: true,
60
+ });
59
61
  // or write everything to disk
60
62
  if (data.dst) {
61
63
  const dst = get_full_path(data.dst);
@@ -71,12 +73,13 @@ class ZipCommand extends BaseCommand {
71
73
  const buffer = zip.toBuffer();
72
74
  return buffer;
73
75
  }
74
- progress(files.length, files.length, {
75
- desc: `压缩完成!`,
76
- depth: 0,
77
- color: "green",
78
- });
79
- info("");
76
+ data.verbose &&
77
+ progress(files.length, files.length, {
78
+ desc: `压缩完成!`,
79
+ depth: 0,
80
+ color: "green",
81
+ });
82
+ data.verbose && info("");
80
83
  }
81
84
  }
82
85
 
@@ -30,11 +30,12 @@ class ZipFolderCommand extends BaseCommand {
30
30
  if (!isAccept(filename)) {
31
31
  return false;
32
32
  }
33
- progress(i++, 0, {
34
- desc: `${filename}`,
35
- depth: 0,
36
- align: true,
37
- });
33
+ data.verbose &&
34
+ progress(i++, 0, {
35
+ desc: `${filename}`,
36
+ depth: 0,
37
+ align: true,
38
+ });
38
39
  return true;
39
40
  });
40
41
  // or write everything to disk
package/index.js CHANGED
@@ -120,7 +120,8 @@ async function MainProcess() {
120
120
  } catch (err) {
121
121
  lastError = err.message || err;
122
122
  }
123
- const costTime = Date.now() - beginTime;
123
+ const endTime = shareData.AUTOMATOR_END_TIME || Date.now();
124
+ const costTime = endTime - beginTime;
124
125
  if (enableTimer) {
125
126
  clearInterval(timer);
126
127
  info("");
@@ -161,28 +162,25 @@ async function MainProcess() {
161
162
  lastError,
162
163
  );
163
164
  }
164
- if (!shareData.QUIET_MODE) {
165
- // 非代码启动,需要暂停
166
- if (shareData.ALERT_RESULT) {
167
- const title = `${shareData.TITLE || "任务即将结束"}`;
168
- await showAlert(
169
- hasError ? "error" : "info",
170
- hasError ? `✖ 失败, ${lastError}` : "✔ 成功!",
171
- title,
172
- );
173
- } else {
174
- const successIcon =
175
- shareData.SUCCESS_ICON ||
176
- `${shareData.AUTOMATOR_ROOT}/assets/success.png`;
177
- const errorIcon =
178
- shareData.ERROR_ICON ||
179
- `${shareData.AUTOMATOR_ROOT}/assets/error.png`;
180
- await showNotify({
181
- title: `${shareData.TITLE || cfgs}`,
182
- message: hasError ? lastError : `任务即将结束`,
183
- icon: hasError ? errorIcon : successIcon,
184
- });
185
- }
165
+ if (shareData.ALERT_RESULT) {
166
+ const title = `${shareData.TITLE || "任务即将结束"}`;
167
+ await showAlert(
168
+ hasError ? "error" : "info",
169
+ hasError ? `✖ 失败, ${lastError}` : "✔ 成功!",
170
+ title,
171
+ );
172
+ } else if (shareData.NOTIFY_RESULT) {
173
+ const successIcon =
174
+ shareData.SUCCESS_ICON ||
175
+ `${shareData.AUTOMATOR_ROOT}/assets/success.png`;
176
+ const errorIcon =
177
+ shareData.ERROR_ICON ||
178
+ `${shareData.AUTOMATOR_ROOT}/assets/error.png`;
179
+ await showNotify({
180
+ title: `${shareData.TITLE || cfgs}`,
181
+ message: hasError ? lastError : `任务即将结束`,
182
+ icon: hasError ? errorIcon : successIcon,
183
+ });
186
184
  }
187
185
  // 手动调用 exit, 会导致异步的定时器事件失效
188
186
  if (shareData.EXIT_IMMEDIATELY) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-automator",
3
- "version": "1.4.26",
3
+ "version": "1.4.27",
4
4
  "description": "Execute automation with yaml configuration(compatible with json)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -39,6 +39,9 @@
39
39
  "html-to-text": "^8.2.0",
40
40
  "iconv-lite": "^0.6.2",
41
41
  "image-size": "^1.0.0",
42
+ "imagemin": "^9.0.1",
43
+ "imagemin-mozjpeg": "^10.0.0",
44
+ "imagemin-pngquant": "^10.0.0",
42
45
  "javascript-obfuscator": "^4.1.1",
43
46
  "jimp": "^0.22.12",
44
47
  "json-stable-stringify": "^1.0.1",
@@ -58,7 +61,6 @@
58
61
  "pinyin": "^4.0.0",
59
62
  "request": "^2.88.2",
60
63
  "request-progress": "^3.0.0",
61
- "sharp": "^0.34.3",
62
64
  "split-file": "^2.3.0",
63
65
  "spreadsheet-column": "^1.1.1",
64
66
  "strip-json-comments": "^3.1.1",
@@ -283,8 +283,8 @@ async function copy(src, dst, base, options) {
283
283
  options,
284
284
  );
285
285
  const filesize = get_files_size(srcs);
286
- !options.quiet && info("");
287
- !options.quiet &&
286
+ options.verbose && info("");
287
+ options.verbose &&
288
288
  whisper(
289
289
  `复制 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`,
290
290
  undefined,
@@ -299,7 +299,7 @@ async function copy(src, dst, base, options) {
299
299
  ++dir_num;
300
300
  continue;
301
301
  }
302
- !options.quiet &&
302
+ options.verbose &&
303
303
  display_tool.progress(srcIndex + 1, srcs.length, {
304
304
  desc: `Copy ${show_src}`,
305
305
  depth: 0,
@@ -344,8 +344,8 @@ async function copy(src, dst, base, options) {
344
344
  }
345
345
  }
346
346
 
347
- !options.quiet && info("");
348
- !options.quiet &&
347
+ options.verbose && info("");
348
+ options.verbose &&
349
349
  whisper(
350
350
  `复制完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`,
351
351
  undefined,
@@ -369,8 +369,8 @@ async function move(src, dst, base, options) {
369
369
  options,
370
370
  );
371
371
  const filesize = get_files_size(srcs);
372
- !options.quiet && info("");
373
- !options.quiet &&
372
+ options.verbose && info("");
373
+ options.verbose &&
374
374
  whisper(
375
375
  `移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`,
376
376
  undefined,
@@ -385,7 +385,7 @@ async function move(src, dst, base, options) {
385
385
  ++dir_num;
386
386
  continue;
387
387
  }
388
- !options.quiet &&
388
+ options.verbose &&
389
389
  display_tool.progress(srcIndex + 1, srcs.length, {
390
390
  desc: `Move ${show_src}`,
391
391
  depth: 0,
@@ -432,8 +432,8 @@ async function move(src, dst, base, options) {
432
432
  fs.unlinkSync(src);
433
433
  }
434
434
 
435
- !options.quiet && info("");
436
- !options.quiet &&
435
+ options.verbose && info("");
436
+ options.verbose &&
437
437
  whisper(
438
438
  `移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`,
439
439
  undefined,
@@ -457,8 +457,8 @@ async function move_local(src, dst, base, options) {
457
457
  options,
458
458
  );
459
459
  const filesize = get_files_size(srcs);
460
- !options.quiet && info("");
461
- !options.quiet &&
460
+ options.verbose && info("");
461
+ options.verbose &&
462
462
  whisper(
463
463
  `移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`,
464
464
  undefined,
@@ -472,7 +472,7 @@ async function move_local(src, dst, base, options) {
472
472
  if (fs.lstatSync(src).isDirectory()) {
473
473
  ++dir_num;
474
474
  }
475
- !options.quiet &&
475
+ options.verbose &&
476
476
  display_tool.progress(srcIndex + 1, srcs.length, {
477
477
  desc: `Rename ${show_src}`,
478
478
  depth: 0,
@@ -517,8 +517,8 @@ async function move_local(src, dst, base, options) {
517
517
  }
518
518
  }
519
519
 
520
- !options.quiet && info("");
521
- !options.quiet &&
520
+ options.verbose && info("");
521
+ options.verbose &&
522
522
  whisper(
523
523
  `移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`,
524
524
  undefined,
@@ -530,8 +530,8 @@ async function remove(src, options) {
530
530
  srcs = get_file_list(src);
531
531
  options = Object.assign({ recursive: true }, options);
532
532
  const filesize = get_files_size(srcs);
533
- !options.quiet && info("");
534
- !options.quiet &&
533
+ options.verbose && info("");
534
+ options.verbose &&
535
535
  whisper(
536
536
  `删除 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} options: ${JSON.stringify(options)}`,
537
537
  undefined,
@@ -543,7 +543,7 @@ async function remove(src, options) {
543
543
  const src = srcs[srcIndex];
544
544
  const show_src = src;
545
545
  try {
546
- display_tool.progress(srcIndex + 1, srcs.length, {
546
+ options.verbose && display_tool.progress(srcIndex + 1, srcs.length, {
547
547
  desc: `Remove ${show_src}`,
548
548
  depth: 0,
549
549
  color: "cyan",
@@ -565,8 +565,8 @@ async function remove(src, options) {
565
565
  }
566
566
  }
567
567
 
568
- !options.quiet && info("");
569
- !options.quiet &&
568
+ options.verbose && info("");
569
+ options.verbose &&
570
570
  whisper(
571
571
  `删除完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`,
572
572
  undefined,
@@ -41,7 +41,7 @@ async function doRequest(data) {
41
41
  }
42
42
  let result;
43
43
  const useCache = enable_http_cache && http_cache;
44
- const quiet = data.quiet;
44
+ const quiet = !data.verbose;
45
45
  !quiet && info(`[${options.method}] ${url}${useCache ? "[缓存]" : ""}`);
46
46
  let hasProgress = false;
47
47
  const fileDst = get_full_path(
@@ -338,7 +338,7 @@ async function select(content, data) {
338
338
  onKeyPress(undefined, { name: "return" });
339
339
  }
340
340
  });
341
- !data.quiet && success(`已选择:${getPrint(selectedOption, true)}`);
341
+ data.verbose && success(`已选择:${getPrint(selectedOption, true)}`);
342
342
  return selectedOption;
343
343
  }
344
344
 
@@ -628,7 +628,7 @@ async function multiSelect(content, data) {
628
628
  onKeyPress(undefined, { name: "return" });
629
629
  }
630
630
  });
631
- !data.quiet && success(`已选择:${getPrint(selectedOptions, true)}`);
631
+ data.verbose && success(`已选择:${getPrint(selectedOptions, true)}`);
632
632
  return selectedOptions;
633
633
  }
634
634
 
@@ -25,7 +25,7 @@ async function exec_shell(data) {
25
25
  const instant_stdout = data.instant_stdout;
26
26
  const capture_stdout = isStdOut() || data.capture_stdout;
27
27
  const acceptableErrors = data.acceptableErrors || [];
28
- const quiet = data.quiet;
28
+ const quiet = !data.verbose;
29
29
  const result = await new Promise((resolve, _reject) => {
30
30
  /** @type {string[]} */
31
31
  let cmd = data.cmd;
@@ -59,7 +59,7 @@ async function exec_shell(data) {
59
59
  const errors = [];
60
60
  const encoding = data.encoding || "cp936";
61
61
  const raw_output = encoding === "raw";
62
- !quiet && whisper(`cmd:[${cmd}] cwd:${data.cwd} inputs:${data.inputs}`);
62
+ !quiet && info(`cmd:[${cmd}] cwd:${data.cwd} inputs:${data.inputs}`);
63
63
  options.stdio = [
64
64
  "pipe",
65
65
  capture_stdout ? "pipe" : process.stdout,