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
@@ -0,0 +1,13 @@
1
+ const { exec_shell } = require('../utils/shell_tool');
2
+ const { BaseCommand } = require('./base');
3
+
4
+ class ShellCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ return await exec_shell(data);
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ ShellCommand,
13
+ };
@@ -0,0 +1,17 @@
1
+ const { BaseCommand } = require("./base");
2
+
3
+ class SleepCommand extends BaseCommand {
4
+ async execute() {
5
+ let data = this.selfData;
6
+ const timeout = data.timeout;
7
+ await new Promise(resolve => {
8
+ setTimeout(() => {
9
+ resolve();
10
+ }, timeout);
11
+ });
12
+ }
13
+ }
14
+
15
+ module.exports = {
16
+ SleepCommand,
17
+ };
@@ -0,0 +1,13 @@
1
+ const { BaseCommand } = require("./base");
2
+
3
+ class StoreCommand extends BaseCommand {
4
+ async execute() {
5
+ let data = this.selfData;
6
+ Object.assign(this.shareData, data);
7
+ return data;
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ StoreCommand,
13
+ };
@@ -0,0 +1,33 @@
1
+ const { number } = require('yargs');
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class StoreOptionalCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ for (let k in data) {
8
+ const presentVal = this.shareData[k];
9
+ if (presentVal == null) {
10
+ this.shareData[k] = data[k];
11
+ } else {
12
+ const expected = typeof data[k];
13
+ const present = typeof presentVal;
14
+ if (expected !== present) {
15
+ if (expected === "number") {
16
+ this.shareData[k] = parseFloat(presentVal);
17
+ } else if (expected === "boolean") {
18
+ if (presentVal && presentVal !== "false" && presentVal !== "0") {
19
+ this.shareData[k] = true;
20
+ } else {
21
+ this.shareData[k] = false;
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ return data;
28
+ }
29
+ }
30
+
31
+ module.exports = {
32
+ StoreOptionalCommand,
33
+ };
@@ -0,0 +1,16 @@
1
+ const { BaseCommand } = require("./base");
2
+ const fs = require("fs");
3
+ const { get_fst_file, get_full_path } = require("../utils/file_tool");
4
+ class StreamCommand extends BaseCommand {
5
+ async execute() {
6
+ if (this.selfData.type == "write") {
7
+ return fs.createWriteStream(get_full_path(this.selfData.dst));
8
+ } else {
9
+ return fs.createReadStream(get_fst_file(this.selfData.src));
10
+ }
11
+ }
12
+ }
13
+
14
+ module.exports = {
15
+ StreamCommand,
16
+ };
@@ -0,0 +1,24 @@
1
+ const { stringify } = require("../utils/file_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class StringifyCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ let content = this.content;
8
+ return stringify(content, data.type, data.options);
9
+ }
10
+
11
+ getRequireContent() {
12
+ return true;
13
+ }
14
+
15
+ getRequiredParams() {
16
+ return [
17
+ "type",
18
+ ];
19
+ }
20
+ }
21
+
22
+ module.exports = {
23
+ StringifyCommand,
24
+ };
@@ -0,0 +1,26 @@
1
+ const { exec_shell } = require("../utils/shell_tool");
2
+ const { BaseCommand } = require("./base");
3
+ const { shareData } = require('./share_data');
4
+
5
+ class SvnAddCommand extends BaseCommand {
6
+ async execute() {
7
+ let data = this.selfData;
8
+ const status = await exec_shell({
9
+ cmd: 'svn status',
10
+ cwd: data.cwd,
11
+ capture_stdout: true,
12
+ });
13
+ for (const line of shareData.processPipes(status, "splitlines|remove_empty")) {
14
+ if (line[0] != "?") continue;
15
+ const status_path = line.substring(8);
16
+ await exec_shell({
17
+ ...data,
18
+ cmd: `svn add "${status_path}"`
19
+ });
20
+ }
21
+ }
22
+ }
23
+
24
+ module.exports = {
25
+ SvnAddCommand,
26
+ };
@@ -0,0 +1,49 @@
1
+ const { whisper, info } = require("../utils/log_tool");
2
+ const { svn_is_dirty } = require("../utils/scm_tool");
3
+ const { exec_shell } = require("../utils/shell_tool");
4
+ const { BaseCommand } = require("./base");
5
+
6
+ class SvnCommitCommand extends BaseCommand {
7
+ async execute() {
8
+ let data = this.selfData;
9
+ if (!data.force) {
10
+ let is_dirty = await svn_is_dirty(data.cwd);
11
+ if (!is_dirty) {
12
+ whisper(`没有要svn提交的更改 ${data.cwd} ${data.msg}`);
13
+ return;
14
+ } else {
15
+ if (data.remove_missing) {
16
+ let missingFiles = is_dirty.split(/[\r\n]{1,2}/).filter(v => v && v[0] == "!").map(v => v.split(/\s+/)[1]);
17
+ if (missingFiles.length) {
18
+ info(`删除svn丢失文件 ${data.cwd}`);
19
+ await exec_shell({
20
+ cmd: "svn rm".split(" ").concat(missingFiles),
21
+ cwd: data.cwd,
22
+ });
23
+ }
24
+ // 移除文件时要update
25
+ await exec_shell({
26
+ cmd: "svn update",
27
+ cwd: data.cwd,
28
+ });
29
+ }
30
+ info(`准备svn提交 ${data.cwd} ${data.msg}`);
31
+ if (data.credential) {
32
+ await exec_shell({
33
+ cmd: `svn commit --username ${data.credential.username} --password ${data.credential.password} -m`.split(" ").concat(data.msg),
34
+ cwd: data.cwd,
35
+ });
36
+ } else {
37
+ await exec_shell({
38
+ cmd: "svn commit -m".split(" ").concat(data.msg),
39
+ cwd: data.cwd,
40
+ });
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ module.exports = {
48
+ SvnCommitCommand,
49
+ };
@@ -0,0 +1,13 @@
1
+ const { svn_export_diff_head } = require("../utils/scm_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class SVNExportDiffHeadCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ await svn_export_diff_head(data.cwd, data.dst, data.base, data.options);
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ SVNExportDiffHeadCommand,
13
+ };
@@ -0,0 +1,13 @@
1
+ const { svn_is_dirty } = require("../utils/scm_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class SvnIsDirtyCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ return await svn_is_dirty(data.cwd);
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ SvnIsDirtyCommand,
13
+ };
@@ -0,0 +1,27 @@
1
+ const { exec_shell } = require("../utils/shell_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class SvnUpdateCommand extends BaseCommand {
5
+ async execute() {
6
+ let data = this.selfData;
7
+ if (data.credential) {
8
+ return await exec_shell({
9
+ cmd: `svn update --username ${data.credential.username} --password ${data.credential.password}`,
10
+ cwd: data.cwd,
11
+ encoding: data.encoding,
12
+ capture_stdout: data.capture_stdout,
13
+ });
14
+ } else {
15
+ return await exec_shell({
16
+ cmd: "svn update",
17
+ cwd: data.cwd,
18
+ encoding: data.encoding,
19
+ capture_stdout: data.capture_stdout,
20
+ });
21
+ }
22
+ }
23
+ }
24
+
25
+ module.exports = {
26
+ SvnUpdateCommand,
27
+ };
@@ -0,0 +1,18 @@
1
+ const { info } = require("../utils/log_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class SwitchCommand extends BaseCommand {
5
+ async execute() {
6
+ let commands_cfg = await this.forward("select", {
7
+ content: this.selfData.commands_cfgs,
8
+ preview: "title",
9
+ quiet: true,
10
+ });
11
+ info(`执行命令 ${commands_cfg.title}`);
12
+ await this.exec(commands_cfg.commands);
13
+ }
14
+ }
15
+
16
+ module.exports = {
17
+ SwitchCommand,
18
+ };
@@ -0,0 +1,12 @@
1
+ const { BaseCommand } = require("./base");
2
+ const temp = require("temp");
3
+ class TempCommand extends BaseCommand {
4
+ async execute() {
5
+ var openFile = temp.openSync(this.selfData.affixes);
6
+ return openFile.path;
7
+ }
8
+ }
9
+
10
+ module.exports = {
11
+ TempCommand,
12
+ };
@@ -0,0 +1,323 @@
1
+ const {
2
+ get_file_list,
3
+ get_full_path,
4
+ format_bytes
5
+ } = require("../utils/file_tool");
6
+ const {
7
+ success,
8
+ getPrint,
9
+ info,
10
+ warn,
11
+ whisper
12
+ } = require("../utils/log_tool");
13
+ const {
14
+ BaseCommand
15
+ } = require("./base");
16
+ const path = require("path");
17
+ const {
18
+ progress
19
+ } = require("../utils/display_tool");
20
+ const {
21
+ createWriteStream, readFileSync
22
+ } = require("fs");
23
+ const {
24
+ getCache,
25
+ setCache
26
+ } = require("../utils/cache_tool");
27
+ const crypto = require("crypto");
28
+
29
+
30
+ class TencentCosCommand extends BaseCommand {
31
+ async execute() {
32
+
33
+ let config = this.selfData.config;
34
+ let mode = this.selfData.mode;
35
+
36
+ return await new Promise((resolve, reject) => {
37
+
38
+ // 引入模块
39
+ var COS = require('cos-nodejs-sdk-v5');
40
+ // 创建实例
41
+ var cos = new COS({
42
+ SecretId: config.secret_id,
43
+ SecretKey: config.secret_key,
44
+ });
45
+
46
+ // 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.cloud.tencent.com/cos5/bucket
47
+ var Bucket = `${config.bucket}-${config.appid}`;
48
+ // 存储桶Region可以在COS控制台指定存储桶的概览页查看 https://console.cloud.tencent.com/cos5/bucket/
49
+ // 关于地域的详情见 https://cloud.tencent.com/document/product/436/6224
50
+ var Region = config.region;
51
+
52
+ switch (mode) {
53
+ case "VIEW": {
54
+ const prefix = this.selfData.src || "";
55
+ let keys = [];
56
+ /**
57
+ *
58
+ * @param {COS.GetBucketResult} ret
59
+ */
60
+ function getPartsComplete(data) {
61
+ keys.push(...data.Contents.map(v => v.Key));
62
+ progress(keys.length, 0, {
63
+ desc: data.NextMarker || "[FINISH]",
64
+ depth: 0,
65
+ color: "gray",
66
+ });
67
+ if (data.NextMarker) {
68
+ getParts(data.NextMarker);
69
+ return;
70
+ }
71
+ info("");
72
+ resolve(keys);
73
+ }
74
+
75
+ function getParts(marker = null) {
76
+ cos.getBucket({
77
+ Bucket: Bucket,
78
+ Region: Region,
79
+ MaxKeys: 1000,
80
+ Marker: marker,
81
+ Prefix: prefix || ""
82
+ }, (err, data) => {
83
+ if (err) {
84
+ reject(getPrint(err, true));
85
+ return;
86
+ }
87
+ getPartsComplete(data);
88
+ });
89
+ }
90
+ getParts();
91
+ break;
92
+ }
93
+ case "DOWNLOAD": {
94
+ let src = this.selfData.src;
95
+ let dst = get_full_path(this.selfData.dst);
96
+ cos.getObject({
97
+ Bucket: Bucket,
98
+ Region: Region,
99
+ Key: src,
100
+ onProgress: function (progressData) {
101
+ progress(progressData.loaded, progressData.total, {
102
+ desc: `Downloading from ${src} ${format_bytes(progressData.speed)}/s`,
103
+ depth: 0,
104
+ color: "cyan",
105
+ align: true,
106
+ format_bytes: true,
107
+ }, true);
108
+ },
109
+ Output: createWriteStream(dst)
110
+ }, (err, data) => {
111
+ if (err) {
112
+ reject(getPrint(err, true));
113
+ return;
114
+ }
115
+ resolve(data);
116
+ });
117
+ break;
118
+ }
119
+ case "UPLOAD_FILE":
120
+ case "UPLOAD": {
121
+ let dst = this.selfData.dst;
122
+ let src = get_full_path(this.selfData.src);
123
+ info("");
124
+ info(`开始上传 ${src} 到 ${dst}`);
125
+ // 分片上传
126
+ cos.sliceUploadFile({
127
+ Bucket: Bucket,
128
+ Region: Region,
129
+ Key: dst,
130
+ onProgress: (progressInfo) => {
131
+ progress(progressInfo.loaded, progressInfo.total, {
132
+ desc: `Uploading to ${dst} ${format_bytes(progressInfo.speed)}/s`,
133
+ depth: 0,
134
+ color: "green",
135
+ format_bytes: true,
136
+ align: true,
137
+ }, true);
138
+ },
139
+ FilePath: src // 本地文件地址,需自行替换
140
+ }, function (err, data) {
141
+ if (err) {
142
+ reject(getPrint(err, true));
143
+ return;
144
+ }
145
+ resolve(data);
146
+ });
147
+ break;
148
+ }
149
+ case "UPLOAD_FILES": {
150
+ let dst_folder = this.selfData.dst;
151
+ let strategy = this.selfData.options && this.selfData.options.strategy || "lazy";
152
+ let concurrency = this.selfData.options && this.selfData.options.concurrency || 10;
153
+ let base = this.selfData.base;
154
+ whisper(`在 ${base} 中收集要上传的文件...`, undefined, true);
155
+ let srcs = get_file_list(this.selfData.src, undefined, true);
156
+ let cacheKey = `tencent_cos/${Bucket}/${dst_folder}`.replace(/\//g, ".");
157
+ let cacheType = this.selfData.cache_type;
158
+ let cacheParam = this.selfData.cache_param;
159
+ let cachedFiles = null;
160
+ getCache(cacheKey, cacheType, cacheParam).then((_cachedFiles) => {
161
+ cachedFiles = _cachedFiles;
162
+ info(`cacheKey=${cacheKey}, cacheType=${cacheType}, cacheParam=${cacheParam},cachedFiles=${JSON.stringify(cachedFiles).substring(0, 20)}`);
163
+ if (!cachedFiles || !Object.keys(cachedFiles).length) {
164
+ const prefix = dst_folder;
165
+ let keys = {};
166
+ /**
167
+ *
168
+ * @param {COS.GetBucketResult} data
169
+ */
170
+ function getPartsComplete(data) {
171
+ data.Contents.forEach(obj => {
172
+ if (!keys[obj.Key]) {
173
+ keys[obj.Key] = !!obj;// obj.ETag;
174
+ }
175
+ });
176
+ let size = Object.keys(keys).length;
177
+ progress(size, size, {
178
+ desc: `获取已上传文件 ${data.NextMarker || ""}`,
179
+ depth: 0,
180
+ color: "gray",
181
+ });
182
+ if (data.NextMarker) {
183
+ getParts(data.NextMarker);
184
+ return;
185
+ }
186
+ info("");
187
+ cachedFiles = keys;
188
+ setCache(cacheKey, cachedFiles, cacheType, cacheParam);
189
+ readyForUpload();
190
+ }
191
+
192
+ function getParts(marker = null) {
193
+ cos.getBucket({
194
+ Bucket: Bucket,
195
+ Region: Region,
196
+ MaxKeys: 1000,
197
+ Marker: marker,
198
+ Prefix: prefix || ""
199
+ }, (err, data) => {
200
+ if (err) {
201
+ reject(getPrint(err, true));
202
+ return;
203
+ }
204
+ getPartsComplete(data);
205
+ });
206
+ }
207
+ getParts();
208
+ } else {
209
+ readyForUpload();
210
+ }
211
+ });
212
+
213
+ function readyForUpload() {
214
+ let rawLength = srcs.length;
215
+ // 过滤文件
216
+ srcs = srcs.filter(src => {
217
+ let cachedValue = cachedFiles[path.join(dst_folder, path.relative(base, src)).replace(/\\/g, "/")];
218
+ switch(strategy) {
219
+ case "lazy": {
220
+ if (cachedValue) {
221
+ return false;
222
+ }
223
+ break;
224
+ }
225
+ case "hash": {
226
+ let hash = crypto.createHash("md5").update(readFileSync(src)).digest("hex");
227
+ if (cachedValue == hash) {
228
+ return false;
229
+ }
230
+ break;
231
+ }
232
+ case "force": {
233
+
234
+ break;
235
+ }
236
+ default: {
237
+ throw `Unkown Strategy ${strategy}`;
238
+ break;
239
+ }
240
+ }
241
+ return true;
242
+ });
243
+ info(`预处理完成!`, "\r");
244
+ info(`实际 ${srcs.length}, 忽略 ${rawLength - srcs.length}, 共计 ${rawLength}`);
245
+ let from = 0;
246
+ function uploadRange(from = 0) {
247
+ let tmpSrcs = srcs.slice(from, from + concurrency);
248
+ if (tmpSrcs.length == 0) {
249
+ resolve(true);
250
+ return;
251
+ }
252
+ let left = tmpSrcs.length;
253
+ let files = tmpSrcs.map((src, index) => {
254
+ let dst = path.join(dst_folder, path.relative(base, src)).replace(/\\/g, "/");
255
+ let speed = 0;
256
+ return {
257
+ Bucket: Bucket,
258
+ Region: Region,
259
+ Key: dst,
260
+ FilePath: src,
261
+ onProgress: (progressInfo) => {
262
+ speed = progressInfo.speed;
263
+ // progress(index + from, srcs.length, {
264
+ // desc: `Uploading to ${dst} ${progressInfo.speed ? format_bytes(progressInfo.speed) + "/s" : ""}`,
265
+ // depth: 0,
266
+ // // format_bytes: true,
267
+ // color: "green",
268
+ // align: true,
269
+ // });
270
+ },
271
+ onFileFinish: (err, data) => {
272
+ if (err) {
273
+ // setCache(cacheKey, cachedFiles, cacheType, cacheParam);
274
+ // reject(getPrint(err, true));
275
+ return;
276
+ }
277
+ --left;
278
+ progress(from + (tmpSrcs.length - left), srcs.length, {
279
+ desc: `Uploaded to ${dst} ${format_bytes(speed)}/s`,
280
+ depth: 0,
281
+ // format_bytes: true,
282
+ color: "green",
283
+ align: true,
284
+ }, true);
285
+ // 当前上传的,存储为 hash
286
+ cachedFiles[dst] = crypto.createHash("md5").update(readFileSync(src)).digest("hex");
287
+ if (left == 0) {
288
+ setCache(cacheKey, cachedFiles, cacheType, cacheParam);
289
+ uploadRange(from + concurrency);
290
+ }
291
+ }
292
+ };
293
+ });
294
+ cos.uploadFiles({
295
+ files: files,
296
+ onProgress: (progressInfo) => {
297
+ },
298
+ onFileFinish: (err, data) => {
299
+ if (err) {
300
+ setCache(cacheKey, cachedFiles, cacheType, cacheParam);
301
+ reject(getPrint(err, true));
302
+ return;
303
+ }
304
+ }
305
+ });
306
+ }
307
+
308
+ uploadRange();
309
+ }
310
+ break;
311
+ }
312
+ default: {
313
+ resolve(false);
314
+ break;
315
+ }
316
+ }
317
+ });
318
+ }
319
+ }
320
+
321
+ module.exports = {
322
+ TencentCosCommand,
323
+ };
@@ -0,0 +1,14 @@
1
+ const transform_tool = require("../utils/transform_tool");
2
+
3
+ const { BaseCommand } = require("./base");
4
+
5
+ class TestCommand extends BaseCommand {
6
+ async execute() {
7
+ let data = this.selfData;
8
+ await this.forward(data.type, data.data);
9
+ }
10
+ }
11
+
12
+ module.exports = {
13
+ TestCommand,
14
+ };
@@ -0,0 +1,18 @@
1
+ const { BaseCommand } = require("./base");
2
+ class TitleCommand extends BaseCommand {
3
+ async execute() {
4
+ this.shareData.TITLE = this.content;
5
+ await this.forward("shell", {
6
+ cmd: ["title", this.content],
7
+ shell: true,
8
+ });
9
+ }
10
+
11
+ getRequireContent() {
12
+ return true;
13
+ }
14
+ }
15
+
16
+ module.exports = {
17
+ TitleCommand,
18
+ };
@@ -0,0 +1,21 @@
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const os = require("os");
4
+ const { BaseCommand } = require("./base");
5
+
6
+ class TmpdirCommand extends BaseCommand {
7
+ async execute() {
8
+ return fs.mkdtempSync(path.join(os.tmpdir(), this.selfData.name));
9
+ }
10
+
11
+
12
+ getRequiredParams() {
13
+ return [
14
+ "name",
15
+ ];
16
+ }
17
+ }
18
+
19
+ module.exports = {
20
+ TmpdirCommand,
21
+ };