node-automator 1.4.30 → 1.4.31
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/mgr.js +2 -0
- package/commands/watch.js +49 -0
- package/package.json +1 -1
package/commands/mgr.js
CHANGED
|
@@ -138,6 +138,7 @@ const { ZipFolderCommand } = require("./zip_folder");
|
|
|
138
138
|
const { EncryptCommand } = require('./encrypt');
|
|
139
139
|
const { DecryptCommand } = require('./decrypt');
|
|
140
140
|
const { TinifyCommand } = require('./tinify');
|
|
141
|
+
const { WatchCommand } = require('./watch');
|
|
141
142
|
|
|
142
143
|
const globalData = {
|
|
143
144
|
executed_cfg: [], // 执行过的配置文件
|
|
@@ -527,6 +528,7 @@ function init() {
|
|
|
527
528
|
register("encrypt", EncryptCommand, false);
|
|
528
529
|
register("decrypt", DecryptCommand, false);
|
|
529
530
|
register("tinify", TinifyCommand, false);
|
|
531
|
+
register("watch", WatchCommand, false);
|
|
530
532
|
}
|
|
531
533
|
|
|
532
534
|
module.exports = {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const { watch } = require('node:fs');
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
const { get_full_path } = require('./share_data');
|
|
4
|
+
const { throttle } = require('../utils/func_tool');
|
|
5
|
+
|
|
6
|
+
class WatchCommand extends BaseCommand {
|
|
7
|
+
async execute() {
|
|
8
|
+
const data = this.selfData;
|
|
9
|
+
const src = get_full_path(data.src);
|
|
10
|
+
const throttleDelay = data.throttleDelay;
|
|
11
|
+
const options = {
|
|
12
|
+
recursive: true,
|
|
13
|
+
...data.options,
|
|
14
|
+
};
|
|
15
|
+
let Handler = async () => {
|
|
16
|
+
let commandCfgs = data.commands;
|
|
17
|
+
// 特殊处理字符的情况
|
|
18
|
+
if (typeof commandCfgs === "string") {
|
|
19
|
+
commandCfgs = this.formatData(commandCfgs);
|
|
20
|
+
}
|
|
21
|
+
// 默认从循环开始执行,增加深度
|
|
22
|
+
await this.exec(commandCfgs, this.depth + 1);
|
|
23
|
+
}
|
|
24
|
+
if (throttleDelay != undefined) {
|
|
25
|
+
Handler = throttle(Handler, throttleDelay);
|
|
26
|
+
}
|
|
27
|
+
watch(
|
|
28
|
+
src,
|
|
29
|
+
options,
|
|
30
|
+
(eventType, filename) => {
|
|
31
|
+
this.shareData.WatchPayload = {
|
|
32
|
+
eventType,
|
|
33
|
+
filename,
|
|
34
|
+
};
|
|
35
|
+
Handler();
|
|
36
|
+
},
|
|
37
|
+
).on("error", (err) => {
|
|
38
|
+
error(`Watch error: ${err}`);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getRequiredParams() {
|
|
43
|
+
return ["src", "commands"];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
WatchCommand,
|
|
49
|
+
};
|