node-automator 1.0.0

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.
Files changed (143) hide show
  1. package/LICENSE +15 -0
  2. package/assets/alert.png +0 -0
  3. package/assets/error.png +0 -0
  4. package/assets/success.png +0 -0
  5. package/commands/abort.js +11 -0
  6. package/commands/alert.js +19 -0
  7. package/commands/assemble.js +56 -0
  8. package/commands/assert.js +18 -0
  9. package/commands/base.js +363 -0
  10. package/commands/break.js +11 -0
  11. package/commands/change_filter.js +34 -0
  12. package/commands/cheerio.js +15 -0
  13. package/commands/clear_screen.js +14 -0
  14. package/commands/commit.js +31 -0
  15. package/commands/compare.js +23 -0
  16. package/commands/confirm.js +16 -0
  17. package/commands/continue.js +11 -0
  18. package/commands/copy.js +14 -0
  19. package/commands/cursor_up.js +12 -0
  20. package/commands/date.js +25 -0
  21. package/commands/debugger.js +11 -0
  22. package/commands/dingtalk.js +110 -0
  23. package/commands/disassemble.js +36 -0
  24. package/commands/divination.js +15 -0
  25. package/commands/download.js +12 -0
  26. package/commands/edit.js +83 -0
  27. package/commands/edit_excel.js +57 -0
  28. package/commands/env_optional.js +57 -0
  29. package/commands/eval.js +27 -0
  30. package/commands/exec_from_file.js +31 -0
  31. package/commands/export_diff_head.js +31 -0
  32. package/commands/file_info.js +41 -0
  33. package/commands/file_size.js +12 -0
  34. package/commands/files.js +14 -0
  35. package/commands/first_exist.js +18 -0
  36. package/commands/flatten.js +18 -0
  37. package/commands/ftp.js +161 -0
  38. package/commands/git_commit.js +31 -0
  39. package/commands/git_export_diff_head.js +13 -0
  40. package/commands/git_is_dirty.js +13 -0
  41. package/commands/hash.js +21 -0
  42. package/commands/http_request.js +12 -0
  43. package/commands/image_crop.js +19 -0
  44. package/commands/input.js +37 -0
  45. package/commands/interval.js +60 -0
  46. package/commands/is_dirty.js +31 -0
  47. package/commands/jwt_decode.js +22 -0
  48. package/commands/list2dict.js +32 -0
  49. package/commands/log.js +72 -0
  50. package/commands/loop.js +115 -0
  51. package/commands/loop_forever.js +66 -0
  52. package/commands/merge_files.js +39 -0
  53. package/commands/mgr.js +476 -0
  54. package/commands/modify.js +44 -0
  55. package/commands/move.js +14 -0
  56. package/commands/move_local.js +14 -0
  57. package/commands/multi_select.js +16 -0
  58. package/commands/mysql_connect.js +29 -0
  59. package/commands/mysql_end.js +13 -0
  60. package/commands/mysql_query.js +19 -0
  61. package/commands/notify.js +13 -0
  62. package/commands/open.js +30 -0
  63. package/commands/parse.js +18 -0
  64. package/commands/pause.js +15 -0
  65. package/commands/print.js +47 -0
  66. package/commands/read_cache.js +12 -0
  67. package/commands/read_cfg.js +13 -0
  68. package/commands/read_clipboard.js +19 -0
  69. package/commands/read_excel.js +17 -0
  70. package/commands/read_only_excel.js +40 -0
  71. package/commands/read_plain.js +14 -0
  72. package/commands/remove.js +14 -0
  73. package/commands/retrieve.js +17 -0
  74. package/commands/reveal.js +33 -0
  75. package/commands/revision_info.js +31 -0
  76. package/commands/schedule.js +80 -0
  77. package/commands/select.js +17 -0
  78. package/commands/send_email.js +25 -0
  79. package/commands/share_data.js +745 -0
  80. package/commands/shell.js +13 -0
  81. package/commands/sleep.js +17 -0
  82. package/commands/store.js +13 -0
  83. package/commands/store_optional.js +33 -0
  84. package/commands/stream.js +16 -0
  85. package/commands/stringify.js +24 -0
  86. package/commands/svn_add.js +26 -0
  87. package/commands/svn_commit.js +49 -0
  88. package/commands/svn_export_diff_head.js +13 -0
  89. package/commands/svn_is_dirty.js +13 -0
  90. package/commands/svn_update.js +27 -0
  91. package/commands/switch.js +18 -0
  92. package/commands/temp.js +12 -0
  93. package/commands/tencent_cos.js +323 -0
  94. package/commands/test.js +14 -0
  95. package/commands/title.js +18 -0
  96. package/commands/tmpdir.js +21 -0
  97. package/commands/translate.js +58 -0
  98. package/commands/traversal.js +38 -0
  99. package/commands/truncate.js +31 -0
  100. package/commands/truncate_all.js +62 -0
  101. package/commands/ts_sort.js +18 -0
  102. package/commands/unzip.js +50 -0
  103. package/commands/updating_revision.js +28 -0
  104. package/commands/valid_required.js +31 -0
  105. package/commands/void.js +10 -0
  106. package/commands/watch_mail.js +94 -0
  107. package/commands/web_socket.js +233 -0
  108. package/commands/which.js +60 -0
  109. package/commands/write_cache.js +16 -0
  110. package/commands/write_cfg.js +18 -0
  111. package/commands/write_clipboard.js +23 -0
  112. package/commands/write_excel.js +17 -0
  113. package/commands/write_plain.js +18 -0
  114. package/commands/zip.js +78 -0
  115. package/commands/zip_data.js +64 -0
  116. package/examples/print_env.yml +3 -0
  117. package/index.js +109 -0
  118. package/package.json +63 -0
  119. package/scratch/.gitkeep +0 -0
  120. package/utils/alert_tool.js +133 -0
  121. package/utils/base64_tool.js +13 -0
  122. package/utils/cache/local_cache.js +79 -0
  123. package/utils/cache/raw_cache.js +47 -0
  124. package/utils/cache/simple_local_cache.js +33 -0
  125. package/utils/cache/simple_sqlite_cache.js +43 -0
  126. package/utils/cache/simple_svn_cache.js +49 -0
  127. package/utils/cache/svn_cache.js +40 -0
  128. package/utils/cache_tool.js +53 -0
  129. package/utils/display_tool.js +85 -0
  130. package/utils/divination_util.js +555 -0
  131. package/utils/file_tool.js +529 -0
  132. package/utils/hash_tool.js +8 -0
  133. package/utils/interaction_tool.js +228 -0
  134. package/utils/log_tool.js +190 -0
  135. package/utils/parse_directive.js +194 -0
  136. package/utils/parse_tool.js +236 -0
  137. package/utils/request_tool.js +156 -0
  138. package/utils/scm_tool.js +108 -0
  139. package/utils/selection_tool.js +593 -0
  140. package/utils/shell_tool.js +162 -0
  141. package/utils/svn_diff/diff_file.js +44 -0
  142. package/utils/svn_diff/diff_parser.js +55 -0
  143. package/utils/transform_tool.js +520 -0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2023, TsubasaYeung
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Binary file
Binary file
Binary file
@@ -0,0 +1,11 @@
1
+ const { BaseCommand } = require("./base");
2
+
3
+ class AbortCommand extends BaseCommand {
4
+ async execute() {
5
+ throw (this.selfData && this.selfData.prompt) || "任务中止";
6
+ }
7
+ }
8
+
9
+ module.exports = {
10
+ AbortCommand,
11
+ };
@@ -0,0 +1,19 @@
1
+ const { showAlert } = require("../utils/alert_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class AlertCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ await showAlert(data.type, data.msg, data.title);
8
+ }
9
+
10
+ getRequiredParams() {
11
+ return [
12
+ "msg",
13
+ ];
14
+ }
15
+ }
16
+
17
+ module.exports = {
18
+ AlertCommand,
19
+ };
@@ -0,0 +1,56 @@
1
+ const {
2
+ BaseCommand
3
+ } = require("./base");
4
+
5
+ /**
6
+ * 把数组(content)中的元素使用指定符号(delimiter)分割,组合得到指定属性名(props)的对象数组(ret)
7
+ * @example
8
+ * content = ["Key1,Key2,Key3", "Value1,Value2,Value3"];
9
+ * delimiter = ",";
10
+ * props = "k,v"
11
+ * // 得到结果
12
+ * ret = [
13
+ * {k: "Key1", v: "Value1"},
14
+ * {k: "Key2", v: "Value2"},
15
+ * {k: "Key3", v: "Value3"},
16
+ * ]
17
+ */
18
+ class AssembleCommand extends BaseCommand {
19
+ async execute() {
20
+ let delimiter = this.selfData.delimiter;
21
+ if (delimiter) {
22
+ delimiter = new RegExp(delimiter);
23
+ }
24
+ let props = this.selfData.props;
25
+ if (delimiter && typeof props === "string") {
26
+ props = props.split(delimiter);
27
+ }
28
+ let arrays = this.content.map(v => delimiter && typeof v === "string" ? v.split(delimiter) : v);
29
+ let num_item = arrays.reduce((prev, curr) => {
30
+ return Math.max(prev, curr.length);
31
+ }, 0);
32
+ let ret = [];
33
+ for (let idx_item = 0; idx_item < num_item; ++idx_item) {
34
+ let tmp = {};
35
+ props.forEach((v, prop_idx) => {
36
+ tmp[v] = arrays[prop_idx][idx_item];
37
+ });
38
+ ret.push(tmp);
39
+ }
40
+ return ret;
41
+ }
42
+
43
+ getRequiredParams() {
44
+ return [
45
+ 'props'
46
+ ];
47
+ }
48
+
49
+ getRequireContent() {
50
+ return true;
51
+ }
52
+ }
53
+
54
+ module.exports = {
55
+ AssembleCommand,
56
+ };
@@ -0,0 +1,18 @@
1
+ const { toArray } = require('../utils/transform_tool');
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class AssertCommand extends BaseCommand {
5
+ async execute() {
6
+ let missingKeys = [];
7
+ toArray(this.selfData.key).forEach((key) => {
8
+ if (!this.getDataByKey(key)) missingKeys.push(key);
9
+ });
10
+ if (missingKeys.length) {
11
+ throw `${missingKeys.map(v => `"${v}"`).join(",")} 参数不存在(${missingKeys.length})`;
12
+ }
13
+ }
14
+ }
15
+
16
+ module.exports = {
17
+ AssertCommand,
18
+ };
@@ -0,0 +1,363 @@
1
+ const keypress = require("keypress");
2
+ const { warn, getPrint, stdout, setLastError } = require("../utils/log_tool");
3
+ const { convert, flatten, removeDuplicate } = require("../utils/transform_tool");
4
+ const { parse, get_full_path, write_with_type } = require("../utils/file_tool");
5
+
6
+ const { eval_code } = require("./share_data");
7
+
8
+
9
+ keypress(process.stdin);
10
+
11
+ const { shareData, getDataByKey } = require("./share_data");
12
+
13
+ const PROCESS_STATE = {
14
+ NONE: 0,
15
+ CONTINUE: 1,
16
+ BREAK: 2,
17
+ };
18
+
19
+ class BaseCommand {
20
+ constructor(type, globalData, execSingle, exec) {
21
+ this.type = type;
22
+ this.selfData = null;
23
+ this.shareData = shareData;
24
+ this.globalData = globalData;
25
+ this.execSingle = execSingle;
26
+ this.exec = exec;
27
+ }
28
+
29
+ async willExecute() {
30
+ return true;
31
+ }
32
+
33
+ async didExecute() {
34
+
35
+ }
36
+
37
+ async checkValid(commandCfg) {
38
+ let conditionCode = commandCfg.when;
39
+ let when_tip = commandCfg.when_tip;
40
+ let cfgData = commandCfg.data;
41
+ if (conditionCode) {
42
+ let willExec = eval_code(conditionCode);
43
+ if (!willExec) {
44
+ when_tip && warn(`[${when_tip}]`);
45
+ return;
46
+ }
47
+ }
48
+ // 如果可选, 则要判断是否store_key是否已经有值
49
+ let if_false = commandCfg.if_false;
50
+ if (if_false) {
51
+ let checkKey = typeof if_false === "string" ? if_false : cfgData && cfgData.store_key;
52
+ if (checkKey && this.getDataByKey(checkKey)) {
53
+ // warn(`${checkKey} 不为空, 跳过执行`)
54
+ return;
55
+ }
56
+ }
57
+ let if_true = commandCfg.if_true;
58
+ if (if_true) {
59
+ let checkKey = typeof if_true === "string" ? if_true : cfgData && cfgData.store_key;
60
+ if (checkKey && !this.getDataByKey(checkKey)) {
61
+ // warn(`${checkKey} 为空, 跳过执行`)
62
+ return;
63
+ }
64
+ }
65
+ let optional = commandCfg.optional;
66
+ if (optional) {
67
+ let options = ["Yes", "No"];
68
+ warn(`\n是否执行 ${commandCfg.title || commandCfg.type}?`);
69
+ await this.forward("select", { content: options, store_key: "$checkValidOptional"});
70
+ if (options.indexOf(shareData.$checkValidOptional) == 1) {
71
+ return;
72
+ }
73
+ }
74
+ return true;
75
+ }
76
+
77
+ async handle(commandCfg, content, depth = 0) {
78
+ /** @type {{type: string, title?: string, when:?: string, data: any, ignore_error: boolean, data_print: boolean, data_confirm: boolean}} */
79
+ this.selfCfg = commandCfg;
80
+ this.selfData = commandCfg.data;
81
+ /** @type {string} */
82
+ this.content = content;
83
+ this.depth = depth || 0;
84
+
85
+ // 判断参数是否存在
86
+ let requiredParams = this.getRequiredParams();
87
+ let failed = false;
88
+ for (let index = 0; index < requiredParams.length; index++) {
89
+ const key = requiredParams[index];
90
+ let ret = getDataByKey(key, this.selfData);
91
+ if (ret == null) {
92
+ failed = true;
93
+ warn(`\n缺少 ${key}`);
94
+ }
95
+ }
96
+ if (failed) {
97
+ throw (`参数校验失败,请检查所有缺少的参数 ${getPrint(this.selfCfg, true)}`);
98
+ }
99
+
100
+ let ret;
101
+ let data = this.selfData;
102
+ let willExec = await this.willExecute();
103
+ if (!willExec) {
104
+ warn("\n不执行");
105
+ return;
106
+ }
107
+ // 打印完整 data
108
+ if (this.selfCfg.data_print) {
109
+ await this.forward("print", { content: data, mode: "content", level: 3 });
110
+ }
111
+ // 确认完整 data
112
+ if (this.selfCfg.data_confirm) {
113
+ await this.forward("confirm", { content: data, mode: "content" });
114
+ }
115
+ if (data) {
116
+ // 内容打印
117
+ if (data.content_print) {
118
+ await this.forward("print", { content: this.content, mode: "content", level: 3 });
119
+ }
120
+ // 内容确认
121
+ if (data.content_confirm) {
122
+ await this.forward("confirm", { content: this.content, mode: "content" });
123
+ }
124
+ }
125
+
126
+ ret = await this.execute();
127
+ await this.didExecute();
128
+ if (data) {
129
+ ////// 数据预处理 BEG
130
+ // 对结果进行语法解析
131
+ if (data.parse_type) {
132
+ try {
133
+ ret = await parse(ret, data.parse_type, data.parse_options);
134
+ } catch (err) {
135
+ setLastError(`parse ${ret} ${data.parse_type} error ${err.message}`);
136
+ ret = null;
137
+ }
138
+ }
139
+ // 类型转换
140
+ if (data && data.value_type) {
141
+ ret = convert(ret, data.value_type);
142
+ }
143
+ // 数组处理
144
+ if (ret instanceof Array) {
145
+ // 扁平处理
146
+ if (data.flatten) {
147
+ ret = flatten(ret);
148
+ }
149
+ // 数据除重
150
+ if (data.remove_duplicate) {
151
+ ret = removeDuplicate(ret, data);
152
+ }
153
+ // 数据排序
154
+ if (data.store_sort) {
155
+ ret.sort();
156
+ }
157
+ }
158
+ // 字符串类型处理
159
+ if (typeof ret === "string") {
160
+ if (data.store_trim) {
161
+ ret = ret.trim();
162
+ }
163
+ }
164
+ ////// 数据预处理 END
165
+
166
+ // 默认值
167
+ if (!ret && data.default_value != null) {
168
+ ret = data.default_value;
169
+ }
170
+ // 保存到共享数据
171
+ if (data.store_key) {
172
+ let keys = data.store_key instanceof Array ? data.store_key : data.store_key.split(".");
173
+ let dst = this.shareData;
174
+ let len = keys.length;
175
+ let key;
176
+ let store_key_type = data.store_key_type;
177
+ for (let i = 0; i < len - 1; i++) {
178
+ key = keys[i];
179
+ // 键转换
180
+ switch (store_key_type && store_key_type[i]) {
181
+ case "eval":
182
+ key = eval_code(key);
183
+ break;
184
+ }
185
+ if (!dst[key]) {
186
+ dst[key] = {};
187
+ }
188
+ dst = dst[key];
189
+ }
190
+ key = keys[len - 1];
191
+ let store_mode = data.store_mode || "default";
192
+ switch (store_mode) {
193
+ case "push": {
194
+ if (!dst[key]) {
195
+ dst[key] = [];
196
+ }
197
+ dst = dst[key];
198
+ dst.push(ret);
199
+ break;
200
+ }
201
+ case "unshift": {
202
+ if (!dst[key]) {
203
+ dst[key] = [];
204
+ }
205
+ dst = dst[key];
206
+ dst.unshift(ret);
207
+ break;
208
+ }
209
+ case "append": {
210
+ if (dst[key] == null) {
211
+ dst[key] = "";
212
+ }
213
+ dst[key] += ret;
214
+ break;
215
+ }
216
+ case "merge": {
217
+ dst[key] = Object.assign({}, dst[key], ret);
218
+ break;
219
+ }
220
+ case "concat": {
221
+ if (!dst[key]) {
222
+ dst[key] = [];
223
+ }
224
+ dst[key] = dst[key].concat(ret);
225
+ break;
226
+ }
227
+ case "default": {
228
+ dst[key] = ret;
229
+ break;
230
+ }
231
+ default: {
232
+ throw (`未实现的store_mode ${store_mode}`);
233
+ break;
234
+ }
235
+ }
236
+ }
237
+ // 保存到store_dst目标
238
+ if (data.store_dst) {
239
+ let store_dst = get_full_path(data.store_dst);
240
+ let store_dst_type = data.store_dst_type;
241
+ await write_with_type(ret, store_dst, store_dst_type);
242
+ if (data.reveal_dst) {
243
+ await this.forward("reveal", { src: store_dst });
244
+ }
245
+ if (data.open_dst) {
246
+ await this.forward("open", { src: store_dst });
247
+ }
248
+ }
249
+ // if (data.key && !data.store_key && !data.store_dst && ret != undefined) {
250
+ // warn(`返回值未存储 ${getPrint(this.selfCfg, true)}`);
251
+ // }
252
+ // 数据映射
253
+ if (data.mapping) {
254
+ if (typeof data.mapping === "boolean") {
255
+ for (let k in ret) {
256
+ this.shareData[k] = ret[k];
257
+ }
258
+ } else {
259
+ for (let i = 0; i < data.mapping.length; i++) {
260
+ const k = data.mapping[i];
261
+ this.shareData[k] = ret[i];
262
+ }
263
+ }
264
+ }
265
+ // 参数打印
266
+ if (data.store_print) {
267
+ await this.forward("print", { content: ret, mode: "content", level: data.store_print_level ?? 3 });
268
+ }
269
+ // 参数确认
270
+ if (data.store_confirm) {
271
+ await this.forward("confirm", { content: ret, mode: "content" });
272
+ }
273
+ // 参数写入标准输出stdout,需要配合参数 --LOG_LEVEL 99
274
+ if (data.store_stdout) {
275
+ stdout(ret);
276
+ }
277
+ // 写入剪切板
278
+ if (data.store_clipboard) {
279
+ await this.forward("write_clipboard", { content: ret });
280
+ }
281
+ // 数据校验
282
+ if (data.store_validator) {
283
+ let [ok, errmsg] = eval_code(data.store_validator)(ret);
284
+ if (!ok) {
285
+ setLastError(errmsg || "校验失败");
286
+ }
287
+ }
288
+ }
289
+ // 写日志
290
+ if (this.selfCfg.log != undefined) {
291
+ await this.forward("log", { content: this.selfCfg.log });
292
+ }
293
+ if (this.selfCfg.required && ret == null) {
294
+ throw (`执行结果不能为空`);
295
+ }
296
+ return ret;
297
+ }
298
+
299
+ async execute() {
300
+
301
+ }
302
+
303
+ /**
304
+ * 转交给另外一个类型的命令处理
305
+ * @param {*} type
306
+ */
307
+ async forward(type, data = this.selfData) {
308
+ return await this.execSingle({
309
+ type: type,
310
+ // 传递 ignore_error
311
+ ignore_error: this.selfCfg.ignore_error,
312
+ data: data,
313
+ }, this.depth);
314
+ }
315
+
316
+ /**
317
+ * 是否需要传入content
318
+ */
319
+ getRequireContent() {
320
+ return false;
321
+ }
322
+
323
+ getDataByKey() {
324
+ return getDataByKey.apply(this, arguments);
325
+ }
326
+
327
+ /**
328
+ * 需要提供的参数
329
+ */
330
+ getRequiredParams() {
331
+ return [
332
+
333
+ ];
334
+ }
335
+
336
+ /**
337
+ * 设置执行状态
338
+ * @param {*} state
339
+ */
340
+ setProcessState(state) {
341
+ this.globalData.process_state = state;
342
+ }
343
+
344
+ /**
345
+ * 重置执行状态
346
+ */
347
+ resetProcessState() {
348
+ this.globalData.process_state = PROCESS_STATE.NONE;
349
+ }
350
+
351
+ /**
352
+ * 是否为全自动
353
+ * @returns
354
+ */
355
+ isFullAutomatic() {
356
+ return this.shareData.FULL_AUTOMATIC;
357
+ }
358
+ }
359
+
360
+ module.exports = {
361
+ BaseCommand,
362
+ PROCESS_STATE,
363
+ };
@@ -0,0 +1,11 @@
1
+ const { BaseCommand, PROCESS_STATE } = require("./base");
2
+
3
+ class BreakCommand extends BaseCommand {
4
+ async execute() {
5
+ this.setProcessState(PROCESS_STATE.BREAK);
6
+ }
7
+ }
8
+
9
+ module.exports = {
10
+ BreakCommand,
11
+ };
@@ -0,0 +1,34 @@
1
+
2
+ const { setCache, getCache } = require("../utils/cache_tool");
3
+ const { BaseCommand } = require("./base");
4
+
5
+ class ChangeFilterCommand extends BaseCommand {
6
+ async execute() {
7
+ let key_name = this.selfData.key_name;
8
+ let status_name = this.selfData.status_name;
9
+ let default_status = this.selfData.default_status;
10
+ let cache_key = "[ChangeFilterCommand]:" + this.selfData.cache_key;
11
+ let cacheType = this.selfData.cache_type;
12
+ let cacheParam = this.selfData.cache_param;
13
+ let cached = await getCache(cache_key, cacheType, cacheParam) || {};
14
+ let ret = this.content.filter(v => {
15
+ let key = this.getDataByKey(key_name, v);
16
+ let status = this.getDataByKey(status_name, v);
17
+ let cached_status = cached[key];
18
+ cached[key] = status;
19
+ if (default_status != null && status != default_status) return true;
20
+ if (cached_status != null && cached_status != status) return true;
21
+ return false;
22
+ });
23
+ await setCache(cache_key, cached, cacheType, cacheParam);
24
+ return ret;
25
+ }
26
+
27
+ getRequireContent() {
28
+ return true;
29
+ }
30
+ }
31
+
32
+ module.exports = {
33
+ ChangeFilterCommand,
34
+ };
@@ -0,0 +1,15 @@
1
+ const { BaseCommand, PROCESS_STATE } = require("./base");
2
+
3
+ class CheerioCommand extends BaseCommand {
4
+ async execute() {
5
+ return require("cheerio").load(this.content)
6
+ }
7
+
8
+ getRequireContent() {
9
+ return true;
10
+ }
11
+ }
12
+
13
+ module.exports = {
14
+ CheerioCommand,
15
+ };
@@ -0,0 +1,14 @@
1
+ const { write } = require("../utils/log_tool");
2
+ const { BaseCommand } = require("./base");
3
+ const { clear_screen } = require("./share_data");
4
+
5
+ class ClearScreenCommand extends BaseCommand {
6
+ async execute() {
7
+ write(clear_screen + "\n");
8
+ write(`\x1B[${99}A`);
9
+ }
10
+ }
11
+
12
+ module.exports = {
13
+ ClearScreenCommand,
14
+ };
@@ -0,0 +1,31 @@
1
+ const { vital } = require("../utils/log_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class CommitCommand extends BaseCommand {
5
+ async execute() {
6
+ switch (this.selfData.type) {
7
+ case 'svn': {
8
+ return await this.forward('svn_commit');
9
+ break;
10
+ }
11
+ case 'git': {
12
+ return await this.forward('git_commit');
13
+ break;
14
+ }
15
+ default: {
16
+ throw (`不支持的类型 ${this.selfData.type}`);
17
+ break;
18
+ }
19
+ }
20
+ }
21
+
22
+ getRequiredParams() {
23
+ return [
24
+ "type",
25
+ ];
26
+ }
27
+ }
28
+
29
+ module.exports = {
30
+ CommitCommand,
31
+ };
@@ -0,0 +1,23 @@
1
+ const { BaseCommand } = require("./base");
2
+
3
+ class CompareCommand extends BaseCommand {
4
+ async execute() {
5
+ let lhs = this.selfData.lhs;
6
+ let rhs = this.selfData.rhs;
7
+ let ret = {};
8
+ if (!lhs) {
9
+ ret = rhs;
10
+ } else {
11
+ for (let key in rhs) {
12
+ if (rhs[key] !== lhs[key]) {
13
+ ret[key] = rhs[key];
14
+ }
15
+ }
16
+ }
17
+ return ret;
18
+ }
19
+ }
20
+
21
+ module.exports = {
22
+ CompareCommand,
23
+ };
@@ -0,0 +1,16 @@
1
+ const { pause } = require("../utils/interaction_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class ConfirmCommand extends BaseCommand {
5
+ async execute() {
6
+ await this.forward("print");
7
+ await this.forward("pause", {
8
+ prompt: this.selfData.prompt || "请确认以上参数",
9
+ countdown: this.selfData.countdown,
10
+ });
11
+ }
12
+ }
13
+
14
+ module.exports = {
15
+ ConfirmCommand,
16
+ };
@@ -0,0 +1,11 @@
1
+ const { BaseCommand, PROCESS_STATE } = require("./base");
2
+
3
+ class ContinueCommand extends BaseCommand {
4
+ async execute() {
5
+ this.setProcessState(PROCESS_STATE.CONTINUE);
6
+ }
7
+ }
8
+
9
+ module.exports = {
10
+ ContinueCommand,
11
+ };
@@ -0,0 +1,14 @@
1
+ const { copy } = require("../utils/file_tool");
2
+ const { log } = require("../utils/log_tool");
3
+ const { BaseCommand } = require("./base");
4
+
5
+ class CopyCommand extends BaseCommand {
6
+ async execute() {
7
+ let data = this.selfData;
8
+ await copy(data.src, data.dst, data.base, data.options);
9
+ }
10
+ }
11
+
12
+ module.exports = {
13
+ CopyCommand,
14
+ };
@@ -0,0 +1,12 @@
1
+ const { moveCursorLineUp } = require('../utils/interaction_tool');
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class CursorUpCommand extends BaseCommand {
5
+ async execute() {
6
+ moveCursorLineUp(this.selfData.line);
7
+ }
8
+ }
9
+
10
+ module.exports = {
11
+ CursorUpCommand,
12
+ };