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,79 @@
|
|
|
1
|
+
// const LocalStorage = require("node-localstorage").LocalStorage;
|
|
2
|
+
|
|
3
|
+
const { writeFileSync, readFileSync, existsSync, mkdirSync } = require('fs');
|
|
4
|
+
const { error, warn } = require("../log_tool");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { shareData } = require('../../commands/share_data');
|
|
7
|
+
module.exports = class LocalCache {
|
|
8
|
+
constructor(location) {
|
|
9
|
+
this.location = location || path.resolve(shareData.AUTOMATOR_APPDATA, ".local_cache");
|
|
10
|
+
this.StorageCache = {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async setCache(key, val) {
|
|
14
|
+
key += ".yml";
|
|
15
|
+
this.StorageCache[key] = val;
|
|
16
|
+
try {
|
|
17
|
+
var resStr = require("yaml").stringify(val);
|
|
18
|
+
this.getLocalStorage().setItem(key, resStr);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
warn(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getCache(key) {
|
|
25
|
+
key += ".yml";
|
|
26
|
+
var res = null;
|
|
27
|
+
res = this.StorageCache[key];
|
|
28
|
+
if (!res) {
|
|
29
|
+
try {
|
|
30
|
+
res = this.getLocalStorage().getItem(key);
|
|
31
|
+
if (res) {
|
|
32
|
+
res = require("yaml").parse(res);
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
warn(e);
|
|
36
|
+
}
|
|
37
|
+
if (res) {
|
|
38
|
+
this.StorageCache[key] = res;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return res;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getLocalStorage() {
|
|
45
|
+
if (!this.localStorage) {
|
|
46
|
+
this.localStorage = new LocalStorage(this.location);
|
|
47
|
+
}
|
|
48
|
+
return this.localStorage;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
class LocalStorage {
|
|
53
|
+
constructor(location) {
|
|
54
|
+
this.location = location;
|
|
55
|
+
if (!existsSync(location)) {
|
|
56
|
+
mkdirSync(location, {
|
|
57
|
+
recursive: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
parseKey(key) {
|
|
63
|
+
return path.join(this.location, key.replace(/[\\\/\:\*\?"<>\|]/g, (substring) => encodeURIComponent(substring)));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setItem(key, val) {
|
|
67
|
+
let file = this.parseKey(key);
|
|
68
|
+
writeFileSync(file, val, "utf-8");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getItem(key) {
|
|
72
|
+
let file = this.parseKey(key);
|
|
73
|
+
try {
|
|
74
|
+
return readFileSync(file, "utf-8");
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { error, warn } = require("../log_tool");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const { shareData } = require('../../commands/share_data');
|
|
5
|
+
module.exports = class RawCache {
|
|
6
|
+
constructor(location) {
|
|
7
|
+
this.location = location || path.resolve(shareData.AUTOMATOR_APPDATA, ".raw_cache");
|
|
8
|
+
if (!fs.existsSync(this.location)) {
|
|
9
|
+
fs.mkdirSync(this.location, {
|
|
10
|
+
recursive: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
this.StorageCache = {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async setCache(key, val) {
|
|
17
|
+
this.StorageCache[key] = val;
|
|
18
|
+
try {
|
|
19
|
+
fs.writeFileSync(path.resolve(this.location, key), val);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
warn(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getCache(key) {
|
|
26
|
+
var res = null;
|
|
27
|
+
res = this.StorageCache[key];
|
|
28
|
+
if (!res) {
|
|
29
|
+
try {
|
|
30
|
+
res = fs.readFileSync(path.resolve(this.location, key));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
// warn(e);
|
|
33
|
+
}
|
|
34
|
+
if (res) {
|
|
35
|
+
this.StorageCache[key] = res;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getLocalStorage() {
|
|
42
|
+
if (!this.localStorage) {
|
|
43
|
+
this.localStorage = new LocalStorage(this.location);
|
|
44
|
+
}
|
|
45
|
+
return this.localStorage;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const LocalStorage = require("node-localstorage").LocalStorage;
|
|
2
|
+
|
|
3
|
+
const { error, warn } = require("../log_tool");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const { shareData } = require('../../commands/share_data');
|
|
7
|
+
module.exports = class SimpleLocalCache {
|
|
8
|
+
constructor(location) {
|
|
9
|
+
this.location = location || path.resolve(shareData.AUTOMATOR_APPDATA, `.simple_local_cache.yml`);
|
|
10
|
+
if (fs.existsSync(this.location)) {
|
|
11
|
+
this.StorageCache = require("yaml").parse(fs.readFileSync(this.location, "utf-8"));
|
|
12
|
+
} else {
|
|
13
|
+
this.StorageCache = {};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async setCache(key, val) {
|
|
18
|
+
this.StorageCache[key] = val;
|
|
19
|
+
try {
|
|
20
|
+
fs.writeFileSync(this.location, require("yaml").stringify(this.StorageCache), "utf-8");
|
|
21
|
+
} catch (e) {
|
|
22
|
+
warn(e);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getCache(key) {
|
|
27
|
+
return this.StorageCache[key];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getSize() {
|
|
31
|
+
return Object.keys(this.StorageCache).length;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const sqlite3 = require("sqlite3");
|
|
5
|
+
const {
|
|
6
|
+
open
|
|
7
|
+
} = require("sqlite");
|
|
8
|
+
const { shareData } = require('../../commands/share_data');
|
|
9
|
+
|
|
10
|
+
module.exports = class SimpleSqliteCache {
|
|
11
|
+
constructor(location) {
|
|
12
|
+
this.location = location || path.resolve(shareData.AUTOMATOR_APPDATA, ".simple_sqlite_cache.db");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async setCache(key, val) {
|
|
16
|
+
// await (await this.getDB()).exec(`INSERT INTO tbl VALUES ("${encodeURIComponent(key)}", "${encodeURIComponent(val)}")`);
|
|
17
|
+
await (await this.getDB()).exec(`REPLACE INTO tbl VALUES ("${encodeURIComponent(key)}", "${encodeURIComponent(val)}")`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getCache(key) {
|
|
21
|
+
let ret = await (await this.getDB()).get('SELECT value FROM tbl WHERE key = ?', encodeURIComponent(key));
|
|
22
|
+
return ret && decodeURIComponent(ret.value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getDB() {
|
|
26
|
+
if (!this.db) {
|
|
27
|
+
this.db = await open({
|
|
28
|
+
filename: this.location,
|
|
29
|
+
driver: sqlite3.cached.Database,
|
|
30
|
+
});
|
|
31
|
+
await this.db.exec('CREATE TABLE IF NOT EXISTS tbl (\
|
|
32
|
+
key TEXT,\
|
|
33
|
+
value TEXT,\
|
|
34
|
+
PRIMARY KEY (key)\
|
|
35
|
+
)');
|
|
36
|
+
}
|
|
37
|
+
return this.db;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async getSize() {
|
|
41
|
+
return (await (await this.getDB()).get('SELECT count(key) FROM tbl'))['count(key)'];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const {read_cfg, write_with_type} = require("../file_tool");
|
|
2
|
+
const {exec_shell} = require("../shell_tool");
|
|
3
|
+
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const { error, warn } = require("../log_tool");
|
|
7
|
+
module.exports = class SimpleSVNCache {
|
|
8
|
+
constructor(location) {
|
|
9
|
+
this.location = location;
|
|
10
|
+
this.basename = path.basename(this.location);
|
|
11
|
+
this.cwd = path.dirname(this.location);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async setCache(key, val) {
|
|
15
|
+
await this.updateCache();
|
|
16
|
+
this.StorageCache[key] = val;
|
|
17
|
+
try {
|
|
18
|
+
fs.writeFileSync(this.location, require("yaml").stringify(this.StorageCache), "utf-8");
|
|
19
|
+
await exec_shell({
|
|
20
|
+
cmd: `svn add ${this.basename} --force`,
|
|
21
|
+
cwd: this.cwd,
|
|
22
|
+
});
|
|
23
|
+
await exec_shell({
|
|
24
|
+
cmd: `svn commit ${this.basename} -m "AutoSet ${key}=${JSON.stringify(val).replace(/"/g, "'").substring(0, 50)}"`,
|
|
25
|
+
cwd: this.cwd,
|
|
26
|
+
});
|
|
27
|
+
} catch (e) {
|
|
28
|
+
warn(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getCache(key) {
|
|
33
|
+
await this.updateCache();
|
|
34
|
+
return this.StorageCache[key];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async updateCache() {
|
|
38
|
+
await exec_shell({
|
|
39
|
+
cmd: `svn update ${this.basename}`,
|
|
40
|
+
cwd: this.location,
|
|
41
|
+
});
|
|
42
|
+
this.StorageCache = require("yaml").parse(fs.readFileSync(this.location, "utf-8"));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getSize() {
|
|
46
|
+
this.updateCache();
|
|
47
|
+
return Object.keys(this.StorageCache).length;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const {read_cfg, write_with_type} = require("../file_tool");
|
|
2
|
+
const {exec_shell} = require("../shell_tool");
|
|
3
|
+
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { error, warn } = require("../log_tool");
|
|
6
|
+
module.exports = class SVNCache {
|
|
7
|
+
constructor(location) {
|
|
8
|
+
this.location = location;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async setCache(key, val) {
|
|
12
|
+
key = encodeURIComponent(key);
|
|
13
|
+
let basename = key + ".yml";
|
|
14
|
+
let fullpath = path.join(this.location, basename);
|
|
15
|
+
try {
|
|
16
|
+
await write_with_type(val, fullpath);
|
|
17
|
+
await exec_shell({
|
|
18
|
+
cmd: `svn add ${basename} --force`,
|
|
19
|
+
cwd: this.location,
|
|
20
|
+
});
|
|
21
|
+
await exec_shell({
|
|
22
|
+
cmd: `svn commit ${basename} -m "AutoSet ${basename}=${JSON.stringify(val).replace(/"/g, "'").substring(0, 50)}"`,
|
|
23
|
+
cwd: this.location,
|
|
24
|
+
});
|
|
25
|
+
} catch (e) {
|
|
26
|
+
warn(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getCache(key) {
|
|
31
|
+
key = encodeURIComponent(key);
|
|
32
|
+
let basename = key + ".yml";
|
|
33
|
+
let fullpath = path.join(this.location, basename);
|
|
34
|
+
await exec_shell({
|
|
35
|
+
cmd: `svn update ${basename}`,
|
|
36
|
+
cwd: this.location,
|
|
37
|
+
});
|
|
38
|
+
return await read_cfg(fullpath);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const LocalCache = require("./cache/local_cache");
|
|
2
|
+
const RawCache = require("./cache/raw_cache");
|
|
3
|
+
const SVNCache = require("./cache/svn_cache");
|
|
4
|
+
const SimpleLocalCache = require("./cache/simple_local_cache");
|
|
5
|
+
const SimpleSVNCache = require("./cache/simple_svn_cache");
|
|
6
|
+
// const SimpleSqliteCache = require("./cache/simple_sqlite_cache");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const type2param2mgr = {};
|
|
10
|
+
const type2mgrcls = {
|
|
11
|
+
"raw": RawCache,
|
|
12
|
+
"local": LocalCache,
|
|
13
|
+
"svn": SVNCache,
|
|
14
|
+
"simple_local": SimpleLocalCache,
|
|
15
|
+
"simple_svn": SimpleSVNCache,
|
|
16
|
+
// "simple_sqlite": SimpleSqliteCache,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function getCacheMgr(type, param) {
|
|
20
|
+
let param2mgr = type2param2mgr[type] || (type2param2mgr[type] = {});
|
|
21
|
+
let mgr = param2mgr[param] || (param2mgr[param] = new (type2mgrcls[type])(param));
|
|
22
|
+
return mgr;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// const defaultCache = new LocalCache();
|
|
26
|
+
// const defaultCache = new SVNFileCache();
|
|
27
|
+
|
|
28
|
+
async function setCache(key, val, type, param) {
|
|
29
|
+
if (!type) {
|
|
30
|
+
type = "local";
|
|
31
|
+
}
|
|
32
|
+
const cacheMgr = getCacheMgr(type, param);
|
|
33
|
+
return await cacheMgr.setCache(key, val);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function getCache(key, type, param) {
|
|
37
|
+
if (!type) {
|
|
38
|
+
type = "local";
|
|
39
|
+
}
|
|
40
|
+
const cacheMgr = getCacheMgr(type, param);
|
|
41
|
+
return await cacheMgr.getCache(key);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function getSize(type, param) {
|
|
45
|
+
const cacheMgr = getCacheMgr(type, param);
|
|
46
|
+
return await cacheMgr.getSize();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
setCache,
|
|
51
|
+
getCache,
|
|
52
|
+
getSize,
|
|
53
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const process = require("process");
|
|
2
|
+
const { stdout_columns, clear_line_end, shareData } = require("../commands/share_data");
|
|
3
|
+
const { clearLine } = require("./interaction_tool");
|
|
4
|
+
const { omit, omit_offset, write } = require("./log_tool");
|
|
5
|
+
const { alignNumber, formatByteSize, alignStr, Alignment } = require("./transform_tool");
|
|
6
|
+
|
|
7
|
+
const color_cfg = [
|
|
8
|
+
"cyan",
|
|
9
|
+
"green",
|
|
10
|
+
"white",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {*} cur
|
|
17
|
+
* @param {*} total
|
|
18
|
+
* @param {{
|
|
19
|
+
* char_count?: number,
|
|
20
|
+
* char1?: string,
|
|
21
|
+
* char2?: string,
|
|
22
|
+
* desc?: string,
|
|
23
|
+
* show_progress_txt?: boolean,
|
|
24
|
+
* color?: string = "reset",
|
|
25
|
+
* depth?: number = 0,
|
|
26
|
+
* align?: boolean = false,
|
|
27
|
+
* }} options
|
|
28
|
+
*/
|
|
29
|
+
function progress(cur, total, options, important) {
|
|
30
|
+
if (shareData.FULL_AUTOMATIC && !important) {
|
|
31
|
+
write(".");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let depth = options && options.depth || 0;
|
|
35
|
+
depth = Math.min(depth, 5);
|
|
36
|
+
let color = options.color || color_cfg[Math.min(color_cfg.length - 1, depth)];
|
|
37
|
+
let padding = 4;
|
|
38
|
+
options = Object.assign({}, {
|
|
39
|
+
char_count: 30,
|
|
40
|
+
char1: "━"[color],
|
|
41
|
+
char2: "━"["gray"],
|
|
42
|
+
desc: "",
|
|
43
|
+
show_progress_txt: true,
|
|
44
|
+
}, options);
|
|
45
|
+
// options.color = "gray";
|
|
46
|
+
let { char_count, char1, char2, desc, show_progress_txt, format_bytes } = options;
|
|
47
|
+
char_count -= depth * padding;
|
|
48
|
+
if (char_count <= 0)
|
|
49
|
+
char_count = 10;
|
|
50
|
+
percent = cur >= total ? 100 : alignNumber(Math.floor(100 * cur / total), 100);
|
|
51
|
+
char_num = cur >= total ? char_count : Math.floor(char_count * cur / total);
|
|
52
|
+
if (!format_bytes) {
|
|
53
|
+
curr_total = `(${alignNumber(cur, total > 0 ? total : cur)}/${total > 0 ? total : "∞"})`;
|
|
54
|
+
} else {
|
|
55
|
+
cur = formatByteSize(cur);
|
|
56
|
+
total = formatByteSize(total);
|
|
57
|
+
curr_total = `(${alignNumber(cur, total)}/${total})`;
|
|
58
|
+
}
|
|
59
|
+
chars1 = char1.repeat(char_num);
|
|
60
|
+
chars2 = char2.repeat(char_count - char_num);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
let progressChars;
|
|
64
|
+
if (show_progress_txt)
|
|
65
|
+
progressChars = `${chars1}${chars2} ${percent}% ${curr_total} ${desc}`;
|
|
66
|
+
else
|
|
67
|
+
progressChars = `${chars1}${chars2} ${desc}`;
|
|
68
|
+
if (!shareData.FULL_AUTOMATIC) {
|
|
69
|
+
progressChars = "\r" + progressChars[color] + clear_line_end;
|
|
70
|
+
} else {
|
|
71
|
+
progressChars = progressChars + "\n";
|
|
72
|
+
}
|
|
73
|
+
if (options.align) {
|
|
74
|
+
// progressChars = `${alignStr(progressChars, stdout_columns, {alignment: Alignment.LEFT})}`;
|
|
75
|
+
} else {
|
|
76
|
+
// // 清空本行
|
|
77
|
+
// clearLine();
|
|
78
|
+
// write(`${progressChars}`)
|
|
79
|
+
}
|
|
80
|
+
write(progressChars);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
progress,
|
|
85
|
+
};
|