jsir 3.0.4 → 3.0.6
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 +45 -22
- package/deps/room.js +2 -2
- package/deps/server.js +2 -2
- package/deps/util.js +23 -17
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -56,12 +56,21 @@ const _dealOnLazyGet = (key, onLazyTempCode) => {
|
|
|
56
56
|
return _data[key]
|
|
57
57
|
}
|
|
58
58
|
return new Promise(async (resolve, reject) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (typeof _onLazyTempCode === 'function') {
|
|
60
|
+
if (!await _onLazyTempCode()) {
|
|
61
|
+
reject("tempCode check failed")
|
|
62
|
+
} else {
|
|
63
|
+
_onLazyGetMap[key] = Date.now() + _lazyTime
|
|
64
|
+
resolve(_data[key])
|
|
65
|
+
}
|
|
62
66
|
} else {
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let inputCode = onLazyTempCode || await nextLine(i => i, "TEMP_CODE: ", true)
|
|
68
|
+
if (inputCode !== _onLazyTempCode) {
|
|
69
|
+
reject("tempCode check failed")
|
|
70
|
+
} else {
|
|
71
|
+
_onLazyGetMap[key] = Date.now() + _lazyTime
|
|
72
|
+
resolve(_data[key])
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
})
|
|
67
76
|
}
|
|
@@ -75,6 +84,11 @@ const _dataSet = (key, val, onLazyTempCode) => {
|
|
|
75
84
|
}
|
|
76
85
|
} else if (true === onLazyTempCode) {
|
|
77
86
|
useOnLazy = true
|
|
87
|
+
} else if (typeof onLazyTempCode === "function") {
|
|
88
|
+
useOnLazy = true
|
|
89
|
+
if (!vl(_onLazyTempCode)) {
|
|
90
|
+
_onLazyTempCode = onLazyTempCode;
|
|
91
|
+
}
|
|
78
92
|
} else if (onLazyTempCode !== undefined) {
|
|
79
93
|
throw "invalid tempCode defined"
|
|
80
94
|
}
|
|
@@ -635,7 +649,13 @@ async function wrapperInput(str, packOutput = false) {
|
|
|
635
649
|
await _wrapperInput(str);
|
|
636
650
|
} catch (e) {
|
|
637
651
|
if (promptId === setting.promptId) {
|
|
638
|
-
|
|
652
|
+
let msg = (e.message || e);
|
|
653
|
+
if (msg === 'Terminal Interrupt') {
|
|
654
|
+
console.warn(msg)
|
|
655
|
+
console.$warn(e)
|
|
656
|
+
} else {
|
|
657
|
+
console.error(e)
|
|
658
|
+
}
|
|
639
659
|
} else {
|
|
640
660
|
console.$error(e)
|
|
641
661
|
}
|
|
@@ -1720,21 +1740,13 @@ const keywordDef = {
|
|
|
1720
1740
|
short: 'T'
|
|
1721
1741
|
},
|
|
1722
1742
|
room: {
|
|
1723
|
-
comment: 'manage room ([node])',
|
|
1743
|
+
comment: 'manage room ([node/pid][cmdStr])',
|
|
1724
1744
|
exeFn: async (args) => {
|
|
1725
1745
|
await Room.syncSetting();
|
|
1726
1746
|
if (args.length > 0) {
|
|
1727
|
-
let have = false;
|
|
1728
1747
|
let tasks = []
|
|
1729
|
-
let
|
|
1730
|
-
let
|
|
1731
|
-
for (let arg of args) {
|
|
1732
|
-
if (inputArgs.length > 0 || !/^\d/.test(arg)) {
|
|
1733
|
-
inputArgs.push(arg)
|
|
1734
|
-
} else {
|
|
1735
|
-
targets.push(arg)
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1748
|
+
let taskPids = []
|
|
1749
|
+
let targets = [args[0]]
|
|
1738
1750
|
for (let room of setting.rooms) {
|
|
1739
1751
|
for (let pid of Object.keys(room.jsirs || {})) {
|
|
1740
1752
|
if (targets.indexOf(room.selfNode) === -1 && targets.indexOf(pid) === -1) {
|
|
@@ -1747,17 +1759,26 @@ const keywordDef = {
|
|
|
1747
1759
|
&& room.jsirs[pid].port === setting.defaultPort) {
|
|
1748
1760
|
continue;
|
|
1749
1761
|
}
|
|
1750
|
-
have = true;
|
|
1751
1762
|
tasks.push(async (input) => {
|
|
1763
|
+
let pidKey = `[${room.name} ${pid}]`
|
|
1764
|
+
if (taskPids.includes(pid)) {
|
|
1765
|
+
console.log(warnStr(`Skip ${pidKey} Cause Duplicate Pid`))
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
console.log(infoStr(pidKey))
|
|
1769
|
+
taskPids.push(pid);
|
|
1752
1770
|
let jsir = room.jsirs[pid];
|
|
1753
|
-
console.log(infoStr(`[${pid}]`))
|
|
1754
1771
|
let resp = await Room.reqNode(room.selfNode, "post", "/enter", jsir.port, JSON.stringify({input}))
|
|
1755
1772
|
console.log(JSON.parse(resp).output)
|
|
1756
1773
|
})
|
|
1757
1774
|
}
|
|
1758
1775
|
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1776
|
+
if (tasks.length === 0) {
|
|
1777
|
+
console.warn('no items')
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
let inputStr = args.slice(1).join(' ')
|
|
1781
|
+
let input = inputStr || await nextLine(i => i)
|
|
1761
1782
|
if (vl(input)) {
|
|
1762
1783
|
for (let task of tasks) {
|
|
1763
1784
|
try {
|
|
@@ -2592,7 +2613,9 @@ process.on('beforeExit', async function () {
|
|
|
2592
2613
|
if (_noAppendNextLine) {
|
|
2593
2614
|
terminalTitle(null)
|
|
2594
2615
|
} else {
|
|
2595
|
-
|
|
2616
|
+
if (!isRunningInBackground()) {
|
|
2617
|
+
nextLine();
|
|
2618
|
+
}
|
|
2596
2619
|
Room.onRoom()
|
|
2597
2620
|
}
|
|
2598
2621
|
});
|
package/deps/room.js
CHANGED
|
@@ -54,7 +54,7 @@ function onRoom() {
|
|
|
54
54
|
}
|
|
55
55
|
})
|
|
56
56
|
} catch (e) {
|
|
57
|
-
console.$
|
|
57
|
+
console.$error("initRoute failed", e)
|
|
58
58
|
}
|
|
59
59
|
_onRoom();
|
|
60
60
|
}
|
|
@@ -79,7 +79,7 @@ function offRoom() {
|
|
|
79
79
|
setting.roomTid[0] = null
|
|
80
80
|
if (setting.server) {
|
|
81
81
|
setting.server.close(() => {
|
|
82
|
-
console.$
|
|
82
|
+
console.$log('Existing server shut down.');
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
}
|
package/deps/server.js
CHANGED
|
@@ -103,7 +103,7 @@ async function createServer(port) {
|
|
|
103
103
|
return await new Promise((resolve, reject) => {
|
|
104
104
|
server.listen(port, () => {
|
|
105
105
|
const address = server.address();
|
|
106
|
-
console.$
|
|
106
|
+
console.$log(`Server listening on port ${address.port}`);
|
|
107
107
|
resolve(server)
|
|
108
108
|
});
|
|
109
109
|
server.on('error', (err) => {
|
|
@@ -149,7 +149,7 @@ function setRoute(method, url, fn, isApi = false, handler = jsonHandle) {
|
|
|
149
149
|
isApi
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
|
-
console.$
|
|
152
|
+
console.$log(`setRoute: ${method.toUpperCase()} ${url} ${handler ? handler.name:''}`);
|
|
153
153
|
return setting.server;
|
|
154
154
|
}
|
|
155
155
|
|
package/deps/util.js
CHANGED
|
@@ -136,10 +136,10 @@ const $error = createLimitLogger(`${setting.name}.error`, {
|
|
|
136
136
|
error: true,
|
|
137
137
|
syncLogs: [$log]
|
|
138
138
|
});
|
|
139
|
-
const $errorOnly = createLimitLogger(`${setting.name}.error`, {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
139
|
+
// const $errorOnly = createLimitLogger(`${setting.name}.error`, {
|
|
140
|
+
// logInfo: false,
|
|
141
|
+
// error: true
|
|
142
|
+
// });
|
|
143
143
|
|
|
144
144
|
const roomLog = createLimitLogger(`room.log`, {
|
|
145
145
|
logInfo: false
|
|
@@ -285,17 +285,17 @@ function createConsole(uniqueName, _logToFile, _errorToFile) {
|
|
|
285
285
|
result.$draft = draftLog;
|
|
286
286
|
result.$abort = () => false;
|
|
287
287
|
if (uniqueName) {
|
|
288
|
-
let pair = parseUniqueName(uniqueName)
|
|
289
|
-
let fileName = pair[0] + '/' + pair[1].split(".")[0]
|
|
290
|
-
logToFile = createLimitLogger(fileName + '.log', {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
});
|
|
294
|
-
errorToFile = createLimitLogger(fileName + '.error', {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
});
|
|
288
|
+
// let pair = parseUniqueName(uniqueName)
|
|
289
|
+
// let fileName = pair[0] + '/' + pair[1].split(".")[0]
|
|
290
|
+
// logToFile = createLimitLogger(fileName + '.log', {
|
|
291
|
+
// logInfo: false,
|
|
292
|
+
// syncLogs: [$log]
|
|
293
|
+
// });
|
|
294
|
+
// errorToFile = createLimitLogger(fileName + '.error', {
|
|
295
|
+
// logInfo: false,
|
|
296
|
+
// error: true,
|
|
297
|
+
// syncLogs: [logToFile, $errorOnly]
|
|
298
|
+
// });
|
|
299
299
|
const promptId = setting.promptId;
|
|
300
300
|
result.$abort = () => promptId !== setting.promptId;
|
|
301
301
|
}
|
|
@@ -629,6 +629,7 @@ async function draftModify(fLine) {
|
|
|
629
629
|
fs.writeFileSync(tempPath, results[0].split(/\n/).slice(1).join('\n'))
|
|
630
630
|
await eia(getEditor(), [`"${tempPath}"`], true)
|
|
631
631
|
let tempText = String(fs.readFileSync(tempPath))
|
|
632
|
+
fs.writeFileSync(tempPath, '')
|
|
632
633
|
let lineRange = lineRanges.get(results[0]);
|
|
633
634
|
let before = allLines.filter((_, index) => {
|
|
634
635
|
return index < lineRange.start;
|
|
@@ -844,7 +845,7 @@ function createLimitLogger(fileName, {
|
|
|
844
845
|
setting.newError = true;
|
|
845
846
|
}
|
|
846
847
|
if (time) {
|
|
847
|
-
let prefix = debugStr(`${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${String(process.pid%
|
|
848
|
+
let prefix = debugStr(`${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${String(process.pid%100000).padStart(5, '0')}>`)
|
|
848
849
|
text = `${prefix} ${text}`
|
|
849
850
|
}
|
|
850
851
|
fp.appendFile(logPath, text + '\n')
|
|
@@ -2249,6 +2250,10 @@ function currentRooms() {
|
|
|
2249
2250
|
return JSON.parse(JSON.stringify(setting.rooms));
|
|
2250
2251
|
}
|
|
2251
2252
|
|
|
2253
|
+
function uid() {
|
|
2254
|
+
return Date.now().toString(36) + Math.random().toString(36).slice(2, 10).padEnd(8, '0');
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2252
2257
|
module.exports = {
|
|
2253
2258
|
formatSec,
|
|
2254
2259
|
wrapperJsirText,
|
|
@@ -2369,5 +2374,6 @@ module.exports = {
|
|
|
2369
2374
|
formatMb,
|
|
2370
2375
|
currentJsir,
|
|
2371
2376
|
currentRoom,
|
|
2372
|
-
currentRooms
|
|
2377
|
+
currentRooms,
|
|
2378
|
+
uid
|
|
2373
2379
|
}
|