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,162 @@
1
+ var child_process = require('child_process');
2
+ const {
3
+ get_fst_file
4
+ } = require('../utils/file_tool');
5
+ const {
6
+ dirname
7
+ } = require('path');
8
+ const {
9
+ option
10
+ } = require('yargs');
11
+
12
+ const iconv = require('iconv-lite');
13
+ const {
14
+ info,
15
+ warn,
16
+ vital,
17
+ error,
18
+ whisper,
19
+ success,
20
+ log,
21
+ isStdOut,
22
+ setLastError,
23
+ resetError
24
+ } = require('../utils/log_tool');
25
+
26
+ /**
27
+ *
28
+ * @param {{ cmd: string | string[], cwd?: string, encoding?:string = "cp936", capture_stdout?: boolean = false, ignore_code?: boolean = false, shell?: boolean = false, inputs?: any[]}} data
29
+ */
30
+ async function exec_shell(data) {
31
+ let instant_stdout = data.instant_stdout;
32
+ let capture_stdout = isStdOut() || data.capture_stdout;
33
+ let acceptableErrors = data.acceptableErrors || [];
34
+ const result = await new Promise((resolve, reject) => {
35
+ /** @type {string[]} */
36
+ let cmd = data.cmd;
37
+ if (typeof cmd === "string") {
38
+ cmd = generateTokens(cmd);
39
+ } else {
40
+ cmd = cmd.map(v => "" + v);
41
+ }
42
+ let cwd = data.cwd;
43
+ if (!cwd) {
44
+ let filepath = get_fst_file(cmd);
45
+ if (filepath) {
46
+ cwd = dirname(filepath);
47
+ }
48
+ }
49
+ if (cwd) {
50
+ let exist = get_fst_file(cwd);
51
+ if (!exist) {
52
+ throw (`未找到指定目录 ${cwd}`);
53
+ } else {
54
+ cwd = exist;
55
+ }
56
+ }
57
+ let options = {
58
+ cwd: cwd,
59
+ // shell 为 false(默认值), 可能会影响后续的控制台打印
60
+ // shell 为 true, 可能会影响 vbs 脚本调用
61
+ shell: data.shell == undefined ? false : data.shell,
62
+ };
63
+ let results = [];
64
+ let errors = [];
65
+ let encoding = data.encoding || "cp936";
66
+ whisper(`cmd:[${cmd}] cwd:${data.cwd} inputs:${data.inputs}`);
67
+ options.stdio = ["pipe", capture_stdout ? "pipe" : process.stdout, "pipe"];
68
+ const child = child_process.spawn(cmd[0], cmd.slice(1), options);
69
+ if (child.stdout) {
70
+ child.stdout.on("data", (chunk) => {
71
+ results.push(chunk);
72
+ if (instant_stdout) {
73
+ warn(iconv.decode(chunk, encoding));
74
+ }
75
+ });
76
+ }
77
+ if (child.stderr) {
78
+ child.stderr.on("data", (chunk) => {
79
+ errors.push(chunk);
80
+ });
81
+ }
82
+ try {
83
+ if (child.stdin) {
84
+ if (data.inputs) {
85
+ child.stdin.write(data.inputs.join("\n"));
86
+ }
87
+ child.stdin.end();
88
+ }
89
+ } catch (err) {
90
+ setLastError(`${err}`);
91
+ resolve("");
92
+ }
93
+ child.on("error", (err) => {
94
+ setLastError(err);
95
+ resolve("");
96
+ });
97
+ // child.on('close', code => {
98
+ child.on('exit', code => {
99
+ if (!data.ignore_code && code != 0) {
100
+ let errMsg = iconv.decode(Buffer.concat(errors), encoding);
101
+ let isAcceptableErrors = errMsg && acceptableErrors.some(err => {
102
+ return errMsg.indexOf(err) >= 0;
103
+ });
104
+ if (!isAcceptableErrors) {
105
+ setLastError(`错误码 ${code} ${errMsg}`, code);
106
+ }
107
+ }
108
+ if (results.length) {
109
+ let result = iconv.decode(Buffer.concat(results), encoding);
110
+ if (data.trim) {
111
+ result = result.trim();
112
+ }
113
+ resolve(result);
114
+ } else {
115
+ resolve("");
116
+ }
117
+ });
118
+ });
119
+ if (!capture_stdout) { // 不捕获输出
120
+ // 换行使打印数据显示更干净
121
+ // log("");
122
+ }
123
+ return result;
124
+ }
125
+
126
+ /**
127
+ * 解析字符串为token数组
128
+ * @param {string} cmd
129
+ * @returns
130
+ */
131
+ function generateTokens(cmd) {
132
+ let tokens = [];
133
+ let buffer = "";
134
+ for (let i = 0, len = cmd.length; i < len; ++i) {
135
+ let char = cmd[i];
136
+ if (buffer[0] === "\"") {
137
+ if (char === "\"") {
138
+ tokens.push(buffer.substring(1));
139
+ buffer = "";
140
+ continue;
141
+ }
142
+ } else {
143
+ if (char === " ") {
144
+ if (buffer.length) {
145
+ tokens.push(buffer);
146
+ buffer = "";
147
+ }
148
+ continue;
149
+ }
150
+ }
151
+ buffer += char;
152
+ }
153
+ if (buffer.length) {
154
+ tokens.push(buffer);
155
+ buffer = "";
156
+ }
157
+ return tokens;
158
+ }
159
+
160
+ module.exports = {
161
+ exec_shell,
162
+ };
@@ -0,0 +1,44 @@
1
+ (function() {
2
+ var DiffFile;
3
+
4
+ module.exports = DiffFile = (function() {
5
+ function DiffFile(firstLine) {
6
+ this.name = firstLine.split(/\s/)[1];
7
+ this.lines = [];
8
+ }
9
+
10
+ DiffFile.prototype.setIndex = function(indexLine) {
11
+ var match;
12
+ match = indexLine.split(/\s/)[2].replace(')', '');
13
+ return this.from = match;
14
+ };
15
+
16
+ DiffFile.prototype.finishHeaderParse = function(line) {
17
+ var match;
18
+ match = line.split(/\s/)[2].replace(')', '');
19
+ this.to = match;
20
+ return this.headerParsed = true;
21
+ };
22
+
23
+ DiffFile.prototype.appendLine = function(line) {
24
+ var match;
25
+ this.lines.push(line);
26
+ if (line.type === 'chunk') {
27
+ match = line.content.match(/^@@\s+\-([^\s]+)\s+\+([^\s]+)/);
28
+ this.deletionLineNum = match[1].split(',')[0];
29
+ return this.additionLineNum = match[2].split(',')[0];
30
+ } else if (line.type === 'normal') {
31
+ line.deletionLineNum = this.deletionLineNum++;
32
+ return line.additionLineNum = this.additionLineNum++;
33
+ } else if (line.type === 'deletion') {
34
+ return line.deletionLineNum = this.deletionLineNum++;
35
+ } else if (line.type === 'addition') {
36
+ return line.additionLineNum = this.additionLineNum++;
37
+ }
38
+ };
39
+
40
+ return DiffFile;
41
+
42
+ })();
43
+
44
+ }).call(this);
@@ -0,0 +1,55 @@
1
+ (function() {
2
+ var DiffFile;
3
+
4
+ DiffFile = require('./diff_file');
5
+
6
+ module.exports.parse = function(diffStr) {
7
+ var currentFile, files, lines;
8
+ files = [];
9
+ currentFile = null;
10
+ lines = diffStr.split("\n");
11
+ lines.pop();
12
+ lines.forEach(function(line) {
13
+ if (line.match(/^Index/)) {
14
+ currentFile = new DiffFile(line);
15
+ return files.push(currentFile);
16
+ } else {
17
+ if (!currentFile.headerParsed) {
18
+ if (line.match(/^\-\-\-/)) {
19
+ currentFile.setIndex(line);
20
+ }
21
+ if(line.match(/^={67}$/)) {
22
+ return;
23
+ }
24
+ if (line.match(/^\+\+\+/)) {
25
+ return currentFile.finishHeaderParse(line);
26
+ }
27
+ } else {
28
+ if (line.match(/^@@/)) {
29
+ return currentFile.appendLine({
30
+ content: line,
31
+ type: 'chunk'
32
+ });
33
+ } else if (line.match(/^-/)) {
34
+ return currentFile.appendLine({
35
+ content: line,
36
+ type: 'deletion'
37
+ });
38
+ } else if (line.match(/^\+/)) {
39
+ return currentFile.appendLine({
40
+ content: line,
41
+ type: 'addition'
42
+ });
43
+ } else {
44
+ return currentFile.appendLine({
45
+ content: line,
46
+ type: 'normal'
47
+ });
48
+ }
49
+ }
50
+ }
51
+ });
52
+ return files;
53
+ };
54
+
55
+ }).call(this);