node-automator 1.4.19 → 1.4.21
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/merge_file.js +25 -0
- package/commands/mgr.js +4 -0
- package/commands/split_file.js +39 -0
- package/package.json +2 -1
- package/utils/transform_tool.js +24 -7
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { get_file_list, get_full_path } = require('../utils/file_tool');
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class MergeFileCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
const splitFile = require('split-file');
|
|
7
|
+
let { src, dst } = this.selfData;
|
|
8
|
+
src = get_file_list(src);
|
|
9
|
+
dst = get_full_path(dst);
|
|
10
|
+
const names = await new Promise((resolve, reject) => {
|
|
11
|
+
splitFile.mergeFiles(src, dst)
|
|
12
|
+
.then((names) => {
|
|
13
|
+
resolve(names);
|
|
14
|
+
})
|
|
15
|
+
.catch((err) => {
|
|
16
|
+
reject(err);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return names;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
MergeFileCommand,
|
|
25
|
+
};
|
package/commands/mgr.js
CHANGED
|
@@ -120,6 +120,8 @@ const { BackupCommand } = require('./backup');
|
|
|
120
120
|
const { CompressCommand } = require('./compress');
|
|
121
121
|
const { Word2txtCommand } = require('./word2txt');
|
|
122
122
|
const { ObfuscateCommand } = require('./obfuscate');
|
|
123
|
+
const { SplitFileCommand } = require('./split_file');
|
|
124
|
+
const { MergeFileCommand } = require('./merge_file');
|
|
123
125
|
|
|
124
126
|
const globalData = {
|
|
125
127
|
"executed_cfg": [], // 执行过的配置文件
|
|
@@ -483,6 +485,8 @@ function init() {
|
|
|
483
485
|
register("compress", CompressCommand, false);
|
|
484
486
|
register("word2txt", Word2txtCommand, false);
|
|
485
487
|
register("obfuscate", ObfuscateCommand, false);
|
|
488
|
+
register("split_file", SplitFileCommand, false);
|
|
489
|
+
register("merge_file", MergeFileCommand, false);
|
|
486
490
|
}
|
|
487
491
|
|
|
488
492
|
module.exports = {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { get_fst_file, get_full_path } = require('../utils/file_tool');
|
|
2
|
+
const { getByteSize } = require('../utils/transform_tool');
|
|
3
|
+
const { BaseCommand } = require("./base");
|
|
4
|
+
|
|
5
|
+
class SplitFileCommand extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
const splitFile = require('split-file');
|
|
8
|
+
let { src, maxSize, numParts, dst } = this.selfData;
|
|
9
|
+
src = get_fst_file(src);
|
|
10
|
+
dst = get_full_path(dst, "FOLDER");
|
|
11
|
+
const names = await new Promise((resolve, reject) => {
|
|
12
|
+
if (maxSize) {
|
|
13
|
+
maxSize = getByteSize(maxSize);
|
|
14
|
+
splitFile.splitFileBySize(src, maxSize, dst)
|
|
15
|
+
.then((names) => {
|
|
16
|
+
resolve(names);
|
|
17
|
+
})
|
|
18
|
+
.catch((err) => {
|
|
19
|
+
reject(err);
|
|
20
|
+
});
|
|
21
|
+
} else if (numParts) {
|
|
22
|
+
splitFile.splitFile(src, numParts, dst)
|
|
23
|
+
.then((names) => {
|
|
24
|
+
resolve(names);
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
reject(err);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
reject("maxSize or numParts is required");
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return names;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
SplitFileCommand,
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-automator",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.21",
|
|
4
4
|
"description": "Execute automation with yaml configuration(compatible with json)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"request": "^2.88.2",
|
|
54
54
|
"request-progress": "^3.0.0",
|
|
55
55
|
"sharp": "^0.34.3",
|
|
56
|
+
"split-file": "^2.3.0",
|
|
56
57
|
"spreadsheet-column": "^1.1.1",
|
|
57
58
|
"strip-json-comments": "^3.1.1",
|
|
58
59
|
"temp": "^0.9.4",
|
package/utils/transform_tool.js
CHANGED
|
@@ -32,8 +32,8 @@ function removeDuplicate(value, options) {
|
|
|
32
32
|
value = value.map(v => {
|
|
33
33
|
let raw = typeof v === "string" ? v : JSON.stringify(v);
|
|
34
34
|
let repeat = seen[duplicate_map[raw]] || 0;
|
|
35
|
-
let prefix = options.remove_duplicate_prefix && format(options.remove_duplicate_prefix, {repeat}) || "";
|
|
36
|
-
let suffix = options.remove_duplicate_suffix && format(options.remove_duplicate_suffix, {repeat}) || "";
|
|
35
|
+
let prefix = options.remove_duplicate_prefix && format(options.remove_duplicate_prefix, { repeat }) || "";
|
|
36
|
+
let suffix = options.remove_duplicate_suffix && format(options.remove_duplicate_suffix, { repeat }) || "";
|
|
37
37
|
return prefix + v + suffix;
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -274,8 +274,8 @@ function formatByValues(values, fmt, prefix) {
|
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
const dayInWeeks = [
|
|
278
|
-
const fullDayInWeeks = [
|
|
277
|
+
const dayInWeeks = ["日", "一", "二", "三", "四", "五", "六"];
|
|
278
|
+
const fullDayInWeeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
|
279
279
|
/**
|
|
280
280
|
* 格式化日期
|
|
281
281
|
* @param {Date} date
|
|
@@ -417,7 +417,7 @@ function alignNumber(from, to, options) {
|
|
|
417
417
|
* @param { {alignment: Alignment, paddingChar: string} } options
|
|
418
418
|
*/
|
|
419
419
|
function alignStr(from, toNum, options) {
|
|
420
|
-
options = Object.assign({alignment: Alignment.RIGHT, paddingChar: " "}, options);
|
|
420
|
+
options = Object.assign({ alignment: Alignment.RIGHT, paddingChar: " " }, options);
|
|
421
421
|
let prefixNum = 0;
|
|
422
422
|
let suffixNum = 0;
|
|
423
423
|
from = from.toString().substr(0, toNum);
|
|
@@ -436,7 +436,7 @@ function alignStr(from, toNum, options) {
|
|
|
436
436
|
suffixNum = Math.floor(totalOffset / 2);
|
|
437
437
|
break;
|
|
438
438
|
}
|
|
439
|
-
case Alignment.RIGHT:
|
|
439
|
+
case Alignment.RIGHT:
|
|
440
440
|
default: {
|
|
441
441
|
prefixNum = totalOffset;
|
|
442
442
|
break;
|
|
@@ -482,11 +482,27 @@ function formatByteSize(bytes) {
|
|
|
482
482
|
return (bytes / KB).toFixed(2) + " KB";
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
+
function getByteSize(formatedStr) {
|
|
486
|
+
formatedStr = formatedStr.toString().trim();
|
|
487
|
+
let bytes = 0;
|
|
488
|
+
if (formatedStr.match(/gb?$/i)) {
|
|
489
|
+
bytes = Number(formatedStr.replace(/gb?$/i, "")) * GB;
|
|
490
|
+
} else if (formatedStr.match(/mb?$/i)) {
|
|
491
|
+
bytes = Number(formatedStr.replace(/mb?$/i, "")) * MB;
|
|
492
|
+
} else if (formatedStr.match(/kb?$/i)) {
|
|
493
|
+
bytes = Number(formatedStr.replace(/kb?$/i, "")) * KB;
|
|
494
|
+
} else {
|
|
495
|
+
bytes = Number(formatedStr.replace(/b?$/i, ""));
|
|
496
|
+
}
|
|
497
|
+
return bytes;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
|
|
485
501
|
/**
|
|
486
502
|
*
|
|
487
503
|
* @param {string} key
|
|
488
504
|
*/
|
|
489
|
-
|
|
505
|
+
function getDataByKeySimple(key, from) {
|
|
490
506
|
const subkeys = key.split(".");
|
|
491
507
|
let val = from;
|
|
492
508
|
for (const subkey of subkeys) {
|
|
@@ -517,4 +533,5 @@ module.exports = {
|
|
|
517
533
|
escapeString,
|
|
518
534
|
removeDuplicate,
|
|
519
535
|
removeDuplicateObject,
|
|
536
|
+
getByteSize,
|
|
520
537
|
};
|