node-automator 1.4.14 → 1.4.16

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.
@@ -20,7 +20,7 @@ class CompressCommand extends BaseCommand {
20
20
  const options = data.options;
21
21
  await sharp(src)[format](options)
22
22
  .toFile(tmp);
23
- await move(tmp, path.dirname(dst));
23
+ await move(tmp, path.dirname(dst), undefined, { quiet: true, rename: path.basename(dst) });
24
24
  }
25
25
  }
26
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-automator",
3
- "version": "1.4.14",
3
+ "version": "1.4.16",
4
4
  "description": "Execute automation with yaml configuration(compatible with json)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -149,7 +149,7 @@ function write_plain(dst, data, options) {
149
149
  }
150
150
 
151
151
  async function write_with_type(data, dst, type, options) {
152
- if (Buffer.isBuffer(data) || typeof data === "string") {
152
+ if (Buffer.isBuffer(data) || typeof data === "string") {
153
153
  write_plain(dst, data);
154
154
  } else {
155
155
  if (!type) {
@@ -168,7 +168,7 @@ async function write_with_type(data, dst, type, options) {
168
168
  }
169
169
  switch (options?.mode) {
170
170
  case "merge": {
171
- data = {...(await read_cfg(dst, type)), ...data};
171
+ data = { ...(await read_cfg(dst, type)), ...data };
172
172
  break;
173
173
  }
174
174
  case "concat": {
@@ -267,8 +267,8 @@ async function copy(src, dst, base, options) {
267
267
  overwrite: true
268
268
  }, options);
269
269
  let filesize = get_files_size(srcs);
270
- info("");
271
- whisper(`复制 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
270
+ !options.quiet && info("");
271
+ !options.quiet && whisper(`复制 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
272
272
  let dir_num = 0;
273
273
  let actual_files = [];
274
274
  for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
@@ -278,7 +278,7 @@ async function copy(src, dst, base, options) {
278
278
  ++dir_num;
279
279
  continue;
280
280
  }
281
- display_tool.progress(srcIndex + 1, srcs.length, {
281
+ !options.quiet && display_tool.progress(srcIndex + 1, srcs.length, {
282
282
  desc: `Copy ${show_src}`,
283
283
  depth: 0,
284
284
  color: "green",
@@ -311,6 +311,10 @@ async function copy(src, dst, base, options) {
311
311
  actual_files.push(src);
312
312
  }
313
313
  await new Promise(resolve => {
314
+ // 如果存在,先删除
315
+ if (fs.existsSync(dstFile)) {
316
+ fs.unlinkSync(dstFile);
317
+ }
314
318
  // !options.overwrite ? fs.constants.COPYFILE_EXCL : 0
315
319
  fs.copyFile(src, dstFile, 0, (err) => {
316
320
  if (err) {
@@ -322,9 +326,9 @@ async function copy(src, dst, base, options) {
322
326
  }
323
327
  }
324
328
  }
325
-
326
- info("");
327
- whisper(`复制完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
329
+
330
+ !options.quiet && info("");
331
+ !options.quiet && whisper(`复制完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
328
332
  }
329
333
 
330
334
  async function move(src, dst, base, options) {
@@ -340,8 +344,8 @@ async function move(src, dst, base, options) {
340
344
  overwrite: true
341
345
  }, options);
342
346
  let filesize = get_files_size(srcs);
343
- info("");
344
- whisper(`移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
347
+ !options.quiet && info("");
348
+ !options.quiet && whisper(`移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
345
349
  let actual_files = [];
346
350
  let dir_num = 0;
347
351
  for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
@@ -351,7 +355,7 @@ async function move(src, dst, base, options) {
351
355
  ++dir_num;
352
356
  continue;
353
357
  }
354
- display_tool.progress(srcIndex + 1, srcs.length, {
358
+ !options.quiet && display_tool.progress(srcIndex + 1, srcs.length, {
355
359
  desc: `Move ${show_src}`,
356
360
  depth: 0,
357
361
  color: "cyan",
@@ -384,6 +388,10 @@ async function move(src, dst, base, options) {
384
388
  if (!options.overwrite && fs.existsSync(dstFile)) {
385
389
  resolve();
386
390
  } else {
391
+ // 如果存在,先删除
392
+ if (fs.existsSync(dstFile)) {
393
+ fs.unlinkSync(dstFile);
394
+ }
387
395
  fs.copyFile(src, dstFile, 0, (err) => {
388
396
  if (err) {
389
397
  throw (err);
@@ -397,9 +405,9 @@ async function move(src, dst, base, options) {
397
405
  // 再删除
398
406
  fs.unlinkSync(src);
399
407
  }
400
-
401
- info("");
402
- whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
408
+
409
+ !options.quiet && info("");
410
+ !options.quiet && whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
403
411
  }
404
412
 
405
413
  async function move_local(src, dst, base, options) {
@@ -415,8 +423,8 @@ async function move_local(src, dst, base, options) {
415
423
  overwrite: true
416
424
  }, options);
417
425
  let filesize = get_files_size(srcs);
418
- info("");
419
- whisper(`移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
426
+ !options.quiet && info("");
427
+ !options.quiet && whisper(`移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
420
428
  let actual_files = [];
421
429
  let dir_num = 0;
422
430
  for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
@@ -425,7 +433,7 @@ async function move_local(src, dst, base, options) {
425
433
  if (fs.lstatSync(src).isDirectory()) {
426
434
  ++dir_num;
427
435
  }
428
- display_tool.progress(srcIndex + 1, srcs.length, {
436
+ !options.quiet && display_tool.progress(srcIndex + 1, srcs.length, {
429
437
  desc: `Rename ${show_src}`,
430
438
  depth: 0,
431
439
  color: "cyan",
@@ -469,17 +477,17 @@ async function move_local(src, dst, base, options) {
469
477
  }
470
478
  }
471
479
  }
472
-
473
- info("");
474
- whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
480
+
481
+ !options.quiet && info("");
482
+ !options.quiet && whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
475
483
  }
476
484
 
477
485
  async function remove(src, options) {
478
486
  srcs = get_file_list(src);
479
487
  options = Object.assign({ recursive: true }, options);
480
488
  let filesize = get_files_size(srcs);
481
- info("");
482
- whisper(`删除 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} options: ${JSON.stringify(options)}`, undefined, true);
489
+ !options.quiet && info("");
490
+ !options.quiet && whisper(`删除 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} options: ${JSON.stringify(options)}`, undefined, true);
483
491
  let actual_files = [];
484
492
  let dir_num = 0;
485
493
  for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
@@ -507,9 +515,9 @@ async function remove(src, options) {
507
515
  warn(err);
508
516
  }
509
517
  }
510
-
511
- info("");
512
- whisper(`删除完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
518
+
519
+ !options.quiet && info("");
520
+ !options.quiet && whisper(`删除完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
513
521
  }
514
522
 
515
523
  module.exports = {