jsir 2.2.3 → 2.2.5
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/cmd/oaa.js +26 -10
- package/deps/util.js +36 -27
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -1329,19 +1329,20 @@ const keywordDef = {
|
|
|
1329
1329
|
},
|
|
1330
1330
|
short: 'p'
|
|
1331
1331
|
},
|
|
1332
|
-
|
|
1333
|
-
comment: '
|
|
1332
|
+
exe: {
|
|
1333
|
+
comment: 'System execute',
|
|
1334
1334
|
exeFn: (args) => {
|
|
1335
|
-
let
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1335
|
+
let cmd = ''
|
|
1336
|
+
let _args = []
|
|
1337
|
+
if (args.length > 0) {
|
|
1338
|
+
cmd = args[0]
|
|
1339
|
+
}
|
|
1340
|
+
if (args.length > 1) {
|
|
1341
|
+
_args = args.slice(1)
|
|
1341
1342
|
}
|
|
1342
|
-
ei(`cd "${$workspaceMap[global.$defaultSpace]}"
|
|
1343
|
+
ei(`cd "${$workspaceMap[global.$defaultSpace]}";${cmd}`, _args, true)
|
|
1343
1344
|
},
|
|
1344
|
-
short: '
|
|
1345
|
+
short: 'E'
|
|
1345
1346
|
},
|
|
1346
1347
|
log: {
|
|
1347
1348
|
comment: 'View log (type[[lt][le]], index)',
|
|
@@ -1371,6 +1372,18 @@ const keywordDef = {
|
|
|
1371
1372
|
ei(cmdStr, [path], true)
|
|
1372
1373
|
},
|
|
1373
1374
|
short: 'l'
|
|
1375
|
+
},
|
|
1376
|
+
debug: {
|
|
1377
|
+
comment: 'debug mode',
|
|
1378
|
+
exeFn: (args) => {
|
|
1379
|
+
if (global.$DEBUG) {
|
|
1380
|
+
delTips("DEBUG")
|
|
1381
|
+
} else {
|
|
1382
|
+
global.$DEBUG = true;
|
|
1383
|
+
setTips("DEBUG", "DEBUG", () => delete global.$DEBUG);
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
short: 'D'
|
|
1374
1387
|
}
|
|
1375
1388
|
}
|
|
1376
1389
|
|
|
@@ -2023,6 +2036,9 @@ async function evalText($text = '', $cmdName = '', $args = []) {
|
|
|
2023
2036
|
let $require = async (matchItem) => {
|
|
2024
2037
|
return await _requireSource(currSpace, matchItem)
|
|
2025
2038
|
}
|
|
2039
|
+
// 兼容module.exports
|
|
2040
|
+
$text.replace(/^module\.exports\s*=\s*/m, 'return ')
|
|
2041
|
+
|
|
2026
2042
|
return await evalCode(addErrorTag($text), $cmdName, $args,
|
|
2027
2043
|
$data, $file,
|
|
2028
2044
|
$require, $requires,
|
package/deps/util.js
CHANGED
|
@@ -29,9 +29,9 @@ class SyncQueue {
|
|
|
29
29
|
this.isProcessing = false;
|
|
30
30
|
}
|
|
31
31
|
// 添加任务到队列
|
|
32
|
-
enqueue(task) {
|
|
32
|
+
async enqueue(task) {
|
|
33
33
|
this.queue.push(task);
|
|
34
|
-
this.processQueue();
|
|
34
|
+
await this.processQueue();
|
|
35
35
|
}
|
|
36
36
|
// 处理队列
|
|
37
37
|
async processQueue() {
|
|
@@ -55,10 +55,10 @@ function syncQueue(task, key) {
|
|
|
55
55
|
同步队列分发器
|
|
56
56
|
task: function
|
|
57
57
|
key: 根据key值区分不同队列, 可选
|
|
58
|
-
return
|
|
58
|
+
return Promise
|
|
59
59
|
`
|
|
60
60
|
let queue = getOrFn(syncQueues, trim(key), () => new SyncQueue())
|
|
61
|
-
queue.enqueue(task)
|
|
61
|
+
return queue.enqueue(task)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const $log = createLimitLogger(`${setting.name}.log`, {
|
|
@@ -85,9 +85,12 @@ const draftLog = str => {
|
|
|
85
85
|
_globalDraft(`---------${now.getTime()} ${timeStr(null, now)}\n${trimEmptyLine(str)}`)
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
const $fnCache = {}
|
|
89
88
|
|
|
90
89
|
// fix console begin
|
|
90
|
+
function debugStr(str) {
|
|
91
|
+
return `\x1B[2m${str}\x1B[0m`
|
|
92
|
+
}
|
|
93
|
+
|
|
91
94
|
function infoStr(str) {
|
|
92
95
|
return `\x1B[32m${str}\x1B[39m`
|
|
93
96
|
}
|
|
@@ -169,13 +172,9 @@ const _consoleFns= {
|
|
|
169
172
|
fn: _console.error,
|
|
170
173
|
args: args => [errorStr('[error]'), ...dealLevelArgs(errorStr, args)]
|
|
171
174
|
},
|
|
172
|
-
dir: {
|
|
173
|
-
fn: _console.dir,
|
|
174
|
-
args: args => args
|
|
175
|
-
},
|
|
176
175
|
debug: {
|
|
177
176
|
fn: _console.debug,
|
|
178
|
-
args: args => args
|
|
177
|
+
args: args => [debugStr('[debug]'), ...dealLevelArgs(debugStr, args)]
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
|
|
@@ -215,7 +214,13 @@ function createConsole(uniqueName) {
|
|
|
215
214
|
if (global.$newInput) {
|
|
216
215
|
quite = true;
|
|
217
216
|
}
|
|
217
|
+
if ('debug' === key && !global.$DEBUG) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
218
220
|
if (uniqueName && quite) {
|
|
221
|
+
if ((key === 'table' || key === 'nable') && typeof args[0] === "object") {
|
|
222
|
+
args = ['', ...args]
|
|
223
|
+
}
|
|
219
224
|
let _args = _consoleFns[key].args(args);
|
|
220
225
|
if ("error" === key) {
|
|
221
226
|
result.$log(..._args)
|
|
@@ -493,7 +498,7 @@ function timeStr(fmt, date) {
|
|
|
493
498
|
function vl(obj) {
|
|
494
499
|
let type= typeof obj;
|
|
495
500
|
if (type === 'number') {
|
|
496
|
-
return !Number.isNaN(obj)
|
|
501
|
+
return !Number.isNaN(obj);
|
|
497
502
|
}
|
|
498
503
|
if (typeof obj === 'string') {
|
|
499
504
|
obj = obj.trim()
|
|
@@ -509,31 +514,29 @@ function getVl(...obj) {
|
|
|
509
514
|
}
|
|
510
515
|
}
|
|
511
516
|
|
|
512
|
-
const
|
|
513
|
-
async function cacheFn(key, fn, validMs, awaitRefresh = true) {
|
|
517
|
+
const $fnCache = {}
|
|
518
|
+
async function cacheFn(key, fn, validMs = 0, awaitRefresh = true) {
|
|
514
519
|
getOr($fnCache, key, {
|
|
515
520
|
validMsTime: 0
|
|
516
521
|
});
|
|
517
522
|
if (Date.now() <= $fnCache[key].validMsTime) {
|
|
518
523
|
// do nothing
|
|
519
524
|
} else {
|
|
520
|
-
$fnCache[key].validMsTime =
|
|
521
|
-
|
|
525
|
+
$fnCache[key].validMsTime = Infinity;
|
|
526
|
+
$fnCache[key].promise = (async () => {
|
|
522
527
|
let val;
|
|
523
528
|
try {
|
|
524
529
|
val = await fn()
|
|
525
530
|
} finally {
|
|
526
531
|
$fnCache[key].validMsTime = 0
|
|
527
532
|
}
|
|
528
|
-
$fnCache[key] =
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
validMsTime: Date.now() + (validMs || Date.now())
|
|
532
|
-
}
|
|
533
|
+
$fnCache[key].val = val;
|
|
534
|
+
$fnCache[key].valInit = true;
|
|
535
|
+
$fnCache[key].validMsTime = Date.now() + validMs;
|
|
533
536
|
})();
|
|
534
537
|
}
|
|
535
538
|
if (awaitRefresh || !$fnCache[key].valInit) {
|
|
536
|
-
await
|
|
539
|
+
await $fnCache[key].promise;
|
|
537
540
|
}
|
|
538
541
|
return $fnCache[key].val
|
|
539
542
|
}
|
|
@@ -915,11 +918,20 @@ function toBigNum(str) {
|
|
|
915
918
|
}
|
|
916
919
|
|
|
917
920
|
function reget(str, reg) {
|
|
921
|
+
`
|
|
922
|
+
reget(/aaa(bbb)ccc/, str)
|
|
923
|
+
return bbb
|
|
924
|
+
`
|
|
918
925
|
let r = reg.exec(str)
|
|
919
926
|
return r ? (r[1] || "").trim(): ""
|
|
920
927
|
}
|
|
921
928
|
|
|
922
929
|
function regEach(str, reg, fn) {
|
|
930
|
+
`
|
|
931
|
+
regEach(/aaa(bbb)ccc/, str, fn)
|
|
932
|
+
fn([aaa(bbb)ccc, bbb])
|
|
933
|
+
return void
|
|
934
|
+
`
|
|
923
935
|
let r = reg.exec(str)
|
|
924
936
|
while (r != null) {
|
|
925
937
|
fn(r)
|
|
@@ -1325,11 +1337,7 @@ async function setCbText(str) {
|
|
|
1325
1337
|
}
|
|
1326
1338
|
|
|
1327
1339
|
async function sleep(milliseconds) {
|
|
1328
|
-
return new Promise(resolve =>
|
|
1329
|
-
setTimeout(() => {
|
|
1330
|
-
resolve()
|
|
1331
|
-
}, milliseconds)
|
|
1332
|
-
})
|
|
1340
|
+
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
1333
1341
|
}
|
|
1334
1342
|
|
|
1335
1343
|
function splitArray(items, size) {
|
|
@@ -1831,5 +1839,6 @@ module.exports = {
|
|
|
1831
1839
|
toUniqueName,
|
|
1832
1840
|
isJsirFileName,
|
|
1833
1841
|
toJsirFileName,
|
|
1834
|
-
fileJson
|
|
1842
|
+
fileJson,
|
|
1843
|
+
debugStr
|
|
1835
1844
|
}
|