jsir 3.0.3 → 3.0.4
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 -43
- package/deps/evalCode.js +8 -1
- package/deps/util.js +2 -1
- package/package.json +5 -5
package/cmd/oaa.js
CHANGED
|
@@ -404,6 +404,10 @@ function closeRl() {
|
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
function _nextLine(callback, promptStr, hidden, resolve, reject, end, isText) {
|
|
407
|
+
if (isRunningInBackground()) {
|
|
408
|
+
reject("Unsupported Operation")
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
407
411
|
callback = callback || wrapperInput;
|
|
408
412
|
if (!setting.enableNextLine) {
|
|
409
413
|
console.$warn("NextLine Disabled");
|
|
@@ -469,6 +473,7 @@ function _nextLine(callback, promptStr, hidden, resolve, reject, end, isText) {
|
|
|
469
473
|
if (callback === wrapperInput) {
|
|
470
474
|
setting.promptId = Date.now();
|
|
471
475
|
setting.lastOutput = null;
|
|
476
|
+
terminalTitle();
|
|
472
477
|
}
|
|
473
478
|
}
|
|
474
479
|
|
|
@@ -1185,20 +1190,33 @@ const keywordDef = {
|
|
|
1185
1190
|
clear: {
|
|
1186
1191
|
comment: 'Clear task',
|
|
1187
1192
|
exeFn: async (args) => {
|
|
1188
|
-
if (args.length > 0
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1193
|
+
if (args.length > 0) {
|
|
1194
|
+
if (_cmdMap[args[0]]) {
|
|
1195
|
+
let cmdName = _cmdMap[args[0]];
|
|
1196
|
+
if (args.length === 1) {
|
|
1197
|
+
$data.del(cmdName)
|
|
1198
|
+
console.msg('remove metadata of', cmdName)
|
|
1199
|
+
} else {
|
|
1200
|
+
let metadata = $data.get(cmdName);
|
|
1201
|
+
if (!vl(metadata) || typeof metadata !== 'object') {
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
for (let key of args.slice(1)) {
|
|
1205
|
+
if (metadata.hasOwnProperty(key)) {
|
|
1206
|
+
delete metadata[key]
|
|
1207
|
+
console.msg('remove metadata of', cmdName, key)
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1196
1210
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1211
|
+
} else if ('0' === args[0]) {
|
|
1212
|
+
for (let key of $data.key()) {
|
|
1213
|
+
if (setting.workspaceMap[key.split("/")[0]]) {
|
|
1214
|
+
$data.del(key)
|
|
1215
|
+
console.msg('remove metadata of', key)
|
|
1200
1216
|
}
|
|
1201
1217
|
}
|
|
1218
|
+
} else {
|
|
1219
|
+
await delTips(...args)
|
|
1202
1220
|
}
|
|
1203
1221
|
} else {
|
|
1204
1222
|
await delTips(...args)
|
|
@@ -1708,15 +1726,24 @@ const keywordDef = {
|
|
|
1708
1726
|
if (args.length > 0) {
|
|
1709
1727
|
let have = false;
|
|
1710
1728
|
let tasks = []
|
|
1729
|
+
let targets = []
|
|
1730
|
+
let inputArgs = []
|
|
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
|
+
}
|
|
1711
1738
|
for (let room of setting.rooms) {
|
|
1712
1739
|
for (let pid of Object.keys(room.jsirs || {})) {
|
|
1713
|
-
if (
|
|
1740
|
+
if (targets.indexOf(room.selfNode) === -1 && targets.indexOf(pid) === -1) {
|
|
1714
1741
|
continue;
|
|
1715
1742
|
}
|
|
1716
1743
|
if (setting.selfRoom.selfNode === room.selfNode && String(process.pid) === pid) {
|
|
1717
1744
|
continue;
|
|
1718
1745
|
}
|
|
1719
|
-
if (setting.selfRoom.selfNode !== room.selfNode &&
|
|
1746
|
+
if (setting.selfRoom.selfNode !== room.selfNode && targets.includes(room.selfNode) && !targets.includes(pid)
|
|
1720
1747
|
&& room.jsirs[pid].port === setting.defaultPort) {
|
|
1721
1748
|
continue;
|
|
1722
1749
|
}
|
|
@@ -1729,7 +1756,8 @@ const keywordDef = {
|
|
|
1729
1756
|
})
|
|
1730
1757
|
}
|
|
1731
1758
|
}
|
|
1732
|
-
let
|
|
1759
|
+
let inputStr = trim(inputArgs.join(" "))
|
|
1760
|
+
let input = have ? (inputStr || await nextLine(i => i)):''
|
|
1733
1761
|
if (vl(input)) {
|
|
1734
1762
|
for (let task of tasks) {
|
|
1735
1763
|
try {
|
|
@@ -1824,11 +1852,11 @@ async function _dealKeyword(keyword, args) {
|
|
|
1824
1852
|
let shortKey = keyword === key ? item.short : keyword;
|
|
1825
1853
|
if (item.short === shortKey) {
|
|
1826
1854
|
unMatched = false;
|
|
1855
|
+
console.$log('Execute', key)
|
|
1856
|
+
terminalTitle(key)
|
|
1827
1857
|
if (item === keywordDef.run) {
|
|
1828
|
-
console.$log('Execute', key)
|
|
1829
1858
|
await item.exeFn(args);
|
|
1830
1859
|
} else {
|
|
1831
|
-
console.$log('Execute', key)
|
|
1832
1860
|
await item.exeFn(args.map(trim));
|
|
1833
1861
|
}
|
|
1834
1862
|
break;
|
|
@@ -2133,6 +2161,31 @@ async function runScript(uniqueName, oriArgs) {
|
|
|
2133
2161
|
return await evalText(text, uniqueName, scriptArgs)
|
|
2134
2162
|
}
|
|
2135
2163
|
|
|
2164
|
+
function verifyArgs(scriptArgs = {}, argDef, _uniqueName) {
|
|
2165
|
+
let argNames = Object.keys(argDef)
|
|
2166
|
+
let argAbsent = false
|
|
2167
|
+
let scriptArgKeys = Object.keys(scriptArgs);
|
|
2168
|
+
for (let name of argNames) {
|
|
2169
|
+
let defStr = argDef[name]
|
|
2170
|
+
let beginIdx = defStr.indexOf("^");
|
|
2171
|
+
let endIdx = defStr.indexOf("$");
|
|
2172
|
+
let reg
|
|
2173
|
+
if (beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx) {
|
|
2174
|
+
reg = new RegExp(defStr.substring(beginIdx, endIdx + 1));
|
|
2175
|
+
}
|
|
2176
|
+
if (name.startsWith("_") && scriptArgKeys.indexOf(name) === -1) {
|
|
2177
|
+
continue
|
|
2178
|
+
}
|
|
2179
|
+
if (scriptArgKeys.indexOf(name) === -1 || (reg && !reg.test(scriptArgs[name]))) {
|
|
2180
|
+
argAbsent = true
|
|
2181
|
+
console.warn(`require ${warnStr(name)}` + (defStr ? ` ${defStr}` : ''))
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
if (argAbsent) {
|
|
2185
|
+
throw _uniqueName ? `invalid args for ${_uniqueName}`:'invalid args';
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2136
2189
|
async function getScriptArgs(argDef, oriArgs) {
|
|
2137
2190
|
let shortDefMap = getShortDefMap(Object.keys(argDef))
|
|
2138
2191
|
oriArgs = oriArgs.map(i => shortDefMap[i] ? shortDefMap[i]:i)
|
|
@@ -2184,27 +2237,7 @@ async function getScriptArgs(argDef, oriArgs) {
|
|
|
2184
2237
|
for (let key of Object.keys(exactArgs)) {
|
|
2185
2238
|
scriptArgs[key] = exactArgs[key]
|
|
2186
2239
|
}
|
|
2187
|
-
|
|
2188
|
-
let scriptArgKeys = Object.keys(scriptArgs);
|
|
2189
|
-
for(let name of argNames) {
|
|
2190
|
-
let defStr = argDef[name]
|
|
2191
|
-
let beginIdx = defStr.indexOf("^");
|
|
2192
|
-
let endIdx = defStr.indexOf("$");
|
|
2193
|
-
let reg
|
|
2194
|
-
if (beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx) {
|
|
2195
|
-
reg = new RegExp(defStr.substring(beginIdx, endIdx + 1));
|
|
2196
|
-
}
|
|
2197
|
-
if (name.startsWith("_") && scriptArgKeys.indexOf(name) === -1) {
|
|
2198
|
-
continue
|
|
2199
|
-
}
|
|
2200
|
-
if (scriptArgKeys.indexOf(name) === -1 || (reg && !reg.test(scriptArgs[name]))) {
|
|
2201
|
-
argAbsent = true
|
|
2202
|
-
console.warn(`require ${warnStr(name)}` + (defStr ? ` ${defStr}`:''))
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
if (argAbsent) {
|
|
2206
|
-
throw 'invalid args';
|
|
2207
|
-
}
|
|
2240
|
+
verifyArgs(scriptArgs, argDef);
|
|
2208
2241
|
return scriptArgs;
|
|
2209
2242
|
}
|
|
2210
2243
|
|
|
@@ -2286,7 +2319,7 @@ function parseArgDef(inputString) {
|
|
|
2286
2319
|
}
|
|
2287
2320
|
|
|
2288
2321
|
function getArgDef(text, uniqueName) {
|
|
2289
|
-
if (uniqueName && getJsirTypeKey(parseUniqueName(uniqueName)[1])
|
|
2322
|
+
if (uniqueName && ![setting.exeKey, setting.initKey].includes(getJsirTypeKey(parseUniqueName(uniqueName)[1]))) {
|
|
2290
2323
|
return {}
|
|
2291
2324
|
}
|
|
2292
2325
|
if (text.indexOf("$defArgs") === -1) {
|
|
@@ -2350,7 +2383,7 @@ function filterRequire(currSpace, cmdMatchStr) {
|
|
|
2350
2383
|
return cmds[0];
|
|
2351
2384
|
}
|
|
2352
2385
|
|
|
2353
|
-
async function _requireSource(currSpace, cmdMatchStr, force = false) {
|
|
2386
|
+
async function _requireSource(currSpace, cmdMatchStr, force = false, $args) {
|
|
2354
2387
|
let result
|
|
2355
2388
|
let uniqueName = filterRequire(currSpace, cmdMatchStr);
|
|
2356
2389
|
let path = getFullPath(uniqueName)
|
|
@@ -2382,7 +2415,11 @@ async function _requireSource(currSpace, cmdMatchStr, force = false) {
|
|
|
2382
2415
|
}
|
|
2383
2416
|
})
|
|
2384
2417
|
} else {
|
|
2385
|
-
|
|
2418
|
+
let argDef = getArgDef(text)
|
|
2419
|
+
if (Object.keys(argDef).length > 0) {
|
|
2420
|
+
verifyArgs($args, argDef, uniqueName);
|
|
2421
|
+
}
|
|
2422
|
+
result = await evalText(text, uniqueName, $args)
|
|
2386
2423
|
}
|
|
2387
2424
|
}
|
|
2388
2425
|
} else if (typeKey === setting.exeKey) {
|
|
@@ -2390,7 +2427,11 @@ async function _requireSource(currSpace, cmdMatchStr, force = false) {
|
|
|
2390
2427
|
return await runCmd(trim(argsStr), uniqueName, text)
|
|
2391
2428
|
}
|
|
2392
2429
|
} else {
|
|
2393
|
-
|
|
2430
|
+
if (path.endsWith(".json")) {
|
|
2431
|
+
result = JSON.parse(text);
|
|
2432
|
+
} else {
|
|
2433
|
+
result = text;
|
|
2434
|
+
}
|
|
2394
2435
|
}
|
|
2395
2436
|
if (!vl(result)) {
|
|
2396
2437
|
throw `invalid result: ${cmdMatchStr}`
|
|
@@ -2510,8 +2551,8 @@ async function evalText($text = '', $cmdName = '', $args = {}) {
|
|
|
2510
2551
|
}
|
|
2511
2552
|
return result
|
|
2512
2553
|
}
|
|
2513
|
-
let $require = async (matchItem) => {
|
|
2514
|
-
return await _requireSource(currSpace, matchItem)
|
|
2554
|
+
let $require = async (matchItem, $args) => {
|
|
2555
|
+
return await _requireSource(currSpace, matchItem, false, $args)
|
|
2515
2556
|
}
|
|
2516
2557
|
return await evalCode(addErrorTag($text), $cmdName, $args,
|
|
2517
2558
|
$data,
|
package/deps/evalCode.js
CHANGED
|
@@ -16,11 +16,18 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
|
16
16
|
|
|
17
17
|
// 兼容
|
|
18
18
|
$text = $lib.wrapperJsirText($text)
|
|
19
|
+
$text = $text.split("\n").map(i => {
|
|
20
|
+
const argPass = /\)\s*\|\|/
|
|
21
|
+
if (/\$require\s*\(/.test(i) && argPass.test(i)) {
|
|
22
|
+
return i.replace(argPass, ',').trimEnd() + ")"
|
|
23
|
+
}
|
|
24
|
+
return i
|
|
25
|
+
}).join("\n")
|
|
19
26
|
|
|
20
27
|
const $tips = $lib.tipFns;
|
|
21
|
-
const $errorTag = $lib.errorTag;
|
|
22
28
|
|
|
23
29
|
// 不在context中
|
|
30
|
+
const $errorTag = $lib.errorTag;
|
|
24
31
|
const $setTips = $lib.setTips;
|
|
25
32
|
const $delTips = $lib.delTips;
|
|
26
33
|
const $aop = $lib.aop;
|
package/deps/util.js
CHANGED
|
@@ -2065,8 +2065,9 @@ function getTextComments(text) {
|
|
|
2065
2065
|
function wrapperJsirText(text) {
|
|
2066
2066
|
return text
|
|
2067
2067
|
.replace(/^require\s*\(\s*(["'`][ei][^a-zA-Z]+)/mg, 'await $require($1')
|
|
2068
|
-
.replace(/([\s=;]require\s*\(\s*["'`])\.\/([ei][^a-zA-Z]+)/g, '$1$2')
|
|
2068
|
+
// .replace(/([\s=;]require\s*\(\s*["'`])\.\/([ei][^a-zA-Z]+)/g, '$1$2')
|
|
2069
2069
|
.replace(/([\s=;])require\s*\(\s*(["'`][ei][^a-zA-Z]+)/g, '$1await $require($2')
|
|
2070
|
+
.replace(/([\s=;])require\s*\(\s*(["'`])\.\//g, '$1await $require($2')
|
|
2070
2071
|
.replace(/([\s=;])import\s*\(/g, '$1$import(')
|
|
2071
2072
|
.replace(/^import\s*\(/mg, '$import(')
|
|
2072
2073
|
.replace(/^module\.exports\s*=\s*/m, 'return ')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsir",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "JavaScript Script Management Tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"author": "",
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"bignumber.js": "
|
|
22
|
-
"chokidar": "
|
|
23
|
-
"console.table": "
|
|
24
|
-
"dayjs": "
|
|
21
|
+
"bignumber.js": "9.0.0",
|
|
22
|
+
"chokidar": "3.5.2",
|
|
23
|
+
"console.table": "0.10.0",
|
|
24
|
+
"dayjs": "1.10.4"
|
|
25
25
|
}
|
|
26
26
|
}
|