jsir 2.6.11 → 2.6.13
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 +84 -57
- package/deps/evalCode.js +2 -8
- package/deps/room.js +3 -3
- package/deps/setting.js +4 -2
- package/deps/util.js +97 -44
- package/package.json +2 -3
package/cmd/oaa.js
CHANGED
|
@@ -4,7 +4,7 @@ const {
|
|
|
4
4
|
getLibDataDir, trim, regEach, getConfig, mkdir, reget,
|
|
5
5
|
getCbText, e, sleep, objDataFile, vl, md5, BigNumber,
|
|
6
6
|
arrayDataFile, infoStr, warnStr,
|
|
7
|
-
getInfo,
|
|
7
|
+
getInfo, msgStr, getType,
|
|
8
8
|
isMatch, draftQuery, setConfig,
|
|
9
9
|
getTextComments, importG, requireG,
|
|
10
10
|
clearConsole, trimText, getFnArgsStr,
|
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
getFullPath, parseUniqueName, toUniqueName, isJsirFileName, toJsirFileName,
|
|
14
14
|
getAlias, wrapperJsirText, eia, getKeyTips, getValTips, getJsirTypeKey,
|
|
15
15
|
createDetachedProcess, interceptStdStreams,
|
|
16
|
-
draftModify, isRunningInBackground, fileJson, fileLock, processLock, cleanFileLocks, getMd5Key
|
|
16
|
+
draftModify, isRunningInBackground, fileJson, fileLock, processLock, cleanFileLocks, getMd5Key, terminalTitle
|
|
17
17
|
} = $lib;
|
|
18
18
|
const _args = process.argv.slice(2).map(trim);
|
|
19
19
|
const evalCode = require('../deps/evalCode')
|
|
@@ -131,10 +131,24 @@ const $data = {
|
|
|
131
131
|
`
|
|
132
132
|
get or set by async function
|
|
133
133
|
`
|
|
134
|
-
if (
|
|
135
|
-
return
|
|
134
|
+
if (vl(_data[key])) {
|
|
135
|
+
return _dealOnLazyGet(key, onLazyTempCode);
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
let result = null;
|
|
138
|
+
await processLock('gafs:' + key, async () => {
|
|
139
|
+
if (!vl(_data[key])) {
|
|
140
|
+
result = _dataSet(key, await fn(), onLazyTempCode)
|
|
141
|
+
} else {
|
|
142
|
+
result = _dealOnLazyGet(key, onLazyTempCode)
|
|
143
|
+
}
|
|
144
|
+
}, async () => {
|
|
145
|
+
if (!vl(_data[key])) {
|
|
146
|
+
return true;
|
|
147
|
+
} else {
|
|
148
|
+
result = _dealOnLazyGet(key, onLazyTempCode)
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
return result;
|
|
138
152
|
},
|
|
139
153
|
set: _dataSet,
|
|
140
154
|
del: (key) => {
|
|
@@ -337,8 +351,8 @@ function initRl(callback, promptStr, hidden) {
|
|
|
337
351
|
})
|
|
338
352
|
_rl.on("SIGINT", async () => {
|
|
339
353
|
if (_noAppendNextLine) {
|
|
340
|
-
|
|
341
|
-
|
|
354
|
+
setting.promptId = Date.now();
|
|
355
|
+
await delTips();
|
|
342
356
|
} else {
|
|
343
357
|
_rl._writeToOutput = origin_writeToOutput;
|
|
344
358
|
_haveWrapperInput = true;
|
|
@@ -350,12 +364,12 @@ function initRl(callback, promptStr, hidden) {
|
|
|
350
364
|
}
|
|
351
365
|
origin_writeToOutput = _rl._writeToOutput
|
|
352
366
|
if (promptStr !== '') {
|
|
353
|
-
promptStr = promptStr || (
|
|
367
|
+
promptStr = promptStr || (callback !== wrapperInput ? "-> ":"")
|
|
354
368
|
if (promptStr) {
|
|
355
369
|
promptStr = infoStr(promptStr);
|
|
356
370
|
} else {
|
|
357
|
-
if (
|
|
358
|
-
|
|
371
|
+
if (setting.newError) {
|
|
372
|
+
setting.newError = false;
|
|
359
373
|
promptStr = errorStr(defaultPromptStr())
|
|
360
374
|
} else {
|
|
361
375
|
promptStr = infoStr(defaultPromptStr())
|
|
@@ -394,6 +408,7 @@ function closeRl() {
|
|
|
394
408
|
}
|
|
395
409
|
|
|
396
410
|
function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
411
|
+
callback = callback || wrapperInput;
|
|
397
412
|
if (!setting.enableNextLine) {
|
|
398
413
|
console.$log(warnStr("[warn]"), "NextLine Disabled");
|
|
399
414
|
resolve(null);
|
|
@@ -405,15 +420,13 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
|
405
420
|
return;
|
|
406
421
|
}
|
|
407
422
|
initRl(callback, promptStr, hidden);
|
|
408
|
-
|
|
409
|
-
|
|
423
|
+
if (callback === wrapperInput) {
|
|
424
|
+
terminalTitle()
|
|
425
|
+
} else {
|
|
410
426
|
_haveWrapperInput = false
|
|
411
427
|
}
|
|
412
|
-
if (isJsirNext) {
|
|
413
|
-
global.$newInput = true;
|
|
414
|
-
}
|
|
415
428
|
end = trim(end)
|
|
416
|
-
let
|
|
429
|
+
let inputs = []
|
|
417
430
|
let lineHandler = async line => {
|
|
418
431
|
let textLine = line
|
|
419
432
|
line = trim(line)
|
|
@@ -422,33 +435,32 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
|
422
435
|
end = line
|
|
423
436
|
line = ''
|
|
424
437
|
} else if (line !== end) {
|
|
425
|
-
|
|
438
|
+
inputs.push(textLine)
|
|
426
439
|
}
|
|
427
440
|
} else {
|
|
428
|
-
|
|
441
|
+
inputs.push(line)
|
|
429
442
|
}
|
|
430
|
-
if (trim(textLine) && (hidden ||
|
|
443
|
+
if (trim(textLine) && (hidden || callback !== wrapperInput)) {
|
|
431
444
|
_rl.history = _rl.history.slice(1)
|
|
432
445
|
}
|
|
433
446
|
if (!isText || line === end) {
|
|
447
|
+
let promptId = setting.promptId;
|
|
434
448
|
_haveWrapperInput = true;
|
|
435
449
|
closeRl()
|
|
436
|
-
inputStr =
|
|
437
|
-
if (!isText && /^\d+$/.test(inputStr) && /^\s+/.test(textLine)
|
|
450
|
+
let inputStr = inputs.join("\n");
|
|
451
|
+
if (callback === wrapperInput && !isText && /^\d+$/.test(inputStr) && /^\s+/.test(textLine)) {
|
|
438
452
|
inputStr = '.e ' + inputStr;
|
|
439
453
|
}
|
|
440
|
-
let pro = (callback || wrapperInput)(inputStr);
|
|
441
|
-
resolve(inputStr);
|
|
442
454
|
try {
|
|
443
|
-
await
|
|
455
|
+
resolve(await callback(inputStr));
|
|
444
456
|
} finally {
|
|
445
|
-
if (
|
|
457
|
+
if (callback === wrapperInput) {
|
|
446
458
|
if (!_noAppendNextLine) {
|
|
447
459
|
if (/^\s+$/.test(textLine)) {
|
|
448
460
|
clearConsole(textLine.length - 1)
|
|
449
461
|
filterCmdAndList();
|
|
450
462
|
nextLine(null, defaultPromptStr(true))
|
|
451
|
-
} else {
|
|
463
|
+
} else if (promptId === setting.promptId) {
|
|
452
464
|
nextLine()
|
|
453
465
|
}
|
|
454
466
|
}
|
|
@@ -460,6 +472,9 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
|
460
472
|
_rl.removeAllListeners('line')
|
|
461
473
|
_rl.on('line', lineHandler)
|
|
462
474
|
_rl.prompt()
|
|
475
|
+
if (callback === wrapperInput) {
|
|
476
|
+
setting.promptId = Date.now();
|
|
477
|
+
}
|
|
463
478
|
setting.lastOutput = null;
|
|
464
479
|
}
|
|
465
480
|
|
|
@@ -612,10 +627,15 @@ async function wrapperInput(str, packOutput = false) {
|
|
|
612
627
|
if (packOutput) {
|
|
613
628
|
setting.enterOutputs = []
|
|
614
629
|
}
|
|
630
|
+
const promptId = setting.promptId;
|
|
615
631
|
try {
|
|
616
632
|
await _wrapperInput(str);
|
|
617
633
|
} catch (e) {
|
|
618
|
-
|
|
634
|
+
if (promptId === setting.promptId) {
|
|
635
|
+
console.error(e)
|
|
636
|
+
} else {
|
|
637
|
+
console.$error(e)
|
|
638
|
+
}
|
|
619
639
|
}
|
|
620
640
|
if (packOutput) {
|
|
621
641
|
let outputs = setting.enterOutputs || [];
|
|
@@ -639,16 +659,16 @@ async function _wrapperInput(str) {
|
|
|
639
659
|
if (!str) {
|
|
640
660
|
return;
|
|
641
661
|
}
|
|
642
|
-
|
|
662
|
+
setting.newError = false;
|
|
643
663
|
str = wrapperAlias(str);
|
|
644
664
|
|
|
645
665
|
if (/^[`'"]/.test(str)) {
|
|
646
|
-
let fstr = str.
|
|
666
|
+
let fstr = str.substring(0, 1);
|
|
647
667
|
if (fstr === '`') {
|
|
648
|
-
let text = str.
|
|
668
|
+
let text = str.substring(1) + "\n" + await nextText(line => line, fstr)
|
|
649
669
|
await wrapperInput(text)
|
|
650
670
|
} else {
|
|
651
|
-
let fLine = trim(str.
|
|
671
|
+
let fLine = trim(str.substring(1))
|
|
652
672
|
if (fLine) {
|
|
653
673
|
if (/\s+[+-]$/.test(fLine)) {
|
|
654
674
|
console.log((await draftModify(fLine)).join("\n"))
|
|
@@ -701,6 +721,7 @@ async function runInit(uniqueName, args) {
|
|
|
701
721
|
if (arg === '-') {
|
|
702
722
|
await offServer(uniqueName)
|
|
703
723
|
} else {
|
|
724
|
+
console.$log(`Execute ${uniqueName}`);
|
|
704
725
|
let exportLib = await _requireSource(setting.defaultSpace, uniqueName, true);
|
|
705
726
|
if (typeof exportLib === "function") {
|
|
706
727
|
await execLibFn(exportLib, args)
|
|
@@ -875,7 +896,7 @@ function wrapperClass(lines, wrapperFn, trimClass = true) {
|
|
|
875
896
|
inClass = true;
|
|
876
897
|
className = reget(line, /^class\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
877
898
|
continue
|
|
878
|
-
} else if (inClass && line.startsWith("}")) {
|
|
899
|
+
} else if (inClass && line.startsWith("}") && line.trim() === "}") {
|
|
879
900
|
inClass = false
|
|
880
901
|
results.push(...wrapperFn(className, classLines));
|
|
881
902
|
|
|
@@ -930,7 +951,7 @@ function dealStarCmd(rows, cmd, filterStr) {
|
|
|
930
951
|
}
|
|
931
952
|
|
|
932
953
|
// Capture single-line comments
|
|
933
|
-
if (line.trim().startsWith('//')) {
|
|
954
|
+
if (line.trim().startsWith('//') || line.trim().startsWith("@")) {
|
|
934
955
|
potentialComments.push(line);
|
|
935
956
|
}
|
|
936
957
|
|
|
@@ -953,7 +974,7 @@ function dealStarCmd(rows, cmd, filterStr) {
|
|
|
953
974
|
}
|
|
954
975
|
|
|
955
976
|
// Check for function end and process
|
|
956
|
-
if (fnName && line.startsWith("}") && capturingFunction) {
|
|
977
|
+
if (fnName && line.startsWith("}") && line.trim() === "}" && capturingFunction) {
|
|
957
978
|
let functionContent = functionLines.join('\n');
|
|
958
979
|
let commentContent = trimText(comments.join('\n'));
|
|
959
980
|
let row = getInfo(functionContent, fnName, fnType);
|
|
@@ -968,7 +989,8 @@ function dealStarCmd(rows, cmd, filterStr) {
|
|
|
968
989
|
}
|
|
969
990
|
|
|
970
991
|
// If not capturing function, reset potential comments
|
|
971
|
-
if (!capturingFunction && !inMultiLineComment && line.trim() !== ''
|
|
992
|
+
if (!capturingFunction && !inMultiLineComment && line.trim() !== ''
|
|
993
|
+
&& !line.trim().startsWith('//') && !line.trim().startsWith('@')) {
|
|
972
994
|
potentialComments = [];
|
|
973
995
|
}
|
|
974
996
|
}
|
|
@@ -1039,7 +1061,7 @@ function delTipsByIndex(idxs) {
|
|
|
1039
1061
|
console.warn("no items")
|
|
1040
1062
|
return;
|
|
1041
1063
|
}
|
|
1042
|
-
delTips(...params)
|
|
1064
|
+
return delTips(...params)
|
|
1043
1065
|
}
|
|
1044
1066
|
|
|
1045
1067
|
function getPackageVersion(space, name) {
|
|
@@ -1185,8 +1207,8 @@ const keywordDef = {
|
|
|
1185
1207
|
},
|
|
1186
1208
|
clear: {
|
|
1187
1209
|
comment: 'Clear task',
|
|
1188
|
-
exeFn: (args) => {
|
|
1189
|
-
delTipsByIndex(args.filter(i => i))
|
|
1210
|
+
exeFn: async (args) => {
|
|
1211
|
+
await delTipsByIndex(args.filter(i => i))
|
|
1190
1212
|
},
|
|
1191
1213
|
args: {
|
|
1192
1214
|
tipIndex: 'left prompt index, can be separated by spaces for multiple'
|
|
@@ -1550,11 +1572,11 @@ const keywordDef = {
|
|
|
1550
1572
|
},
|
|
1551
1573
|
quit: {
|
|
1552
1574
|
comment: 'Exit',
|
|
1553
|
-
exeFn: (args) => {
|
|
1575
|
+
exeFn: async (args) => {
|
|
1554
1576
|
Room.offRoom();
|
|
1555
|
-
delTips();
|
|
1556
|
-
console.log(infoStr("Bye!"));
|
|
1577
|
+
await delTips();
|
|
1557
1578
|
_noAppendNextLine = true;
|
|
1579
|
+
console.log(infoStr("Bye!"));
|
|
1558
1580
|
},
|
|
1559
1581
|
short: 'q'
|
|
1560
1582
|
},
|
|
@@ -1625,7 +1647,7 @@ const keywordDef = {
|
|
|
1625
1647
|
},
|
|
1626
1648
|
debug: {
|
|
1627
1649
|
comment: 'debug mode',
|
|
1628
|
-
exeFn: (args) => {
|
|
1650
|
+
exeFn: async (args) => {
|
|
1629
1651
|
if ('+' === args[0]) {
|
|
1630
1652
|
if (!global.$DEBUG) {
|
|
1631
1653
|
global.$DEBUG = true;
|
|
@@ -1633,11 +1655,11 @@ const keywordDef = {
|
|
|
1633
1655
|
}
|
|
1634
1656
|
} else if ('-' === args[0]) {
|
|
1635
1657
|
if (global.$DEBUG) {
|
|
1636
|
-
delTips("DEBUG")
|
|
1658
|
+
await delTips("DEBUG")
|
|
1637
1659
|
}
|
|
1638
1660
|
} else {
|
|
1639
1661
|
if (global.$DEBUG) {
|
|
1640
|
-
delTips("DEBUG")
|
|
1662
|
+
await delTips("DEBUG")
|
|
1641
1663
|
} else {
|
|
1642
1664
|
global.$DEBUG = true;
|
|
1643
1665
|
setTips("DEBUG", "DEBUG", () => delete global.$DEBUG);
|
|
@@ -1648,7 +1670,7 @@ const keywordDef = {
|
|
|
1648
1670
|
},
|
|
1649
1671
|
test: {
|
|
1650
1672
|
comment: 'test mode',
|
|
1651
|
-
exeFn: (args) => {
|
|
1673
|
+
exeFn: async (args) => {
|
|
1652
1674
|
if ('+' === args[0]) {
|
|
1653
1675
|
if (!global.$TEST) {
|
|
1654
1676
|
global.$TEST = true;
|
|
@@ -1656,11 +1678,11 @@ const keywordDef = {
|
|
|
1656
1678
|
}
|
|
1657
1679
|
} else if ('-' === args[0]) {
|
|
1658
1680
|
if (global.$TEST) {
|
|
1659
|
-
delTips("TEST")
|
|
1681
|
+
await delTips("TEST")
|
|
1660
1682
|
}
|
|
1661
1683
|
} else {
|
|
1662
1684
|
if (global.$TEST) {
|
|
1663
|
-
delTips("TEST")
|
|
1685
|
+
await delTips("TEST")
|
|
1664
1686
|
} else {
|
|
1665
1687
|
global.$TEST = true;
|
|
1666
1688
|
setTips("TEST", "TEST", () => delete global.$TEST);
|
|
@@ -2079,6 +2101,9 @@ async function runCmd(str = '', uniqueName = '', text = '') {
|
|
|
2079
2101
|
}
|
|
2080
2102
|
|
|
2081
2103
|
let scriptArgs = await getScriptArgs(argDef, enrichArgs(str.replace(/^\d+\s*/, '')));
|
|
2104
|
+
if (uniqueName) {
|
|
2105
|
+
console.$log(`Execute ${uniqueName}`);
|
|
2106
|
+
}
|
|
2082
2107
|
return await evalText(text, uniqueName, scriptArgs)
|
|
2083
2108
|
}
|
|
2084
2109
|
|
|
@@ -2279,7 +2304,7 @@ function getArgDef(text, uniqueName) {
|
|
|
2279
2304
|
|
|
2280
2305
|
function filterRequire(currSpace, cmdMatchStr) {
|
|
2281
2306
|
if (typeof cmdMatchStr === 'number') {
|
|
2282
|
-
cmdMatchStr = '0x' +
|
|
2307
|
+
cmdMatchStr = '0x' + BigNumber(cmdMatchStr).toString(16).padStart(8, '0');
|
|
2283
2308
|
}
|
|
2284
2309
|
cmdMatchStr = trim(cmdMatchStr);
|
|
2285
2310
|
|
|
@@ -2423,7 +2448,7 @@ function _addErrorTag(lines) {
|
|
|
2423
2448
|
}
|
|
2424
2449
|
functionEnd = false;
|
|
2425
2450
|
}
|
|
2426
|
-
if (line.startsWith("}") && !functionEnd) {
|
|
2451
|
+
if (line.startsWith("}") && line.trim() === "}" && !functionEnd) {
|
|
2427
2452
|
result[i] = `${wrapperFn.length > 0 ? '},arguments)':''}}catch(e){throw($errorTag(e,$cmdName+'[${fnName}]'))}` + line;
|
|
2428
2453
|
functionEnd = true;
|
|
2429
2454
|
fnName = '';
|
|
@@ -2435,9 +2460,6 @@ function _addErrorTag(lines) {
|
|
|
2435
2460
|
}
|
|
2436
2461
|
|
|
2437
2462
|
async function evalText($text = '', $cmdName = '', $args = {}) {
|
|
2438
|
-
if ($cmdName) {
|
|
2439
|
-
console.$log(`Execute ${$cmdName}`);
|
|
2440
|
-
}
|
|
2441
2463
|
let currSpace;
|
|
2442
2464
|
if ($cmdName) {
|
|
2443
2465
|
let pair = parseUniqueName($cmdName)
|
|
@@ -2464,10 +2486,15 @@ async function evalText($text = '', $cmdName = '', $args = {}) {
|
|
|
2464
2486
|
$homeDir, $lib, _cmdMap);
|
|
2465
2487
|
}
|
|
2466
2488
|
|
|
2467
|
-
|
|
2489
|
+
let sigExitCount = 0
|
|
2490
|
+
async function sigExit() {
|
|
2468
2491
|
if (_noAppendNextLine) {
|
|
2469
|
-
|
|
2470
|
-
|
|
2492
|
+
setting.promptId = Date.now();
|
|
2493
|
+
sigExitCount ++;
|
|
2494
|
+
if (sigExitCount > 1) {
|
|
2495
|
+
process.exit(0);
|
|
2496
|
+
}
|
|
2497
|
+
await delTips();
|
|
2471
2498
|
} else {
|
|
2472
2499
|
nextLine();
|
|
2473
2500
|
}
|
|
@@ -2484,9 +2511,9 @@ process.on('rejectionHandled',function(err){
|
|
|
2484
2511
|
})
|
|
2485
2512
|
process.on('SIGINT', sigExit);
|
|
2486
2513
|
process.on('SIGTERM', sigExit);
|
|
2487
|
-
process.on('beforeExit', function () {
|
|
2514
|
+
process.on('beforeExit', async function () {
|
|
2488
2515
|
if (_noAppendNextLine) {
|
|
2489
|
-
|
|
2516
|
+
terminalTitle(null)
|
|
2490
2517
|
} else {
|
|
2491
2518
|
nextLine();
|
|
2492
2519
|
Room.onRoom()
|
package/deps/evalCode.js
CHANGED
|
@@ -19,23 +19,17 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
|
19
19
|
|
|
20
20
|
const $setTips = $lib.setTips;
|
|
21
21
|
const $delTips = $lib.delTips;
|
|
22
|
-
const $tips =
|
|
23
|
-
set: $lib.setTips,
|
|
24
|
-
del: $lib.delTips,
|
|
25
|
-
has: $lib.hasTips,
|
|
26
|
-
key: $lib.tipKeys
|
|
27
|
-
}
|
|
22
|
+
const $tips = $lib.tipFns;
|
|
28
23
|
const $errorTag = $lib.errorTag;
|
|
29
24
|
const $aop = $lib.aop;
|
|
30
25
|
const $aopAsync = $lib.aopAsync;
|
|
31
26
|
|
|
32
27
|
const $context = {
|
|
33
28
|
$defArgs,
|
|
34
|
-
$data, $config,
|
|
29
|
+
$data, $config, $tips,
|
|
35
30
|
$require, $requires, $import,
|
|
36
31
|
$text, $cmdName, $args,
|
|
37
32
|
$nextLine, $nextText,
|
|
38
|
-
$setTips, $delTips, $tips,
|
|
39
33
|
$enter, $filterCmd,
|
|
40
34
|
$currentSpace, $defaultSpace, $workspaceMap,
|
|
41
35
|
$homeDir, $lib, $cmdMap
|
package/deps/room.js
CHANGED
|
@@ -57,7 +57,7 @@ function onRoom() {
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
res.output = await setting.wrapperInput(req.input, true)
|
|
60
|
-
|
|
60
|
+
setting.promptId = Date.now()
|
|
61
61
|
}
|
|
62
62
|
})
|
|
63
63
|
} catch (e) {
|
|
@@ -297,7 +297,7 @@ async function processTasks() {
|
|
|
297
297
|
if (unHandleKey) {
|
|
298
298
|
console.$log(process.pid, `run task ${unHandleKey}[${defTasks[unHandleKey]}]`)
|
|
299
299
|
await setting.wrapperInput(defTasks[unHandleKey]);
|
|
300
|
-
if (!
|
|
300
|
+
if (!setting.newError) {
|
|
301
301
|
tasks[unHandleKey] = process.pid;
|
|
302
302
|
console.$log(process.pid, `handle task ${unHandleKey}[${defTasks[unHandleKey]}]`)
|
|
303
303
|
}
|
|
@@ -431,7 +431,7 @@ async function initRoomJsir(room) {
|
|
|
431
431
|
lastUpdateTime: setting.roomTime,
|
|
432
432
|
port: setting.server ? setting.server.address()?.port:null,
|
|
433
433
|
services: services,
|
|
434
|
-
newError:
|
|
434
|
+
newError: setting.newError,
|
|
435
435
|
version: packageJson.version,
|
|
436
436
|
upTime: formatUptime()
|
|
437
437
|
}
|
package/deps/setting.js
CHANGED
|
@@ -46,6 +46,8 @@ module.exports = {
|
|
|
46
46
|
serviceReg: /[^a-zA-Z]service[^a-zA-Z]|[^a-zA-Z]service$/i,
|
|
47
47
|
wrapperInput: null,
|
|
48
48
|
lastOutput: null,
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
lastChangeFlag: null,
|
|
50
|
+
terminalTitle: null,
|
|
51
|
+
promptId: Date.now(),
|
|
52
|
+
newError: false
|
|
51
53
|
}
|
package/deps/util.js
CHANGED
|
@@ -6,7 +6,6 @@ const readline = require('readline')
|
|
|
6
6
|
const fs = require('fs')
|
|
7
7
|
const fp = require('fs').promises
|
|
8
8
|
const BigNumber = require('bignumber.js');
|
|
9
|
-
const pad = require('pad');
|
|
10
9
|
const crypto = require('crypto');
|
|
11
10
|
const dayJs = require('dayjs')
|
|
12
11
|
const table = require('console.table')
|
|
@@ -16,9 +15,6 @@ const _types = setting.fileType
|
|
|
16
15
|
const _typeKeys = Object.keys(_types)
|
|
17
16
|
const util = require('util')
|
|
18
17
|
|
|
19
|
-
global.$newInput = false
|
|
20
|
-
global.$newError = false
|
|
21
|
-
|
|
22
18
|
let libDataDir;
|
|
23
19
|
let lockDir;
|
|
24
20
|
let logDir;
|
|
@@ -255,6 +251,7 @@ function createConsole(uniqueName) {
|
|
|
255
251
|
result.$log = $log;
|
|
256
252
|
result.$error = $error;
|
|
257
253
|
result.$draft = draftLog;
|
|
254
|
+
result.$abort = () => false;
|
|
258
255
|
if (uniqueName) {
|
|
259
256
|
let pair = parseUniqueName(uniqueName)
|
|
260
257
|
let fileName = pair[0] + '/' + pair[1].split(".")[0]
|
|
@@ -267,21 +264,24 @@ function createConsole(uniqueName) {
|
|
|
267
264
|
error: true,
|
|
268
265
|
syncLogs: [result.$log, roomError]
|
|
269
266
|
});
|
|
267
|
+
const promptId = setting.promptId;
|
|
268
|
+
result.$abort = () => promptId !== setting.promptId;
|
|
270
269
|
}
|
|
271
270
|
let quite = false
|
|
271
|
+
let promptId = 0
|
|
272
272
|
if (uniqueName) {
|
|
273
|
-
|
|
273
|
+
promptId = setting.promptId;
|
|
274
274
|
}
|
|
275
275
|
for (let key of Object.keys(_consoleFns)) {
|
|
276
276
|
result[key] = (...args) => {
|
|
277
|
-
if (
|
|
277
|
+
if (promptId !== setting.promptId) {
|
|
278
278
|
quite = true;
|
|
279
279
|
}
|
|
280
280
|
if ('debug' === key && !global.$DEBUG) {
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
283
|
if ('error' === key) {
|
|
284
|
-
|
|
284
|
+
setting.newError = true;
|
|
285
285
|
}
|
|
286
286
|
let hasFlag = false;
|
|
287
287
|
let sameFlag = false;
|
|
@@ -309,6 +309,7 @@ function createConsole(uniqueName) {
|
|
|
309
309
|
let _args = _consoleFns[key].args(args);
|
|
310
310
|
let lastOutput = null;
|
|
311
311
|
if (hasFlag) {
|
|
312
|
+
terminalTitle(setting.lastChangeFlag.replace(/^\*/, '').replace(/\*$/, '').trim())
|
|
312
313
|
lastOutput = _args.join(" ")
|
|
313
314
|
if (!isRunningInBackground() && setting.lastOutput && sameFlag) {
|
|
314
315
|
let lines = setting.lastOutput.split('\n').length;
|
|
@@ -336,6 +337,20 @@ console = createConsole();
|
|
|
336
337
|
// fix console done
|
|
337
338
|
|
|
338
339
|
|
|
340
|
+
function terminalTitle(title = 'jsir') {
|
|
341
|
+
if (isRunningInBackground()) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (setting.terminalTitle !== title) {
|
|
345
|
+
setting.terminalTitle = title;
|
|
346
|
+
if (title) {
|
|
347
|
+
process.stdout.write(`\x1b]0;${setting.terminalTitle}\x07`);
|
|
348
|
+
} else {
|
|
349
|
+
process.stdout.write('\x1b]0;\x07');
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
339
354
|
function getFullPath(name) {
|
|
340
355
|
name = trim(name)
|
|
341
356
|
if (!name) {
|
|
@@ -787,10 +802,10 @@ function createLimitLogger(fileName, {
|
|
|
787
802
|
|
|
788
803
|
let text = consoleStrs(...args)
|
|
789
804
|
if (error) {
|
|
790
|
-
|
|
805
|
+
setting.newError = true;
|
|
791
806
|
}
|
|
792
807
|
if (time) {
|
|
793
|
-
text = `${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${
|
|
808
|
+
text = `${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${String(process.pid%1000).padStart(3, '0')}> ${text}`
|
|
794
809
|
}
|
|
795
810
|
syncQueue(() => fp.appendFile(logPath, text + '\n'), logPath)
|
|
796
811
|
let _minNum = (Date.now()/(1000 * 60 * 10)).toFixed(0)
|
|
@@ -983,16 +998,17 @@ function aesCipher(str, key, useIv = false){
|
|
|
983
998
|
if (!key || key.length > 16) {
|
|
984
999
|
throw "aesCipher key length should be between 1 and 16"
|
|
985
1000
|
}
|
|
1001
|
+
key = key.padEnd(16, '0');
|
|
986
1002
|
if (useIv) {
|
|
987
1003
|
// Generate random IV
|
|
988
1004
|
const iv = crypto.randomBytes(16);
|
|
989
|
-
const cipher = crypto.createCipheriv('aes-128-cbc',
|
|
1005
|
+
const cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
|
|
990
1006
|
|
|
991
1007
|
// Return IV and ciphertext, as IV is needed for decryption
|
|
992
1008
|
const ciphertext = cipher.update(str, 'utf8', 'hex') + cipher.final('hex');
|
|
993
1009
|
return iv.toString('hex') + ':' + ciphertext; // Combine IV and ciphertext
|
|
994
1010
|
}
|
|
995
|
-
const cipher = crypto.createCipheriv('aes-128-ecb',
|
|
1011
|
+
const cipher = crypto.createCipheriv('aes-128-ecb', key, null);
|
|
996
1012
|
return cipher.update(str, 'utf8', 'hex') + cipher.final('hex');
|
|
997
1013
|
}
|
|
998
1014
|
|
|
@@ -1004,7 +1020,7 @@ function aesDecipher(str, key){
|
|
|
1004
1020
|
if (!key || key.length > 16) {
|
|
1005
1021
|
throw "aesCipher key length should be between 1 and 16";
|
|
1006
1022
|
}
|
|
1007
|
-
|
|
1023
|
+
key = key.padEnd(16, '0');
|
|
1008
1024
|
// Extract IV and ciphertext
|
|
1009
1025
|
if(str.indexOf(":") !== -1) {
|
|
1010
1026
|
const [ivHex, ciphertext] = str.split(':');
|
|
@@ -1012,10 +1028,10 @@ function aesDecipher(str, key){
|
|
|
1012
1028
|
throw "Invalid encrypted string format";
|
|
1013
1029
|
}
|
|
1014
1030
|
const iv = Buffer.from(ivHex, 'hex');
|
|
1015
|
-
const decipher = crypto.createDecipheriv('aes-128-cbc',
|
|
1031
|
+
const decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
|
|
1016
1032
|
return decipher.update(ciphertext, 'hex', 'utf8') + decipher.final('utf8');
|
|
1017
1033
|
}
|
|
1018
|
-
const decipher = crypto.createDecipheriv('aes-128-ecb',
|
|
1034
|
+
const decipher = crypto.createDecipheriv('aes-128-ecb', key, null);
|
|
1019
1035
|
return decipher.update(str, 'hex', 'utf8') + decipher.final('utf8');
|
|
1020
1036
|
}
|
|
1021
1037
|
|
|
@@ -1286,19 +1302,21 @@ async function _fileLock(key, fn) {
|
|
|
1286
1302
|
|
|
1287
1303
|
async function fileLock(key, fn, wait = true) {
|
|
1288
1304
|
`
|
|
1289
|
-
文件锁,
|
|
1305
|
+
文件锁, 默认一直等待直到加锁成功执行fn
|
|
1290
1306
|
wait = false, 加锁失败则不执行fn
|
|
1291
1307
|
return void
|
|
1292
1308
|
`
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
break;
|
|
1297
|
-
}
|
|
1298
|
-
await sleep(9);
|
|
1309
|
+
while (true) {
|
|
1310
|
+
if (await _fileLock(key, fn)) {
|
|
1311
|
+
break;
|
|
1299
1312
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1313
|
+
if (typeof wait === 'function') {
|
|
1314
|
+
wait = await wait();
|
|
1315
|
+
}
|
|
1316
|
+
if (!wait) {
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
await sleep(9);
|
|
1302
1320
|
}
|
|
1303
1321
|
}
|
|
1304
1322
|
|
|
@@ -1308,32 +1326,35 @@ async function processLock(key, fn, wait = true) {
|
|
|
1308
1326
|
wait = false, 加锁失败则不执行fn
|
|
1309
1327
|
return void
|
|
1310
1328
|
`
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
break;
|
|
1315
|
-
}
|
|
1316
|
-
await sleep(9);
|
|
1329
|
+
while (true) {
|
|
1330
|
+
if (await _processLock(key, fn)) {
|
|
1331
|
+
break;
|
|
1317
1332
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1333
|
+
if (typeof wait === 'function') {
|
|
1334
|
+
wait = await wait();
|
|
1335
|
+
}
|
|
1336
|
+
if (!wait) {
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
await sleep(9);
|
|
1320
1340
|
}
|
|
1321
1341
|
}
|
|
1322
1342
|
|
|
1343
|
+
const $locks = {}
|
|
1323
1344
|
async function _processLock(key, fn) {
|
|
1324
1345
|
if (!key || typeof fn !== 'function') {
|
|
1325
1346
|
throw new Error('invalid arguments');
|
|
1326
1347
|
}
|
|
1327
1348
|
key = key.trim();
|
|
1328
|
-
if (
|
|
1349
|
+
if ($locks.hasOwnProperty(key)) {
|
|
1329
1350
|
return false;
|
|
1330
1351
|
}
|
|
1331
|
-
|
|
1352
|
+
$locks[key] = true;
|
|
1332
1353
|
try {
|
|
1333
1354
|
await fn();
|
|
1334
1355
|
return true;
|
|
1335
1356
|
} finally {
|
|
1336
|
-
delete
|
|
1357
|
+
delete $locks[key];
|
|
1337
1358
|
}
|
|
1338
1359
|
}
|
|
1339
1360
|
|
|
@@ -1356,23 +1377,25 @@ function setTips(key, value, onRm) {
|
|
|
1356
1377
|
if (!vl(key) || key.indexOf(",") !== -1) {
|
|
1357
1378
|
throw "invalid tip key";
|
|
1358
1379
|
}
|
|
1359
|
-
|
|
1380
|
+
key = trim(key)
|
|
1381
|
+
getOr(setting.tips, key, []).push(vl(value) ? value:'');
|
|
1360
1382
|
if (onRm) {
|
|
1361
1383
|
getOr(_tipsOnRm, key, []).push(onRm)
|
|
1362
1384
|
}
|
|
1363
1385
|
}
|
|
1364
1386
|
|
|
1365
1387
|
function delTips(...keys) {
|
|
1388
|
+
let pros = []
|
|
1366
1389
|
for (let key of Object.keys(setting.tips)) {
|
|
1367
1390
|
if (keys.length === 0) {
|
|
1368
1391
|
if (key === 'DEBUG') {
|
|
1369
1392
|
continue
|
|
1370
1393
|
}
|
|
1371
1394
|
delete setting.tips[key]
|
|
1372
|
-
tipsOnRmCallback(key)
|
|
1395
|
+
pros.push(tipsOnRmCallback(key))
|
|
1373
1396
|
} else if (keys.indexOf(key) !== -1) {
|
|
1374
1397
|
delete setting.tips[key]
|
|
1375
|
-
tipsOnRmCallback(key)
|
|
1398
|
+
pros.push(tipsOnRmCallback(key))
|
|
1376
1399
|
}
|
|
1377
1400
|
}
|
|
1378
1401
|
if (keys.length === 0) {
|
|
@@ -1380,13 +1403,22 @@ function delTips(...keys) {
|
|
|
1380
1403
|
if (key === 'DEBUG') {
|
|
1381
1404
|
continue
|
|
1382
1405
|
}
|
|
1383
|
-
tipsOnRmCallback(key)
|
|
1406
|
+
pros.push(tipsOnRmCallback(key))
|
|
1384
1407
|
}
|
|
1385
1408
|
}
|
|
1409
|
+
pros = pros.filter(i => i);
|
|
1410
|
+
if (pros.length > 0) {
|
|
1411
|
+
return Promise.all(pros)
|
|
1412
|
+
}
|
|
1386
1413
|
}
|
|
1387
1414
|
|
|
1388
|
-
function hasTips(key) {
|
|
1389
|
-
|
|
1415
|
+
function hasTips(key, value) {
|
|
1416
|
+
key = trim(key)
|
|
1417
|
+
if (vl(value)) {
|
|
1418
|
+
return setting.tips.hasOwnProperty(key) && setting.tips[key].includes(value);
|
|
1419
|
+
} else {
|
|
1420
|
+
return setting.tips.hasOwnProperty(key);
|
|
1421
|
+
}
|
|
1390
1422
|
}
|
|
1391
1423
|
|
|
1392
1424
|
function tipKeys() {
|
|
@@ -1396,15 +1428,22 @@ function tipKeys() {
|
|
|
1396
1428
|
function tipsOnRmCallback(key) {
|
|
1397
1429
|
let callbacks = _tipsOnRm[key]
|
|
1398
1430
|
delete _tipsOnRm[key]
|
|
1431
|
+
const pros = [];
|
|
1399
1432
|
if (callbacks && callbacks.length > 0) {
|
|
1400
1433
|
for (let callback of callbacks) {
|
|
1401
1434
|
try {
|
|
1402
|
-
callback()
|
|
1435
|
+
let result = callback()
|
|
1436
|
+
if (getType(result) === 'Promise') {
|
|
1437
|
+
pros.push(result.catch(e => $error(`[${key}] OnRmCallback`, e)))
|
|
1438
|
+
}
|
|
1403
1439
|
} catch (e) {
|
|
1404
1440
|
$error(`[${key}] OnRmCallback`, e)
|
|
1405
1441
|
}
|
|
1406
1442
|
}
|
|
1407
1443
|
}
|
|
1444
|
+
if (pros.length > 0) {
|
|
1445
|
+
return Promise.all(pros);
|
|
1446
|
+
}
|
|
1408
1447
|
}
|
|
1409
1448
|
|
|
1410
1449
|
async function timer(key, ms, fn, label, printInfo = true){
|
|
@@ -2147,6 +2186,9 @@ end tell
|
|
|
2147
2186
|
function getKeyTips() {
|
|
2148
2187
|
let items = [];
|
|
2149
2188
|
for (let key of Object.keys(setting.tips)) {
|
|
2189
|
+
if (key.startsWith("_")) {
|
|
2190
|
+
continue;
|
|
2191
|
+
}
|
|
2150
2192
|
items.push(trim(key))
|
|
2151
2193
|
}
|
|
2152
2194
|
return items
|
|
@@ -2155,6 +2197,9 @@ function getKeyTips() {
|
|
|
2155
2197
|
function getValTips() {
|
|
2156
2198
|
let items = [];
|
|
2157
2199
|
for (let key of Object.keys(setting.tips)) {
|
|
2200
|
+
if (key.startsWith("_")) {
|
|
2201
|
+
continue;
|
|
2202
|
+
}
|
|
2158
2203
|
let val = setting.tips[key].map(i => {
|
|
2159
2204
|
if (typeof i === 'function') {
|
|
2160
2205
|
try {
|
|
@@ -2260,13 +2305,20 @@ async function aopAsync(items, fn, args) {
|
|
|
2260
2305
|
}
|
|
2261
2306
|
|
|
2262
2307
|
function getMd5Key(str) {
|
|
2263
|
-
return '0x' + md5(str).
|
|
2308
|
+
return '0x' + md5(str).substring(0, 8);
|
|
2264
2309
|
}
|
|
2265
2310
|
|
|
2266
2311
|
function isMd5Key(str) {
|
|
2267
2312
|
return /^0x[a-z\d]{8}$/.test(str);
|
|
2268
2313
|
}
|
|
2269
2314
|
|
|
2315
|
+
const tipFns = {
|
|
2316
|
+
set: setTips,
|
|
2317
|
+
del: delTips,
|
|
2318
|
+
has: hasTips,
|
|
2319
|
+
key: tipKeys
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2270
2322
|
module.exports = {
|
|
2271
2323
|
formatUptime,
|
|
2272
2324
|
wrapperJsirText,
|
|
@@ -2291,7 +2343,6 @@ module.exports = {
|
|
|
2291
2343
|
bMul,
|
|
2292
2344
|
getConfig,
|
|
2293
2345
|
getCbText,
|
|
2294
|
-
pad,
|
|
2295
2346
|
aesCipher,
|
|
2296
2347
|
aesDecipher,
|
|
2297
2348
|
requireG,
|
|
@@ -2387,5 +2438,7 @@ module.exports = {
|
|
|
2387
2438
|
isPidAlive,
|
|
2388
2439
|
cleanFileLocks,
|
|
2389
2440
|
getMd5Key,
|
|
2390
|
-
isMd5Key
|
|
2441
|
+
isMd5Key,
|
|
2442
|
+
terminalTitle,
|
|
2443
|
+
tipFns
|
|
2391
2444
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsir",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.13",
|
|
4
4
|
"description": "JavaScript Script Management Tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"bignumber.js": "^9.0.0",
|
|
22
22
|
"chokidar": "^3.5.2",
|
|
23
23
|
"console.table": "^0.10.0",
|
|
24
|
-
"dayjs": "^1.10.4"
|
|
25
|
-
"pad": "^3.2.0"
|
|
24
|
+
"dayjs": "^1.10.4"
|
|
26
25
|
}
|
|
27
26
|
}
|