jsir 2.0.1 → 2.0.3
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 +23 -7
- package/evalCode.js +3 -2
- package/package.json +1 -1
- package/util.js +8 -3
package/cmd/oaa.js
CHANGED
|
@@ -31,7 +31,22 @@ let _haveWrapperInput = true
|
|
|
31
31
|
let _workspaceConfigFile = 'workspace.json';
|
|
32
32
|
let _exit = false
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const _data = {}
|
|
35
|
+
const $data = {
|
|
36
|
+
get: (key, val) => {
|
|
37
|
+
if (!(key in _data) && val !== undefined) {
|
|
38
|
+
_data[key] = val
|
|
39
|
+
}
|
|
40
|
+
return _data[key]
|
|
41
|
+
},
|
|
42
|
+
set: (key, val) => {
|
|
43
|
+
_data[key] = val
|
|
44
|
+
},
|
|
45
|
+
del: (key) => {
|
|
46
|
+
delete _data[key]
|
|
47
|
+
},
|
|
48
|
+
keys: () => Object.keys(_data)
|
|
49
|
+
}
|
|
35
50
|
const $homeDir = getLibDataDir()
|
|
36
51
|
const $lib = {...require('../util')}
|
|
37
52
|
|
|
@@ -341,7 +356,6 @@ $defArgs({
|
|
|
341
356
|
})
|
|
342
357
|
|
|
343
358
|
let {} = $lib // 引用内置资源
|
|
344
|
-
let [] = await $require() // 模糊引用脚本资源
|
|
345
359
|
|
|
346
360
|
console.log($args)
|
|
347
361
|
|
|
@@ -353,7 +367,6 @@ A test init script
|
|
|
353
367
|
*/
|
|
354
368
|
|
|
355
369
|
let {} = $lib // 引用内置资源
|
|
356
|
-
let [] = await $require() // 模糊引用脚本资源
|
|
357
370
|
|
|
358
371
|
return {}
|
|
359
372
|
`;
|
|
@@ -374,11 +387,11 @@ function rename(dir, oldName, newName) {
|
|
|
374
387
|
if (_fs.existsSync(_new)) {
|
|
375
388
|
warn(`${_new} already exist`)
|
|
376
389
|
} else {
|
|
377
|
-
_fs.
|
|
390
|
+
_fs.renameSync(old, _new)
|
|
378
391
|
info(`${_new} renamed`)
|
|
379
392
|
}
|
|
380
393
|
_cmdMap = {
|
|
381
|
-
1: toUniqueName(
|
|
394
|
+
1: toUniqueName(_new)
|
|
382
395
|
}
|
|
383
396
|
listCmd()
|
|
384
397
|
}
|
|
@@ -1555,11 +1568,14 @@ async function evalText($text = '', $cmdName = '', $args = []) {
|
|
|
1555
1568
|
} else {
|
|
1556
1569
|
currSpace = $defaultSpace
|
|
1557
1570
|
}
|
|
1558
|
-
let $
|
|
1571
|
+
let $requires = async (...matchItems) => {
|
|
1559
1572
|
return await _requireSources(currSpace, ...matchItems)
|
|
1560
1573
|
}
|
|
1574
|
+
let $require = async (matchItem, printLog) => {
|
|
1575
|
+
return (await _requireSources(currSpace, matchItem, printLog))[0]
|
|
1576
|
+
}
|
|
1561
1577
|
try {
|
|
1562
|
-
return await evalCode($text, $cmdName, $args, $require, $
|
|
1578
|
+
return await evalCode($text, $cmdName, $args, $data, $require, $requires,
|
|
1563
1579
|
nextLine, nextText, setTips, delTips, wrapperInput, filterCmd,
|
|
1564
1580
|
currSpace, $log, $draft, $config, $homeDir, $lib)
|
|
1565
1581
|
} catch(e) {
|
package/evalCode.js
CHANGED
|
@@ -5,7 +5,8 @@ const {info: $info, msg: $msg, warn: $warn, error: $error,
|
|
|
5
5
|
importG: $import} = require("./util");
|
|
6
6
|
require = require("./util").requireG;
|
|
7
7
|
module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
8
|
-
$
|
|
8
|
+
$data,
|
|
9
|
+
$require, $requires,
|
|
9
10
|
$nextLine, $nextText,
|
|
10
11
|
$setTips, $delTips,
|
|
11
12
|
$enter, $filterCmd,
|
|
@@ -15,7 +16,7 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
|
15
16
|
const $defArgs = () => $args;
|
|
16
17
|
const $context = {
|
|
17
18
|
global, $data,
|
|
18
|
-
$require, $import,
|
|
19
|
+
$require, $requires, $import,
|
|
19
20
|
$info, $msg, $warn, $error,
|
|
20
21
|
$infoStr, $msgStr, $warnStr, $errorStr,
|
|
21
22
|
$tableStr, $nableStr,
|
package/package.json
CHANGED
package/util.js
CHANGED
|
@@ -473,12 +473,17 @@ function getConfig(key, defaultVal) {
|
|
|
473
473
|
if (writeFlag) {
|
|
474
474
|
fs.writeFileSync(configFile, JSON.stringify(config, null, 2))
|
|
475
475
|
}
|
|
476
|
-
|
|
477
|
-
|
|
476
|
+
let val = getVl(config[key], defaultVal)
|
|
477
|
+
if (typeof val === "string") {
|
|
478
|
+
val = trim(val)
|
|
479
|
+
}
|
|
480
|
+
return val
|
|
478
481
|
}
|
|
479
482
|
|
|
480
483
|
function setConfig(key, val) {
|
|
481
|
-
val
|
|
484
|
+
if (typeof val === "string") {
|
|
485
|
+
val = trim(val)
|
|
486
|
+
}
|
|
482
487
|
let configInit = {}
|
|
483
488
|
if (key) {
|
|
484
489
|
configInit[key] = val
|