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.
- package/LICENSE +15 -0
- package/assets/alert.png +0 -0
- package/assets/error.png +0 -0
- package/assets/success.png +0 -0
- package/commands/abort.js +11 -0
- package/commands/alert.js +19 -0
- package/commands/assemble.js +56 -0
- package/commands/assert.js +18 -0
- package/commands/base.js +363 -0
- package/commands/break.js +11 -0
- package/commands/change_filter.js +34 -0
- package/commands/cheerio.js +15 -0
- package/commands/clear_screen.js +14 -0
- package/commands/commit.js +31 -0
- package/commands/compare.js +23 -0
- package/commands/confirm.js +16 -0
- package/commands/continue.js +11 -0
- package/commands/copy.js +14 -0
- package/commands/cursor_up.js +12 -0
- package/commands/date.js +25 -0
- package/commands/debugger.js +11 -0
- package/commands/dingtalk.js +110 -0
- package/commands/disassemble.js +36 -0
- package/commands/divination.js +15 -0
- package/commands/download.js +12 -0
- package/commands/edit.js +83 -0
- package/commands/edit_excel.js +57 -0
- package/commands/env_optional.js +57 -0
- package/commands/eval.js +27 -0
- package/commands/exec_from_file.js +31 -0
- package/commands/export_diff_head.js +31 -0
- package/commands/file_info.js +41 -0
- package/commands/file_size.js +12 -0
- package/commands/files.js +14 -0
- package/commands/first_exist.js +18 -0
- package/commands/flatten.js +18 -0
- package/commands/ftp.js +161 -0
- package/commands/git_commit.js +31 -0
- package/commands/git_export_diff_head.js +13 -0
- package/commands/git_is_dirty.js +13 -0
- package/commands/hash.js +21 -0
- package/commands/http_request.js +12 -0
- package/commands/image_crop.js +19 -0
- package/commands/input.js +37 -0
- package/commands/interval.js +60 -0
- package/commands/is_dirty.js +31 -0
- package/commands/jwt_decode.js +22 -0
- package/commands/list2dict.js +32 -0
- package/commands/log.js +72 -0
- package/commands/loop.js +115 -0
- package/commands/loop_forever.js +66 -0
- package/commands/merge_files.js +39 -0
- package/commands/mgr.js +476 -0
- package/commands/modify.js +44 -0
- package/commands/move.js +14 -0
- package/commands/move_local.js +14 -0
- package/commands/multi_select.js +16 -0
- package/commands/mysql_connect.js +29 -0
- package/commands/mysql_end.js +13 -0
- package/commands/mysql_query.js +19 -0
- package/commands/notify.js +13 -0
- package/commands/open.js +30 -0
- package/commands/parse.js +18 -0
- package/commands/pause.js +15 -0
- package/commands/print.js +47 -0
- package/commands/read_cache.js +12 -0
- package/commands/read_cfg.js +13 -0
- package/commands/read_clipboard.js +19 -0
- package/commands/read_excel.js +17 -0
- package/commands/read_only_excel.js +40 -0
- package/commands/read_plain.js +14 -0
- package/commands/remove.js +14 -0
- package/commands/retrieve.js +17 -0
- package/commands/reveal.js +33 -0
- package/commands/revision_info.js +31 -0
- package/commands/schedule.js +80 -0
- package/commands/select.js +17 -0
- package/commands/send_email.js +25 -0
- package/commands/share_data.js +745 -0
- package/commands/shell.js +13 -0
- package/commands/sleep.js +17 -0
- package/commands/store.js +13 -0
- package/commands/store_optional.js +33 -0
- package/commands/stream.js +16 -0
- package/commands/stringify.js +24 -0
- package/commands/svn_add.js +26 -0
- package/commands/svn_commit.js +49 -0
- package/commands/svn_export_diff_head.js +13 -0
- package/commands/svn_is_dirty.js +13 -0
- package/commands/svn_update.js +27 -0
- package/commands/switch.js +18 -0
- package/commands/temp.js +12 -0
- package/commands/tencent_cos.js +323 -0
- package/commands/test.js +14 -0
- package/commands/title.js +18 -0
- package/commands/tmpdir.js +21 -0
- package/commands/translate.js +58 -0
- package/commands/traversal.js +38 -0
- package/commands/truncate.js +31 -0
- package/commands/truncate_all.js +62 -0
- package/commands/ts_sort.js +18 -0
- package/commands/unzip.js +50 -0
- package/commands/updating_revision.js +28 -0
- package/commands/valid_required.js +31 -0
- package/commands/void.js +10 -0
- package/commands/watch_mail.js +94 -0
- package/commands/web_socket.js +233 -0
- package/commands/which.js +60 -0
- package/commands/write_cache.js +16 -0
- package/commands/write_cfg.js +18 -0
- package/commands/write_clipboard.js +23 -0
- package/commands/write_excel.js +17 -0
- package/commands/write_plain.js +18 -0
- package/commands/zip.js +78 -0
- package/commands/zip_data.js +64 -0
- package/examples/print_env.yml +3 -0
- package/index.js +109 -0
- package/package.json +63 -0
- package/scratch/.gitkeep +0 -0
- package/utils/alert_tool.js +133 -0
- package/utils/base64_tool.js +13 -0
- package/utils/cache/local_cache.js +79 -0
- package/utils/cache/raw_cache.js +47 -0
- package/utils/cache/simple_local_cache.js +33 -0
- package/utils/cache/simple_sqlite_cache.js +43 -0
- package/utils/cache/simple_svn_cache.js +49 -0
- package/utils/cache/svn_cache.js +40 -0
- package/utils/cache_tool.js +53 -0
- package/utils/display_tool.js +85 -0
- package/utils/divination_util.js +555 -0
- package/utils/file_tool.js +529 -0
- package/utils/hash_tool.js +8 -0
- package/utils/interaction_tool.js +228 -0
- package/utils/log_tool.js +190 -0
- package/utils/parse_directive.js +194 -0
- package/utils/parse_tool.js +236 -0
- package/utils/request_tool.js +156 -0
- package/utils/scm_tool.js +108 -0
- package/utils/selection_tool.js +593 -0
- package/utils/shell_tool.js +162 -0
- package/utils/svn_diff/diff_file.js +44 -0
- package/utils/svn_diff/diff_parser.js +55 -0
- package/utils/transform_tool.js +520 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { BaseCommand } = require("./base");
|
|
2
|
+
|
|
3
|
+
class MysqlConnectCommand extends BaseCommand {
|
|
4
|
+
async execute() {
|
|
5
|
+
let data = this.selfData;
|
|
6
|
+
var mysql = require('mysql');
|
|
7
|
+
var connection = mysql.createConnection({
|
|
8
|
+
host : data.host ?? "localhost",
|
|
9
|
+
port : data.port ?? 3306,
|
|
10
|
+
password : data.password ?? "",
|
|
11
|
+
user : data.user,
|
|
12
|
+
database : data.database,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
connection.connect();
|
|
16
|
+
|
|
17
|
+
// connection.query('SELECT * FROM zt_task LIMIT 10', function (error, results, fields) {
|
|
18
|
+
// if (error) throw error;
|
|
19
|
+
// console.log('The solution is: ', results[0].solution);
|
|
20
|
+
// });
|
|
21
|
+
|
|
22
|
+
// connection.end();
|
|
23
|
+
return connection;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
MysqlConnectCommand,
|
|
29
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { BaseCommand } = require("./base");
|
|
2
|
+
|
|
3
|
+
class MysqlEndCommand extends BaseCommand {
|
|
4
|
+
async execute() {
|
|
5
|
+
let connection = this.selfData.connection;
|
|
6
|
+
connection.end();
|
|
7
|
+
return connection;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
MysqlEndCommand,
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const {
|
|
2
|
+
BaseCommand
|
|
3
|
+
} = require("./base");
|
|
4
|
+
|
|
5
|
+
class MysqlQueryCommand extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
let connection = this.selfData.connection;
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
connection.query(this.selfData.query, function (error, results, fields) {
|
|
10
|
+
if (error) reject(error);
|
|
11
|
+
resolve(results);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
MysqlQueryCommand,
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { showNotify } = require('../utils/alert_tool');
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class NotifyCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
let data = this.selfData;
|
|
7
|
+
return await showNotify(data);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
NotifyCommand,
|
|
13
|
+
};
|
package/commands/open.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { get_file_list } = require("../utils/file_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
const { toArray } = require("../utils/transform_tool");
|
|
4
|
+
|
|
5
|
+
class OpenCommand extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
const open = require("open");
|
|
8
|
+
let data = this.selfData;
|
|
9
|
+
let urls;
|
|
10
|
+
switch (data.mode) {
|
|
11
|
+
case 'web': {
|
|
12
|
+
urls = toArray(data.src);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
case 'file':
|
|
16
|
+
default: {
|
|
17
|
+
urls = get_file_list(data.src);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let options = Object.assign({wait: true}, data.options);
|
|
21
|
+
for (let index = 0; index < urls.length; index++) {
|
|
22
|
+
const file = urls[index];
|
|
23
|
+
await open(file, options);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
OpenCommand,
|
|
30
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { parse } = require("../utils/file_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class ParseCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
let data = this.selfData;
|
|
7
|
+
let content = this.content;
|
|
8
|
+
return parse(content, data.type);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getRequireContent() {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
ParseCommand,
|
|
18
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { pause } = require("../utils/interaction_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class PauseCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
if (this.isFullAutomatic()) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await pause(this.selfData && this.selfData.prompt, this.selfData && this.selfData.countdown);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
PauseCommand,
|
|
15
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const transform_tool = require("../utils/transform_tool");
|
|
2
|
+
const { whisper, info, getPrint, success, log, LogLevel } = require("../utils/log_tool");
|
|
3
|
+
const { pause } = require("../utils/interaction_tool");
|
|
4
|
+
const { BaseCommand } = require("./base");
|
|
5
|
+
const { eval_code } = require("./share_data");
|
|
6
|
+
|
|
7
|
+
class PrintCommand extends BaseCommand {
|
|
8
|
+
async execute() {
|
|
9
|
+
let data = this.selfData;
|
|
10
|
+
let level = data && data.level || LogLevel.INFO;
|
|
11
|
+
let ignore = data && data.ignore || [];
|
|
12
|
+
ignore = transform_tool.toArray(ignore);
|
|
13
|
+
let content = null;
|
|
14
|
+
let use_content = false;
|
|
15
|
+
let useRaw = level === LogLevel.STDOUT;
|
|
16
|
+
if (data && (data.mode == "content" || Object.prototype.hasOwnProperty.call(data, "content"))) {
|
|
17
|
+
content = useRaw ? data.content : getPrint(data.content, true);
|
|
18
|
+
use_content = true;
|
|
19
|
+
} else if (data && (data.mode == "code" || Object.prototype.hasOwnProperty.call(data, "code"))) {
|
|
20
|
+
content = useRaw ? data.content : getPrint(eval_code(data.code), true);
|
|
21
|
+
use_content = true;
|
|
22
|
+
}
|
|
23
|
+
if (use_content) {
|
|
24
|
+
if (content && content.split("\n").length > 1) {
|
|
25
|
+
log("");
|
|
26
|
+
}
|
|
27
|
+
log(content, undefined, level);
|
|
28
|
+
} else {
|
|
29
|
+
log("");
|
|
30
|
+
let keys = data && data.key ? transform_tool.toArray(data.key) : Object.keys(this.shareData);
|
|
31
|
+
keys = keys.filter(key => ignore.indexOf(key) == -1);
|
|
32
|
+
// 仅显示最近的几条
|
|
33
|
+
const numShowLatest = data && data.count || keys.length;
|
|
34
|
+
if (numShowLatest > 20) {
|
|
35
|
+
await pause(`即将打印 ${numShowLatest} 条数据`);
|
|
36
|
+
}
|
|
37
|
+
for (let index = keys.length - numShowLatest; index < keys.length; index++) {
|
|
38
|
+
const key = keys[index];
|
|
39
|
+
log(useRaw ? this.getDataByKey(key) : `${key} => ${getPrint(this.getDataByKey(key), true)}`, undefined, level);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
PrintCommand,
|
|
47
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { getCache } = require("../utils/cache_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class ReadCacheCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
return await getCache(this.selfData.cache_key, this.selfData.cache_type, this.selfData.cache_param);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
ReadCacheCommand,
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { read_cfg } = require("../utils/file_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class ReadCfgCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
let data = this.selfData;
|
|
7
|
+
return await read_cfg(data.src, data.type, data.options);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
ReadCfgCommand,
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const clipboardy = require('clipboardy');
|
|
2
|
+
const { warn } = require('../utils/log_tool');
|
|
3
|
+
const { BaseCommand } = require('./base');
|
|
4
|
+
|
|
5
|
+
class ReadClipboard extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
let data = this.selfData;
|
|
8
|
+
try {
|
|
9
|
+
return clipboardy.readSync();
|
|
10
|
+
} catch (err) {
|
|
11
|
+
warn(err);
|
|
12
|
+
}
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
ReadClipboard,
|
|
19
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { get_fst_file } = require("../utils/file_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class ReadExcelCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
let filename = get_fst_file(this.selfData.src);
|
|
7
|
+
const Excel = require("exceljs");
|
|
8
|
+
// read from a file
|
|
9
|
+
const workbook = new Excel.Workbook();
|
|
10
|
+
let ret = await workbook.xlsx.readFile(filename);
|
|
11
|
+
return ret;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
ReadExcelCommand,
|
|
17
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { get_fst_file } = require("../utils/file_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class ReadOnlyExcelCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
const xlsx = require("xlsx");
|
|
7
|
+
const SpreadsheetColumn = require('spreadsheet-column');
|
|
8
|
+
const sc = new SpreadsheetColumn();
|
|
9
|
+
let filename = get_fst_file(this.selfData.src);
|
|
10
|
+
let ret = xlsx.readFile(filename, this.selfData.options);
|
|
11
|
+
if (this.selfData.sheets_array !== false) {
|
|
12
|
+
ret.SheetsArray = {};
|
|
13
|
+
for (let sheetName in ret.Sheets) {
|
|
14
|
+
let sheetData = ret.Sheets[sheetName];
|
|
15
|
+
let sheetArray = [];
|
|
16
|
+
// "A1:Y71"
|
|
17
|
+
/** @type {string[]} */
|
|
18
|
+
let refs = sheetData['!ref'].split(":");
|
|
19
|
+
let colBeg = sc.fromStr(/[A-Z]+/.exec(refs[0])[0]);
|
|
20
|
+
let rowBeg = /[0-9]+/.exec(refs[0])[0];
|
|
21
|
+
let colEnd = sc.fromStr(/[A-Z]+/.exec(refs[1])[0]);
|
|
22
|
+
let rowEnd = /[0-9]+/.exec(refs[1])[0];
|
|
23
|
+
for (let row = rowBeg; row <= rowEnd; ++row) {
|
|
24
|
+
let rowData = [];
|
|
25
|
+
for (let col = colBeg; col <= colEnd; ++col) {
|
|
26
|
+
let cell = sheetData[`${sc.fromInt(col)}${row}`];
|
|
27
|
+
rowData.push(cell && cell.v);
|
|
28
|
+
}
|
|
29
|
+
sheetArray.push(rowData);
|
|
30
|
+
}
|
|
31
|
+
ret.SheetsArray[sheetName] = sheetArray;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return ret;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
ReadOnlyExcelCommand,
|
|
40
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { read_plain } = require("../utils/file_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class ReadPlainCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
let data = this.selfData;
|
|
7
|
+
let content = read_plain(data.src, data.options);
|
|
8
|
+
return content;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
ReadPlainCommand,
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { remove } = require("../utils/file_tool");
|
|
2
|
+
const { log } = require("../utils/log_tool");
|
|
3
|
+
const { BaseCommand } = require("./base");
|
|
4
|
+
|
|
5
|
+
class RemoveCommand extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
let data = this.selfData;
|
|
8
|
+
await remove(data.src, data.options);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
RemoveCommand,
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { BaseCommand } = require("./base");
|
|
2
|
+
|
|
3
|
+
class RetrieveCommand extends BaseCommand {
|
|
4
|
+
async execute() {
|
|
5
|
+
let data = this.selfData;
|
|
6
|
+
let content = this.content;
|
|
7
|
+
return content;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getRequireContent() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
RetrieveCommand,
|
|
17
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { get_file_list } = require("../utils/file_tool");
|
|
2
|
+
const { warn } = require("../utils/log_tool");
|
|
3
|
+
const { exec_shell } = require("../utils/shell_tool");
|
|
4
|
+
const { BaseCommand } = require("./base");
|
|
5
|
+
|
|
6
|
+
class RevealCommand extends BaseCommand {
|
|
7
|
+
async execute() {
|
|
8
|
+
let data = this.selfData;
|
|
9
|
+
let files = get_file_list(data.src);
|
|
10
|
+
if (files.length == 0) {
|
|
11
|
+
warn(`reveal 未匹配到文件 ${data.src}`);
|
|
12
|
+
}
|
|
13
|
+
for (let index = 0; index < files.length; index++) {
|
|
14
|
+
const file = files[index];
|
|
15
|
+
if (process.platform === 'win32') {
|
|
16
|
+
await exec_shell({
|
|
17
|
+
cmd: ['explorer', "/select,", file.replace(/\//g, "\\")],
|
|
18
|
+
// 这条命令的错误码为1
|
|
19
|
+
ignore_code: true,
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
// TODO: 未测验
|
|
23
|
+
await exec_shell({
|
|
24
|
+
cmd: ['start', file]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
RevealCommand,
|
|
33
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { parse } = require("../utils/file_tool");
|
|
2
|
+
const { exec_shell } = require("../utils/shell_tool");
|
|
3
|
+
const { BaseCommand } = require("./base");
|
|
4
|
+
|
|
5
|
+
class RevisionInfoCommand extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
let svnInfo = await parse(await exec_shell({
|
|
8
|
+
cmd: "svn info",
|
|
9
|
+
cwd: this.selfData.src,
|
|
10
|
+
capture_stdout: true,
|
|
11
|
+
}), 'yaml');
|
|
12
|
+
let svnLogs = await parse(await exec_shell({
|
|
13
|
+
cmd: `svn log -c${this.selfData.revisions} ${svnInfo.URL} --xml`,
|
|
14
|
+
capture_stdout: true,
|
|
15
|
+
encoding: "utf8",
|
|
16
|
+
}), "xml");
|
|
17
|
+
let summary = Array.prototype.slice.call(svnLogs.getElementsByTagName("logentry")).map(logentry => {
|
|
18
|
+
return {
|
|
19
|
+
revision: logentry.attributes.getNamedItem('revision').nodeValue,
|
|
20
|
+
msg: Array.prototype.slice.call(logentry.getElementsByTagName("msg")).map(v => v.textContent).join(""),
|
|
21
|
+
author: Array.prototype.slice.call(logentry.getElementsByTagName("author")).map(v => v.textContent).join(""),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
;
|
|
25
|
+
return summary;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = {
|
|
30
|
+
RevisionInfoCommand,
|
|
31
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const { pause } = require('../utils/interaction_tool');
|
|
2
|
+
const { warn, error, info, success, getPrint } = require('../utils/log_tool');
|
|
3
|
+
const { formatTimeInMillisec, formatDate, convert } = require('../utils/transform_tool');
|
|
4
|
+
const { BaseCommand } = require('./base');
|
|
5
|
+
const { formatData } = require('./share_data');
|
|
6
|
+
|
|
7
|
+
class ScheduleCommand extends BaseCommand {
|
|
8
|
+
async execute() {
|
|
9
|
+
await new Promise(async (resolve, reject) => {
|
|
10
|
+
let data = this.selfData;
|
|
11
|
+
let commandCfgs = data.commands;
|
|
12
|
+
/** 是否阻塞 */
|
|
13
|
+
let blocked = data.blocked;
|
|
14
|
+
// 特殊处理字符的情况
|
|
15
|
+
if (typeof commandCfgs === "string") {
|
|
16
|
+
commandCfgs = formatData(commandCfgs);
|
|
17
|
+
}
|
|
18
|
+
let now = Date.now();
|
|
19
|
+
let timeout;
|
|
20
|
+
let timeout_date = null;
|
|
21
|
+
switch (data.schedule_type) {
|
|
22
|
+
case "delay": {
|
|
23
|
+
timeout = convert(data.value, "millisecond");
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case "date": {
|
|
27
|
+
let date = new Date(data.value);
|
|
28
|
+
timeout = date - now;
|
|
29
|
+
timeout_date = date;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
throw `不支持的计划任务类型 ${data.schedule_type}`;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let asyncId;
|
|
38
|
+
if (!timeout_date) {
|
|
39
|
+
timeout_date = new Date(now + timeout);
|
|
40
|
+
}
|
|
41
|
+
if (isNaN(timeout_date)) {
|
|
42
|
+
throw `日期格式不正确 ${data.value}`;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let willConfirm = timeout <= 0 && !data.force;
|
|
46
|
+
let timer = setTimeout(async () => {
|
|
47
|
+
if (willConfirm) {
|
|
48
|
+
await pause(`需要确认后才可执行任务[${asyncId}]!`);
|
|
49
|
+
}
|
|
50
|
+
info("");
|
|
51
|
+
warn(`开始执行计划任务[${asyncId}]`);
|
|
52
|
+
await this.exec(commandCfgs, this.depth + 1);
|
|
53
|
+
if (blocked) {
|
|
54
|
+
resolve();
|
|
55
|
+
}
|
|
56
|
+
}, timeout);
|
|
57
|
+
asyncId = timer[Object.getOwnPropertySymbols(timer).find(v => v.description == "asyncId")];
|
|
58
|
+
info("");
|
|
59
|
+
if (timeout <= 0) {
|
|
60
|
+
warn(`将在${formatDate(timeout_date)} 时间已过期${formatTimeInMillisec(-timeout)}, 立刻执行计划任务[${asyncId}]`);
|
|
61
|
+
} else {
|
|
62
|
+
warn(`将在${formatDate(timeout_date)} (${formatTimeInMillisec(timeout)}后)执行计划任务[${asyncId}]`);
|
|
63
|
+
}
|
|
64
|
+
if (!blocked) {
|
|
65
|
+
resolve();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getRequiredParams() {
|
|
71
|
+
return [
|
|
72
|
+
"schedule_type",
|
|
73
|
+
"value",
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = {
|
|
79
|
+
ScheduleCommand,
|
|
80
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
const { select } = require('../utils/selection_tool');
|
|
4
|
+
|
|
5
|
+
class SelectCommand extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
return select(this.content, this.selfData);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getRequireContent() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
SelectCommand,
|
|
17
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { setLastError } = require("../utils/log_tool");
|
|
2
|
+
const { BaseCommand } = require("./base");
|
|
3
|
+
|
|
4
|
+
class SendEmailCommand extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
const { SMTPClient, Message } = await import('emailjs');
|
|
7
|
+
const client = new SMTPClient(this.selfData.client);
|
|
8
|
+
const message = new Message(this.selfData.message);
|
|
9
|
+
|
|
10
|
+
return new Promise(resolve => {
|
|
11
|
+
client.send(message, (err, msg) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
setLastError(err);
|
|
14
|
+
resolve();
|
|
15
|
+
} else {
|
|
16
|
+
resolve(msg);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
SendEmailCommand,
|
|
25
|
+
};
|