jsir 2.0.0 → 2.0.2
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 +79 -37
- package/evalCode.js +3 -2
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -29,7 +29,6 @@ let _rl
|
|
|
29
29
|
let _rlHistory = []
|
|
30
30
|
let _haveWrapperInput = true
|
|
31
31
|
let _workspaceConfigFile = 'workspace.json';
|
|
32
|
-
let _workspaces = arrayDataFile(_workspaceConfigFile)
|
|
33
32
|
let _exit = false
|
|
34
33
|
|
|
35
34
|
const $data = {}
|
|
@@ -60,9 +59,11 @@ function getFileOpenExe(fileName) {
|
|
|
60
59
|
|
|
61
60
|
function checkWorkspaces() {
|
|
62
61
|
let localWorkspace = _libDataDir + '/local';
|
|
63
|
-
|
|
62
|
+
global.$workspaceMap = {
|
|
63
|
+
'local': localWorkspace
|
|
64
|
+
}
|
|
64
65
|
mkdir(localWorkspace)
|
|
65
|
-
for (let workspace of
|
|
66
|
+
for (let workspace of arrayDataFile(_workspaceConfigFile)) {
|
|
66
67
|
workspace = workspace.replace(/\/+$/, '')
|
|
67
68
|
let space = getSpaceFromDir(workspace);
|
|
68
69
|
if (space === 'local') {
|
|
@@ -72,18 +73,14 @@ function checkWorkspaces() {
|
|
|
72
73
|
$workspaceMap[space] = workspace;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
-
arrayDataFile(_workspaceConfigFile, () => _workspaces)
|
|
76
|
+
arrayDataFile(_workspaceConfigFile, () => Object.values($workspaceMap))
|
|
77
77
|
initWorkspace()
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async function start() {
|
|
81
81
|
checkWorkspaces()
|
|
82
82
|
|
|
83
|
-
if (_args[0]
|
|
84
|
-
_noAppendNextLine = false
|
|
85
|
-
console.log(warnStr("You can start with .help, use * to expand context"))
|
|
86
|
-
} else if (_args[0]) {
|
|
83
|
+
if (_args[0]) {
|
|
87
84
|
if (_noAppendNextLine) {
|
|
88
85
|
_cmdMap = objDataFile(_cmdMapFile)
|
|
89
86
|
}
|
|
@@ -95,10 +92,8 @@ async function start() {
|
|
|
95
92
|
}).join(' ')
|
|
96
93
|
await wrapperInput(line)
|
|
97
94
|
} else {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
listCmd();
|
|
95
|
+
_noAppendNextLine = false
|
|
96
|
+
console.log(warnStr("You can start with .help, use * to expand context"))
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
|
|
@@ -346,7 +341,6 @@ $defArgs({
|
|
|
346
341
|
})
|
|
347
342
|
|
|
348
343
|
let {} = $lib // 引用内置资源
|
|
349
|
-
let [] = await $require() // 模糊引用脚本资源
|
|
350
344
|
|
|
351
345
|
console.log($args)
|
|
352
346
|
|
|
@@ -358,7 +352,6 @@ A test init script
|
|
|
358
352
|
*/
|
|
359
353
|
|
|
360
354
|
let {} = $lib // 引用内置资源
|
|
361
|
-
let [] = await $require() // 模糊引用脚本资源
|
|
362
355
|
|
|
363
356
|
return {}
|
|
364
357
|
`;
|
|
@@ -383,7 +376,7 @@ function rename(dir, oldName, newName) {
|
|
|
383
376
|
info(`${_new} renamed`)
|
|
384
377
|
}
|
|
385
378
|
_cmdMap = {
|
|
386
|
-
1: toUniqueName(
|
|
379
|
+
1: toUniqueName(_new)
|
|
387
380
|
}
|
|
388
381
|
listCmd()
|
|
389
382
|
}
|
|
@@ -696,11 +689,13 @@ const keywordDef = {
|
|
|
696
689
|
list: {
|
|
697
690
|
comment: '查看文件列表',
|
|
698
691
|
exeFn: (args) => {
|
|
699
|
-
|
|
692
|
+
if (args.length > 0) {
|
|
693
|
+
_cmdMap = arrayToCmdMap(filterCmd(args.length > 0 ? args.join(' '):[',']))
|
|
694
|
+
}
|
|
700
695
|
listCmd()
|
|
701
696
|
},
|
|
702
697
|
args: {
|
|
703
|
-
queryParams: '条件参数(param1,param2 param3 ...)'
|
|
698
|
+
queryParams: '条件参数(param1,param2 param3 ...), [,]代表全部'
|
|
704
699
|
},
|
|
705
700
|
short: 'l'
|
|
706
701
|
},
|
|
@@ -789,7 +784,7 @@ const keywordDef = {
|
|
|
789
784
|
fileIndex: '文件下标',
|
|
790
785
|
newName: '新名字'
|
|
791
786
|
},
|
|
792
|
-
short: '
|
|
787
|
+
short: 'n'
|
|
793
788
|
},
|
|
794
789
|
edit: {
|
|
795
790
|
comment: '编辑文件',
|
|
@@ -895,10 +890,13 @@ const keywordDef = {
|
|
|
895
890
|
exeFn: async (args) => {
|
|
896
891
|
let newWorkspace = args.join(' ')
|
|
897
892
|
if (newWorkspace) {
|
|
898
|
-
|
|
893
|
+
let workspaces = Object.values($workspaceMap)
|
|
894
|
+
workspaces.push(newWorkspace)
|
|
895
|
+
arrayDataFile(_workspaceConfigFile, () => workspaces)
|
|
899
896
|
}
|
|
900
897
|
checkWorkspaces()
|
|
901
|
-
let
|
|
898
|
+
let workspaces = Object.values($workspaceMap)
|
|
899
|
+
let items = workspaces.map((path, index) => {
|
|
902
900
|
return {
|
|
903
901
|
index: ' ' + (index + 1),
|
|
904
902
|
name: getSpaceFromDir(path),
|
|
@@ -912,11 +910,36 @@ const keywordDef = {
|
|
|
912
910
|
},
|
|
913
911
|
short: 'w'
|
|
914
912
|
},
|
|
913
|
+
uninstall: {
|
|
914
|
+
comment: '卸载工作空间',
|
|
915
|
+
exeFn: async (args) => {
|
|
916
|
+
let workspaces = Object.values($workspaceMap)
|
|
917
|
+
let items = workspaces.map((path, index) => {
|
|
918
|
+
return {
|
|
919
|
+
index: ' ' + (index + 1),
|
|
920
|
+
name: getSpaceFromDir(path),
|
|
921
|
+
path
|
|
922
|
+
}
|
|
923
|
+
})
|
|
924
|
+
console.table(items)
|
|
925
|
+
let index = await nextLine(line => line, "index: ")
|
|
926
|
+
let workspace = workspaces[index - 1]
|
|
927
|
+
if (workspace) {
|
|
928
|
+
workspaces = workspaces.filter(i => i !== workspace);
|
|
929
|
+
arrayDataFile(_workspaceConfigFile, () => workspaces);
|
|
930
|
+
checkWorkspaces()
|
|
931
|
+
} else {
|
|
932
|
+
warn('invalid args')
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
short: 'u'
|
|
936
|
+
},
|
|
915
937
|
switch: {
|
|
916
938
|
comment: '切换工作空间',
|
|
917
939
|
exeFn: async (args) => {
|
|
918
940
|
checkWorkspaces()
|
|
919
|
-
let
|
|
941
|
+
let workspaces = Object.values($workspaceMap)
|
|
942
|
+
let items = workspaces.map((path, index) => {
|
|
920
943
|
return {
|
|
921
944
|
index: ' ' + (index + 1),
|
|
922
945
|
name: getSpaceFromDir(path),
|
|
@@ -925,9 +948,11 @@ const keywordDef = {
|
|
|
925
948
|
})
|
|
926
949
|
console.table(items)
|
|
927
950
|
let index = trim(await nextLine(line => line, "switch workspace: "));
|
|
928
|
-
if (index &&
|
|
929
|
-
let workspace =
|
|
951
|
+
if (index && workspaces[index - 1]) {
|
|
952
|
+
let workspace = workspaces[index - 1];
|
|
930
953
|
initWorkspace(getSpaceFromDir(workspace))
|
|
954
|
+
} else {
|
|
955
|
+
warn('no items')
|
|
931
956
|
}
|
|
932
957
|
},
|
|
933
958
|
short: 'S'
|
|
@@ -942,6 +967,25 @@ const keywordDef = {
|
|
|
942
967
|
},
|
|
943
968
|
short: 'a'
|
|
944
969
|
},
|
|
970
|
+
run: {
|
|
971
|
+
comment: '快捷执行',
|
|
972
|
+
exeFn: async (args) => {
|
|
973
|
+
if (!args[0]) {
|
|
974
|
+
warn('invalid args')
|
|
975
|
+
return
|
|
976
|
+
}
|
|
977
|
+
let cmds = filterCmd('^e ' + toJsirFileName(args[0]).replace(/^[eif]\s+/, '') + '$')
|
|
978
|
+
_cmdMap = arrayToCmdMap(cmds)
|
|
979
|
+
listCmd()
|
|
980
|
+
if (cmds.length === 1) {
|
|
981
|
+
await runCmd('1 ' + args.slice(1).join(' '))
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
args: {
|
|
985
|
+
fileNameReg: '文件名称匹配'
|
|
986
|
+
},
|
|
987
|
+
short: 'r'
|
|
988
|
+
},
|
|
945
989
|
quit: {
|
|
946
990
|
comment: '退出',
|
|
947
991
|
exeFn: (args) => {
|
|
@@ -1104,17 +1148,12 @@ function getJsirFileSuffix(name) {
|
|
|
1104
1148
|
|
|
1105
1149
|
function initWorkspace(space) {
|
|
1106
1150
|
let current = getConfig("workspace");
|
|
1107
|
-
if (current && space && current === space) {
|
|
1108
|
-
// 值没有改变
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
1151
|
let workspace = space || current || 'local'
|
|
1112
|
-
if (
|
|
1113
|
-
|
|
1114
|
-
global.$defaultSpace = workspace;
|
|
1115
|
-
} else {
|
|
1116
|
-
global.$defaultSpace = workspace;
|
|
1152
|
+
if (!$workspaceMap[current]) {
|
|
1153
|
+
workspace = 'local'
|
|
1117
1154
|
}
|
|
1155
|
+
setConfig("workspace", workspace)
|
|
1156
|
+
global.$defaultSpace = workspace;
|
|
1118
1157
|
}
|
|
1119
1158
|
|
|
1120
1159
|
function filterCmd(arg){
|
|
@@ -1122,11 +1161,11 @@ function filterCmd(arg){
|
|
|
1122
1161
|
let spaceName
|
|
1123
1162
|
if (arg.indexOf('/') !== -1) {
|
|
1124
1163
|
let index = arg.indexOf('/');
|
|
1125
|
-
spaceName = arg.substring(0, index) || $defaultSpace
|
|
1164
|
+
spaceName = trim(arg.substring(0, index)) || $defaultSpace
|
|
1126
1165
|
arg = trim(arg.substring(index + 1))
|
|
1127
1166
|
}
|
|
1128
1167
|
let cmds = []
|
|
1129
|
-
for (let workspace of
|
|
1168
|
+
for (let workspace of Object.values($workspaceMap)) {
|
|
1130
1169
|
let spaceTmp = getSpaceFromDir(workspace);
|
|
1131
1170
|
if (!spaceName || spaceName === spaceTmp) {
|
|
1132
1171
|
cmds.push(..._filterCmd(workspace, arg));
|
|
@@ -1514,11 +1553,14 @@ async function evalText($text = '', $cmdName = '', $args = []) {
|
|
|
1514
1553
|
} else {
|
|
1515
1554
|
currSpace = $defaultSpace
|
|
1516
1555
|
}
|
|
1517
|
-
let $
|
|
1556
|
+
let $requires = async (...matchItems) => {
|
|
1518
1557
|
return await _requireSources(currSpace, ...matchItems)
|
|
1519
1558
|
}
|
|
1559
|
+
let $require = async (matchItem, printLog) => {
|
|
1560
|
+
return (await _requireSources(currSpace, matchItem, printLog))[0]
|
|
1561
|
+
}
|
|
1520
1562
|
try {
|
|
1521
|
-
return await evalCode($text, $cmdName, $args, $require, $
|
|
1563
|
+
return await evalCode($text, $cmdName, $args, $data, $require, $requires,
|
|
1522
1564
|
nextLine, nextText, setTips, delTips, wrapperInput, filterCmd,
|
|
1523
1565
|
currSpace, $log, $draft, $config, $homeDir, $lib)
|
|
1524
1566
|
} 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,
|