node-automator 1.4.13 → 1.4.15
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/commands/compress.js +16 -8
- package/package.json +2 -1
- package/utils/file_tool.js +25 -25
package/commands/compress.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
const
|
|
2
|
-
const {
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { get_fst_file, get_full_path, move } = require('../utils/file_tool');
|
|
3
3
|
const { BaseCommand } = require("./base");
|
|
4
|
-
const Jimp = require("jimp");
|
|
5
4
|
|
|
6
5
|
class CompressCommand extends BaseCommand {
|
|
7
6
|
async execute() {
|
|
7
|
+
const sharp = require("sharp");
|
|
8
8
|
const data = this.selfData;
|
|
9
9
|
const src = get_fst_file(data.src);
|
|
10
10
|
const dst = get_full_path(data.dst, "FILE");
|
|
11
|
-
const
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const tmp = path.join(this.shareData.AUTOMATOR_SCRATCH, path.basename(src));
|
|
12
|
+
let format = data.format;
|
|
13
|
+
if (!format) {
|
|
14
|
+
format = dst.split(".").pop();
|
|
15
|
+
}
|
|
16
|
+
format = format.toLowerCase();
|
|
17
|
+
if (format === "jpg") {
|
|
18
|
+
format = "jpeg";
|
|
19
|
+
}
|
|
20
|
+
const options = data.options;
|
|
21
|
+
await sharp(src)[format](options)
|
|
22
|
+
.toFile(tmp);
|
|
23
|
+
await move(tmp, path.dirname(dst), undefined, { quiet: true });
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-automator",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.15",
|
|
4
4
|
"description": "Execute automation with yaml configuration(compatible with json)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"persist-path": "^1.0.2",
|
|
53
53
|
"request": "^2.88.2",
|
|
54
54
|
"request-progress": "^3.0.0",
|
|
55
|
+
"sharp": "^0.34.3",
|
|
55
56
|
"spreadsheet-column": "^1.1.1",
|
|
56
57
|
"strip-json-comments": "^3.1.1",
|
|
57
58
|
"temp": "^0.9.4",
|
package/utils/file_tool.js
CHANGED
|
@@ -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
|
|
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",
|
|
@@ -322,9 +322,9 @@ async function copy(src, dst, base, options) {
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
|
|
326
|
-
info("");
|
|
327
|
-
whisper(`复制完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
325
|
+
|
|
326
|
+
!options.quiet && info("");
|
|
327
|
+
!options.quiet && whisper(`复制完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
async function move(src, dst, base, options) {
|
|
@@ -340,8 +340,8 @@ async function move(src, dst, base, options) {
|
|
|
340
340
|
overwrite: true
|
|
341
341
|
}, options);
|
|
342
342
|
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);
|
|
343
|
+
!options.quiet && info("");
|
|
344
|
+
!options.quiet && whisper(`移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
|
|
345
345
|
let actual_files = [];
|
|
346
346
|
let dir_num = 0;
|
|
347
347
|
for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
|
|
@@ -351,7 +351,7 @@ async function move(src, dst, base, options) {
|
|
|
351
351
|
++dir_num;
|
|
352
352
|
continue;
|
|
353
353
|
}
|
|
354
|
-
display_tool.progress(srcIndex + 1, srcs.length, {
|
|
354
|
+
!options.quiet && display_tool.progress(srcIndex + 1, srcs.length, {
|
|
355
355
|
desc: `Move ${show_src}`,
|
|
356
356
|
depth: 0,
|
|
357
357
|
color: "cyan",
|
|
@@ -397,9 +397,9 @@ async function move(src, dst, base, options) {
|
|
|
397
397
|
// 再删除
|
|
398
398
|
fs.unlinkSync(src);
|
|
399
399
|
}
|
|
400
|
-
|
|
401
|
-
info("");
|
|
402
|
-
whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
400
|
+
|
|
401
|
+
!options.quiet && info("");
|
|
402
|
+
!options.quiet && whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
async function move_local(src, dst, base, options) {
|
|
@@ -415,8 +415,8 @@ async function move_local(src, dst, base, options) {
|
|
|
415
415
|
overwrite: true
|
|
416
416
|
}, options);
|
|
417
417
|
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);
|
|
418
|
+
!options.quiet && info("");
|
|
419
|
+
!options.quiet && whisper(`移动 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} ${options.overwrite ? "[覆盖现有文件]" : "[不覆盖现有文件]"} 到 ${dsts} options: ${JSON.stringify(options)}`, undefined, true);
|
|
420
420
|
let actual_files = [];
|
|
421
421
|
let dir_num = 0;
|
|
422
422
|
for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
|
|
@@ -425,7 +425,7 @@ async function move_local(src, dst, base, options) {
|
|
|
425
425
|
if (fs.lstatSync(src).isDirectory()) {
|
|
426
426
|
++dir_num;
|
|
427
427
|
}
|
|
428
|
-
display_tool.progress(srcIndex + 1, srcs.length, {
|
|
428
|
+
!options.quiet && display_tool.progress(srcIndex + 1, srcs.length, {
|
|
429
429
|
desc: `Rename ${show_src}`,
|
|
430
430
|
depth: 0,
|
|
431
431
|
color: "cyan",
|
|
@@ -469,17 +469,17 @@ async function move_local(src, dst, base, options) {
|
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
|
|
473
|
-
info("");
|
|
474
|
-
whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
472
|
+
|
|
473
|
+
!options.quiet && info("");
|
|
474
|
+
!options.quiet && whisper(`移动完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
async function remove(src, options) {
|
|
478
478
|
srcs = get_file_list(src);
|
|
479
479
|
options = Object.assign({ recursive: true }, options);
|
|
480
480
|
let filesize = get_files_size(srcs);
|
|
481
|
-
info("");
|
|
482
|
-
whisper(`删除 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} options: ${JSON.stringify(options)}`, undefined, true);
|
|
481
|
+
!options.quiet && info("");
|
|
482
|
+
!options.quiet && whisper(`删除 ${srcs[0]} 等 ${srcs.length} 个文件(夹) ${format_bytes(filesize)} options: ${JSON.stringify(options)}`, undefined, true);
|
|
483
483
|
let actual_files = [];
|
|
484
484
|
let dir_num = 0;
|
|
485
485
|
for (let srcIndex = 0; srcIndex < srcs.length; srcIndex++) {
|
|
@@ -507,9 +507,9 @@ async function remove(src, options) {
|
|
|
507
507
|
warn(err);
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
-
|
|
511
|
-
info("");
|
|
512
|
-
whisper(`删除完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
510
|
+
|
|
511
|
+
!options.quiet && info("");
|
|
512
|
+
!options.quiet && whisper(`删除完成 (文件: ${actual_files.length}, 目录: ${dir_num}, 总计: ${srcs.length})`, undefined, true);
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
module.exports = {
|