jsir 1.3.0 → 1.3.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/ooa.js +398 -364
- package/evalCode.js +7 -10
- package/package.json +2 -6
- package/util.js +40 -4
package/cmd/ooa.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const {
|
|
3
|
-
|
|
3
|
+
getLibDataDir, trim, regEach, getConfig, mkdir, reget,
|
|
4
4
|
getCbText, e, sleep, objDataFile, setConfig, vl, md5, BigNumber,
|
|
5
5
|
info, warn, error, arrayDataFile, infoStr, warnStr, errorStack,
|
|
6
|
-
getInfo, ei, pad, msgStr, getType,
|
|
6
|
+
getInfo, ei, pad, msgStr, getType,
|
|
7
7
|
errorTag, isArgsMatch, draftQuery
|
|
8
8
|
} = require('../util')
|
|
9
9
|
const evalCode = require('../evalCode')
|
|
@@ -20,7 +20,6 @@ const _home = _libDataDir + '/ooa'
|
|
|
20
20
|
const _args = process.argv.slice(2).map(trim)
|
|
21
21
|
const _history9 = []
|
|
22
22
|
const _tipsOnRm = {}
|
|
23
|
-
const _setting = require('../setting')
|
|
24
23
|
const readline = require("readline");
|
|
25
24
|
const _fileWatcherMap = {}
|
|
26
25
|
|
|
@@ -45,86 +44,8 @@ try {
|
|
|
45
44
|
|
|
46
45
|
let _noAppendNextLine = true
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
comment: "交互界面",
|
|
51
|
-
},
|
|
52
|
-
add: {
|
|
53
|
-
comment: "新增脚本",
|
|
54
|
-
cmd: ['@e ']
|
|
55
|
-
},
|
|
56
|
-
note: {
|
|
57
|
-
comment: "新增笔记",
|
|
58
|
-
cmd: ['@']
|
|
59
|
-
},
|
|
60
|
-
config: {
|
|
61
|
-
comment: "配置",
|
|
62
|
-
cmd: []
|
|
63
|
-
},
|
|
64
|
-
init: {
|
|
65
|
-
comment: "新增初始资源",
|
|
66
|
-
cmd: ['@i ']
|
|
67
|
-
},
|
|
68
|
-
file: {
|
|
69
|
-
comment: "工作脚本模式",
|
|
70
|
-
cmd: ['@f ']
|
|
71
|
-
},
|
|
72
|
-
rm: {
|
|
73
|
-
comment: "删除脚本",
|
|
74
|
-
cmd: ['@-']
|
|
75
|
-
},
|
|
76
|
-
edit: {
|
|
77
|
-
comment: "编辑脚本",
|
|
78
|
-
cmd: ['@w']
|
|
79
|
-
},
|
|
80
|
-
diff: {
|
|
81
|
-
comment: "比较脚本变更",
|
|
82
|
-
cmd: ['@c']
|
|
83
|
-
},
|
|
84
|
-
push: {
|
|
85
|
-
comment: "推送到本地仓库",
|
|
86
|
-
cmd: ['@#']
|
|
87
|
-
},
|
|
88
|
-
pull: {
|
|
89
|
-
comment: "更新工作空间脚本",
|
|
90
|
-
cmd: ['@*']
|
|
91
|
-
},
|
|
92
|
-
repo: {
|
|
93
|
-
comment: "设置本地仓库目录",
|
|
94
|
-
cmd: ['@% ']
|
|
95
|
-
},
|
|
96
|
-
lib: {
|
|
97
|
-
comment: "查看内置资源",
|
|
98
|
-
cmd: ['*$lib ']
|
|
99
|
-
},
|
|
100
|
-
deps: {
|
|
101
|
-
comment: "查看依赖",
|
|
102
|
-
cmd: ['@^']
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
Object.keys(_mainCmdMap).forEach(key => {
|
|
107
|
-
let val = _mainCmdMap[key];
|
|
108
|
-
delete _mainCmdMap[key];
|
|
109
|
-
_mainCmdMap['--' + key] = val;
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
function isMainCmd(mainList) {
|
|
113
|
-
if (!mainList) {
|
|
114
|
-
mainList = Object.keys(_mainCmdMap)
|
|
115
|
-
} else {
|
|
116
|
-
mainList = mainList.map(item => '--' + item);
|
|
117
|
-
}
|
|
118
|
-
return mainList.indexOf(_args[0]) !== -1;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function initRuntime() {
|
|
122
|
-
global.$lib = {...require('../util'), evalText}
|
|
123
|
-
let runtimeScript = 'e RUNTIME.js'
|
|
124
|
-
let runtimePath = getLibDataDir() + '/ooa/' + runtimeScript
|
|
125
|
-
if (_fs.existsSync(runtimePath)) {
|
|
126
|
-
await runCmd('', runtimeScript)
|
|
127
|
-
}
|
|
47
|
+
function initRuntime() {
|
|
48
|
+
global.$lib = {...require('../util')}
|
|
128
49
|
}
|
|
129
50
|
|
|
130
51
|
function getFileOpenExe(fileName) {
|
|
@@ -142,68 +63,14 @@ function getFileOpenExe(fileName) {
|
|
|
142
63
|
return exe || 'idea';
|
|
143
64
|
}
|
|
144
65
|
|
|
145
|
-
|
|
66
|
+
async function start() {
|
|
146
67
|
mkdir(_home)
|
|
147
|
-
if (isMainCmd(['config'])) {
|
|
148
|
-
let fileName = 'config.json';
|
|
149
|
-
let configFile = getLibDataDir() + '/' + fileName;
|
|
150
|
-
ei('vi', [configFile])
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
68
|
dealSourceCmds()
|
|
155
69
|
|
|
156
|
-
if (
|
|
157
|
-
|
|
70
|
+
if (_args[0] === '--repl') {
|
|
71
|
+
initRuntime()
|
|
158
72
|
_noAppendNextLine = false
|
|
159
|
-
|
|
160
|
-
if (_noAppendNextLine) {
|
|
161
|
-
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (isMainCmd(['edit', 'rm', 'diff', 'push', 'pull', 'deps'])
|
|
165
|
-
&& _args[1] && !/^\d+$/.test(_args[1])) {
|
|
166
|
-
warn('wrong args')
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
if (isMainCmd(['lib'])) {
|
|
170
|
-
await initRuntime()
|
|
171
|
-
}
|
|
172
|
-
if (isMainCmd(['add', 'note', 'init'])
|
|
173
|
-
&& (!_args[1] || /^\d+$/.test(_args[1]))) {
|
|
174
|
-
warn('wrong args')
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
let argStr = _args.slice(1).map(i => {
|
|
179
|
-
if (/\s+/.test(i) || !i) {
|
|
180
|
-
i = `"${i}"`
|
|
181
|
-
}
|
|
182
|
-
return i
|
|
183
|
-
}).join(' ').replace(/^@/, '')
|
|
184
|
-
if (isMainCmd(['edit', 'rm', 'diff', 'push', 'pull', 'deps']) && !trim(argStr)) {
|
|
185
|
-
_args[0] = '@'
|
|
186
|
-
}
|
|
187
|
-
if (isMainCmd(['file'])) {
|
|
188
|
-
await initRuntime()
|
|
189
|
-
}
|
|
190
|
-
let info = _mainCmdMap[_args[0]]
|
|
191
|
-
if (info) {
|
|
192
|
-
for(let cmd of info.cmd) {
|
|
193
|
-
await wrapperInput(`${cmd}${argStr}`)
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
await wrapperInput(`${_args[0]}${argStr}`)
|
|
197
|
-
}
|
|
198
|
-
} else if (_args[0] && _args[0].startsWith('--')) {
|
|
199
|
-
let cols = []
|
|
200
|
-
for (let key of Object.keys(_mainCmdMap)) {
|
|
201
|
-
cols.push({
|
|
202
|
-
cmd: key,
|
|
203
|
-
comment: _mainCmdMap[key].comment
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
console.table(cols)
|
|
73
|
+
console.log(warnStr("You can start with .help"))
|
|
207
74
|
} else if (_args[0]) {
|
|
208
75
|
if (_noAppendNextLine) {
|
|
209
76
|
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
@@ -213,10 +80,10 @@ run(async () => {
|
|
|
213
80
|
i = `"${i}"`
|
|
214
81
|
}
|
|
215
82
|
return i
|
|
216
|
-
}).join(' ')
|
|
83
|
+
}).join(' ')
|
|
217
84
|
if (/^\d+$/.test(_args[0])) {
|
|
218
85
|
if (_args[0] === '0' || (_cmdMap[_args[0]] && ['e ', 'f '].filter(i => _cmdMap[_args[0]].startsWith(i)).length > 0)) {
|
|
219
|
-
|
|
86
|
+
initRuntime()
|
|
220
87
|
}
|
|
221
88
|
}
|
|
222
89
|
await wrapperInput(line)
|
|
@@ -224,9 +91,9 @@ run(async () => {
|
|
|
224
91
|
if (_noAppendNextLine) {
|
|
225
92
|
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
226
93
|
}
|
|
227
|
-
|
|
94
|
+
listCmd();
|
|
228
95
|
}
|
|
229
|
-
}
|
|
96
|
+
}
|
|
230
97
|
|
|
231
98
|
async function getFileWatcher(fileName, workFilePath, text) {
|
|
232
99
|
info("workFile open " + workFilePath)
|
|
@@ -257,6 +124,10 @@ async function workFile(name) {
|
|
|
257
124
|
name = 'workFile'
|
|
258
125
|
}
|
|
259
126
|
let fileName = `f ${toJsirFileName(name)}`
|
|
127
|
+
await watchFile(fileName)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function watchFile(fileName) {
|
|
260
131
|
let workFilePath = `${_home}/${fileName}`;
|
|
261
132
|
if (!_fs.existsSync(workFilePath)) {
|
|
262
133
|
_fs.writeFileSync(workFilePath, '');
|
|
@@ -272,7 +143,7 @@ async function workFile(name) {
|
|
|
272
143
|
if (trim(exeStr)) {
|
|
273
144
|
try {
|
|
274
145
|
console.log("\n" + infoStr("------ workFile run ------"))
|
|
275
|
-
await
|
|
146
|
+
await wrapperInput("# " + exeStr)
|
|
276
147
|
} catch (e) {
|
|
277
148
|
error(e)
|
|
278
149
|
}
|
|
@@ -303,6 +174,7 @@ function getExeStr(oldText, newText) {
|
|
|
303
174
|
}
|
|
304
175
|
let oldLine = olds[i];
|
|
305
176
|
let newLine = news[i];
|
|
177
|
+
|
|
306
178
|
if (reg.test(trim(newLine))) {
|
|
307
179
|
if (flagChange) {
|
|
308
180
|
break;
|
|
@@ -317,6 +189,9 @@ function getExeStr(oldText, newText) {
|
|
|
317
189
|
currText = []
|
|
318
190
|
} else {
|
|
319
191
|
currText.push(newLine)
|
|
192
|
+
if (flagChange && trim(newLine).endsWith(";;")) {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
320
195
|
}
|
|
321
196
|
|
|
322
197
|
if (oldLine !== newLine) {
|
|
@@ -451,8 +326,6 @@ function dealSourceCmds() {
|
|
|
451
326
|
_fs.writeFileSync(_home + "/" + item, String(_fs.readFileSync(source + "/" + item)))
|
|
452
327
|
}
|
|
453
328
|
})
|
|
454
|
-
} else {
|
|
455
|
-
warn(`require config.jsLibSource, run [${_setting.name} repo]`)
|
|
456
329
|
}
|
|
457
330
|
}
|
|
458
331
|
|
|
@@ -683,12 +556,7 @@ async function _wrapperInput(str) {
|
|
|
683
556
|
let isStar = str.startsWith('*')
|
|
684
557
|
let text = trim(str.replace(/^[$#*]/, ''))
|
|
685
558
|
if (is$) {
|
|
686
|
-
|
|
687
|
-
if (result === $lib) {
|
|
688
|
-
console.table(objProfileRows(result))
|
|
689
|
-
} else {
|
|
690
|
-
console.log(result)
|
|
691
|
-
}
|
|
559
|
+
console.log(await evalText('return ' + text))
|
|
692
560
|
} else if (isStar) {
|
|
693
561
|
let items = text.split(/\s+/).map(trim).filter(i => i)
|
|
694
562
|
let result = await evalText('return ' + items[0])
|
|
@@ -711,14 +579,12 @@ async function _wrapperInput(str) {
|
|
|
711
579
|
} else {
|
|
712
580
|
await evalText(text)
|
|
713
581
|
}
|
|
714
|
-
} else if (str.match(
|
|
715
|
-
let
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (fstr) {
|
|
719
|
-
await dealKeyword(str, strs, fstr, ostr)
|
|
582
|
+
} else if (str.match(/^\./)) {
|
|
583
|
+
let argsStr = trim(str.substring(1))
|
|
584
|
+
if (argsStr) {
|
|
585
|
+
await dealKeyword(argsStr)
|
|
720
586
|
} else {
|
|
721
|
-
|
|
587
|
+
help()
|
|
722
588
|
}
|
|
723
589
|
} else if (!str.split(/\s+/)[0].match(/^\d+$/)) {
|
|
724
590
|
_cmdMap = filterCmd(str.split(/\s+/))
|
|
@@ -743,6 +609,18 @@ async function _wrapperInput(str) {
|
|
|
743
609
|
}
|
|
744
610
|
}
|
|
745
611
|
|
|
612
|
+
|
|
613
|
+
function help() {
|
|
614
|
+
console.nable(Object.keys(keywordDef).map(key => {
|
|
615
|
+
let item = keywordDef[key];
|
|
616
|
+
return {
|
|
617
|
+
keyword: ' ' + warnStr(`.${key}`),
|
|
618
|
+
short: ' ' + warnStr(`.${item.short}`),
|
|
619
|
+
comment: [item.comment, item.args ? getArgComments(item.args).join('\n'):''].filter(i => i).join("\n"),
|
|
620
|
+
}
|
|
621
|
+
}))
|
|
622
|
+
}
|
|
623
|
+
|
|
746
624
|
function delTipsByIndex(idxs) {
|
|
747
625
|
let keys = Object.keys($tips)
|
|
748
626
|
let indexKeyMap = {}
|
|
@@ -762,203 +640,336 @@ function delTipsByIndex(idxs) {
|
|
|
762
640
|
delTips(...params)
|
|
763
641
|
}
|
|
764
642
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
let
|
|
798
|
-
if (!
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
_fs.
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
} else if (/^v\d*$/.test(fstr)) {
|
|
806
|
-
let name = _cmdMap[trim(fstr.replace(/^v/, ''))]
|
|
807
|
-
if (!name) {
|
|
808
|
-
warn("no items")
|
|
809
|
-
} else {
|
|
810
|
-
let path = _home + '/' + _cmdMap[trim(fstr.replace(/^v/, ''))]
|
|
811
|
-
let text =trim(trim(str.substring(1)).replace(/^v\d+/, ''))
|
|
812
|
-
if (!text) {
|
|
813
|
-
text = await getCbText()
|
|
814
|
-
}
|
|
815
|
-
if (text) {
|
|
816
|
-
_fs.writeFileSync(path, text)
|
|
643
|
+
const keywordDef = {
|
|
644
|
+
help: {
|
|
645
|
+
comment: '帮助文档',
|
|
646
|
+
exeFn: (args) => {
|
|
647
|
+
help()
|
|
648
|
+
},
|
|
649
|
+
short: 'H'
|
|
650
|
+
},
|
|
651
|
+
list: {
|
|
652
|
+
comment: '查看本地文件列表',
|
|
653
|
+
exeFn: (args) => {
|
|
654
|
+
_cmdMap = filterCmd(args.length > 0 ? args:[','])
|
|
655
|
+
listCmd()
|
|
656
|
+
},
|
|
657
|
+
args: {
|
|
658
|
+
queryParams: '条件参数(param1,param2 param3 ...)'
|
|
659
|
+
},
|
|
660
|
+
short: 'l'
|
|
661
|
+
},
|
|
662
|
+
clear: {
|
|
663
|
+
comment: '清除任务',
|
|
664
|
+
exeFn: (args) => {
|
|
665
|
+
delTipsByIndex(args.filter(i => i))
|
|
666
|
+
},
|
|
667
|
+
args: {
|
|
668
|
+
tipIndex: '左侧提示符下标,可以多个用空格隔开'
|
|
669
|
+
},
|
|
670
|
+
short: 'C'
|
|
671
|
+
},
|
|
672
|
+
see: {
|
|
673
|
+
comment: '查看本地文件',
|
|
674
|
+
exeFn: (args) => {
|
|
675
|
+
let name = _cmdMap[args[0]]
|
|
676
|
+
if (!name) {
|
|
677
|
+
warn("no items")
|
|
678
|
+
} else {
|
|
679
|
+
let path = _home + '/' + name
|
|
680
|
+
let sourceStr = String(_fs.readFileSync(path))
|
|
681
|
+
console.log(sourceStr)
|
|
817
682
|
}
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
683
|
+
},
|
|
684
|
+
args: {
|
|
685
|
+
fileIndex: '文件下标'
|
|
686
|
+
},
|
|
687
|
+
short: 's'
|
|
688
|
+
},
|
|
689
|
+
rm: {
|
|
690
|
+
comment: '删除本地文件以及其源文件',
|
|
691
|
+
exeFn: (args) => {
|
|
692
|
+
let name = _cmdMap[args[0]]
|
|
693
|
+
if (!name) {
|
|
694
|
+
warn("no items")
|
|
695
|
+
} else {
|
|
696
|
+
let path = _home + '/' + name
|
|
697
|
+
_fs.unlinkSync(path)
|
|
827
698
|
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
828
699
|
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
829
700
|
if (_fs.existsSync(jsLibDir + '/' + name)) {
|
|
830
|
-
|
|
701
|
+
_fs.unlinkSync(jsLibDir + '/' + name)
|
|
831
702
|
}
|
|
832
703
|
}
|
|
833
|
-
|
|
704
|
+
info(`${path} removed`)
|
|
834
705
|
}
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
706
|
+
},
|
|
707
|
+
args: {
|
|
708
|
+
fileIndex: '文件下标'
|
|
709
|
+
},
|
|
710
|
+
short: 'R'
|
|
711
|
+
},
|
|
712
|
+
rename: {
|
|
713
|
+
comment: '重命名本地文件以及其源文件',
|
|
714
|
+
exeFn: (args) => {
|
|
715
|
+
let name = _cmdMap[args[0]]
|
|
716
|
+
if (!name) {
|
|
717
|
+
warn("no items")
|
|
718
|
+
} else {
|
|
719
|
+
let newName =trim(args.slice(1).join(" "))
|
|
720
|
+
if (newName) {
|
|
721
|
+
newName = toJsirFileName(newName)
|
|
722
|
+
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
723
|
+
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
724
|
+
if (_fs.existsSync(jsLibDir + '/' + name)) {
|
|
725
|
+
rename(jsLibDir, name, newName)
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
rename(_home, name, newName, true)
|
|
847
729
|
}
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
args: {
|
|
733
|
+
fileIndex: '文件下标',
|
|
734
|
+
newName: '新名字'
|
|
735
|
+
},
|
|
736
|
+
short: 'r'
|
|
737
|
+
},
|
|
738
|
+
source: {
|
|
739
|
+
comment: '查看源文件',
|
|
740
|
+
exeFn: (args) => {
|
|
741
|
+
let name = _cmdMap[args[0]]
|
|
742
|
+
if (!name) {
|
|
743
|
+
warn("no items")
|
|
848
744
|
} else {
|
|
849
|
-
|
|
745
|
+
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
746
|
+
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
747
|
+
let sFile = jsLibDir + "/" + name
|
|
748
|
+
if (_fs.existsSync(sFile)) {
|
|
749
|
+
let sourceStr = String(_fs.readFileSync(sFile))
|
|
750
|
+
console.log(sourceStr)
|
|
751
|
+
}
|
|
752
|
+
} else {
|
|
753
|
+
warn('require origin workspace')
|
|
754
|
+
}
|
|
850
755
|
}
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
756
|
+
},
|
|
757
|
+
args: {
|
|
758
|
+
fileIndex: '文件下标'
|
|
759
|
+
},
|
|
760
|
+
short: 'S'
|
|
761
|
+
},
|
|
762
|
+
get: {
|
|
763
|
+
comment: '将源文件内容覆盖到本地文件',
|
|
764
|
+
exeFn: (args) => {
|
|
765
|
+
let name = _cmdMap[args[0]]
|
|
766
|
+
if (!args[0]) {
|
|
767
|
+
listCmd('*')
|
|
768
|
+
} else if (!name) {
|
|
769
|
+
warn("no items")
|
|
770
|
+
} else {
|
|
771
|
+
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
772
|
+
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
773
|
+
let sFile = jsLibDir + "/" + name
|
|
774
|
+
if (_fs.existsSync(sFile)) {
|
|
775
|
+
let sourceStr = String(_fs.readFileSync(sFile))
|
|
776
|
+
let path = _home + '/' + name
|
|
777
|
+
if (sourceStr) {
|
|
778
|
+
_fs.writeFileSync(path, sourceStr)
|
|
779
|
+
}
|
|
867
780
|
}
|
|
781
|
+
info(`${name} pulled`)
|
|
782
|
+
} else {
|
|
783
|
+
warn('require origin workspace')
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
args: {
|
|
788
|
+
fileIndex: '文件下标'
|
|
789
|
+
},
|
|
790
|
+
short: 'g'
|
|
791
|
+
},
|
|
792
|
+
push: {
|
|
793
|
+
comment: '将本地文件内容覆盖到源文件',
|
|
794
|
+
exeFn: (args) => {
|
|
795
|
+
let name = _cmdMap[args[0]]
|
|
796
|
+
if (!args[0]) {
|
|
797
|
+
listCmd('#')
|
|
798
|
+
} else if (!name) {
|
|
799
|
+
warn("no items")
|
|
800
|
+
} else {
|
|
801
|
+
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
802
|
+
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
803
|
+
_fs.writeFileSync(jsLibDir + "/" + name, String(_fs.readFileSync(_home + '/' + name)))
|
|
804
|
+
info(`${name} pushed`)
|
|
805
|
+
} else {
|
|
806
|
+
warn('require origin workspace')
|
|
868
807
|
}
|
|
869
|
-
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
args: {
|
|
811
|
+
fileIndex: '文件下标'
|
|
812
|
+
},
|
|
813
|
+
short: 'p'
|
|
814
|
+
},
|
|
815
|
+
unsync: {
|
|
816
|
+
comment: '查看未同步源文件的本地文件列表',
|
|
817
|
+
exeFn: (args) => {
|
|
818
|
+
listCmd('')
|
|
819
|
+
},
|
|
820
|
+
short: 'u'
|
|
821
|
+
},
|
|
822
|
+
edit: {
|
|
823
|
+
comment: '编辑本地文件',
|
|
824
|
+
exeFn: async (args) => {
|
|
825
|
+
let name = _cmdMap[args[0]]
|
|
826
|
+
if (!name) {
|
|
827
|
+
warn("no items")
|
|
870
828
|
} else {
|
|
871
|
-
|
|
829
|
+
let path = _home + '/' + name
|
|
830
|
+
await e(`"${getFileOpenExe(name)}" "${path}"`)
|
|
872
831
|
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
832
|
+
},
|
|
833
|
+
args: {
|
|
834
|
+
fileIndex: '文件下标'
|
|
835
|
+
},
|
|
836
|
+
short: 'e'
|
|
837
|
+
},
|
|
838
|
+
compare: {
|
|
839
|
+
comment: '比较本地文件和源文件',
|
|
840
|
+
exeFn: async (args) => {
|
|
841
|
+
let name = _cmdMap[args[0]]
|
|
842
|
+
if (!name) {
|
|
843
|
+
warn("no items")
|
|
885
844
|
} else {
|
|
886
|
-
|
|
845
|
+
let path = _home + '/' + name
|
|
846
|
+
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
847
|
+
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
848
|
+
let sPath = jsLibDir + "/" + name
|
|
849
|
+
await e(`idea diff "${sPath}" "${path}"`)
|
|
850
|
+
} else {
|
|
851
|
+
warn('require origin workspace')
|
|
852
|
+
}
|
|
887
853
|
}
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
let name = _cmdMap[trim(fstr.replace(/^c/, ''))]
|
|
901
|
-
if (!name) {
|
|
902
|
-
warn("no items")
|
|
903
|
-
} else {
|
|
904
|
-
let path = _home + '/' + name
|
|
905
|
-
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
906
|
-
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
907
|
-
let sPath = jsLibDir + "/" + name
|
|
908
|
-
await e(`idea diff "${sPath}" "${path}"`)
|
|
854
|
+
},
|
|
855
|
+
args: {
|
|
856
|
+
fileIndex: '文件下标',
|
|
857
|
+
},
|
|
858
|
+
short: 'c'
|
|
859
|
+
},
|
|
860
|
+
deps: {
|
|
861
|
+
comment: '查看文件依赖',
|
|
862
|
+
exeFn: (args) => {
|
|
863
|
+
let name = _cmdMap[args[0]]
|
|
864
|
+
if (!name) {
|
|
865
|
+
warn("no items")
|
|
909
866
|
} else {
|
|
910
|
-
|
|
867
|
+
let md5Keys = getScriptRequires(name);
|
|
868
|
+
_cmdMap = filterCmd(md5Keys)
|
|
869
|
+
listCmd()
|
|
911
870
|
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
871
|
+
},
|
|
872
|
+
args: {
|
|
873
|
+
fileIndex: '文件下标'
|
|
874
|
+
},
|
|
875
|
+
short: 'd'
|
|
876
|
+
},
|
|
877
|
+
history: {
|
|
878
|
+
comment: '查看执行记录',
|
|
879
|
+
exeFn: (args) => {
|
|
880
|
+
hisToCmdMap()
|
|
920
881
|
listCmd()
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
console.log(`${i+1}: ${_repos[i]}`)
|
|
882
|
+
},
|
|
883
|
+
short: 'h'
|
|
884
|
+
},
|
|
885
|
+
file: {
|
|
886
|
+
comment: '工作文件模式',
|
|
887
|
+
exeFn: async (args) => {
|
|
888
|
+
if (args.length === 0) {
|
|
889
|
+
await workFile('')
|
|
890
|
+
} else {
|
|
891
|
+
let name = _cmdMap[args[0]]
|
|
892
|
+
if (!name) {
|
|
893
|
+
warn("no items")
|
|
894
|
+
} else {
|
|
895
|
+
await watchFile(name)
|
|
896
|
+
}
|
|
937
897
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
898
|
+
},
|
|
899
|
+
args: {
|
|
900
|
+
fileIndex: '文件下标'
|
|
901
|
+
},
|
|
902
|
+
short: 'f'
|
|
903
|
+
},
|
|
904
|
+
workspace: {
|
|
905
|
+
comment: '源空间管理',
|
|
906
|
+
exeFn: async (args) => {
|
|
907
|
+
let newRepo = args.join(' ')
|
|
908
|
+
let currRepo = getConfig('jsLibSource');
|
|
909
|
+
if (!newRepo) {
|
|
910
|
+
console.log(`current: ${currRepo}`)
|
|
911
|
+
_repos = _repos.filter(i => _fs.existsSync(i))
|
|
912
|
+
for(let i = 0; i<_repos.length; i++) {
|
|
913
|
+
console.log(`${i+1}: ${_repos[i]}`)
|
|
914
|
+
}
|
|
915
|
+
let repoStr = trim(await nextLine(line => line, 'reset(or blank): '))
|
|
916
|
+
if (/^\d+$/.test(repoStr)) {
|
|
917
|
+
repoStr = _repos[Number(repoStr) - 1]
|
|
918
|
+
}
|
|
919
|
+
newRepo = repoStr
|
|
941
920
|
}
|
|
942
|
-
newRepo
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
921
|
+
if (newRepo && newRepo !== currRepo) {
|
|
922
|
+
if (_fs.existsSync(newRepo)) {
|
|
923
|
+
setConfig('jsLibSource', newRepo)
|
|
924
|
+
if (_repos.indexOf(newRepo) === -1) {
|
|
925
|
+
_repos.push(newRepo)
|
|
926
|
+
}
|
|
927
|
+
arrayDataFile('repos.json', () => _repos)
|
|
928
|
+
dealSourceCmds()
|
|
929
|
+
} else {
|
|
930
|
+
warn(`repo ${newRepo} not exist`)
|
|
949
931
|
}
|
|
950
|
-
arrayDataFile('repos.json', () => _repos)
|
|
951
|
-
dealSourceCmds()
|
|
952
|
-
} else {
|
|
953
|
-
warn(`repo ${newRepo} not exist`)
|
|
954
932
|
}
|
|
933
|
+
},
|
|
934
|
+
short: 'w'
|
|
935
|
+
},
|
|
936
|
+
add: {
|
|
937
|
+
comment: '新增文件',
|
|
938
|
+
exeFn: async (args) => {
|
|
939
|
+
await save(args)
|
|
940
|
+
},
|
|
941
|
+
args: {
|
|
942
|
+
fileName: '文件名称(e可执行,i资源文件,f工作文件), 例:.add e test'
|
|
943
|
+
},
|
|
944
|
+
short: 'a'
|
|
945
|
+
},
|
|
946
|
+
quit: {
|
|
947
|
+
comment: '退出',
|
|
948
|
+
exeFn: (args) => {
|
|
949
|
+
console.log(infoStr("Bye!"))
|
|
950
|
+
_exit = true;
|
|
951
|
+
process.exit(0)
|
|
952
|
+
},
|
|
953
|
+
short: 'q'
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
async function dealKeyword(str) {
|
|
958
|
+
let unMatched = true;
|
|
959
|
+
for (let key of Object.keys(keywordDef)) {
|
|
960
|
+
let item = keywordDef[key]
|
|
961
|
+
let currStr = str === key ? item.short : str.replace(new RegExp(`^${key}\\s+`), item.short + ' ')
|
|
962
|
+
let strs = trim(currStr).split(/\s+/)
|
|
963
|
+
let fstr = strs[0]
|
|
964
|
+
let ostr = strs.slice(1)
|
|
965
|
+
if (item.short === fstr) {
|
|
966
|
+
unMatched = false;
|
|
967
|
+
await item.exeFn(ostr);
|
|
968
|
+
break;
|
|
955
969
|
}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
process.exit(0)
|
|
960
|
-
} else {
|
|
961
|
-
await save(strs)
|
|
970
|
+
}
|
|
971
|
+
if (unMatched) {
|
|
972
|
+
warn("unknown keyword")
|
|
962
973
|
}
|
|
963
974
|
}
|
|
964
975
|
|
|
@@ -1093,11 +1104,12 @@ function getArgComments(argDef) {
|
|
|
1093
1104
|
if (keys.length > 0) {
|
|
1094
1105
|
let aLine = []
|
|
1095
1106
|
for (let k of keys) {
|
|
1096
|
-
|
|
1107
|
+
let item = warnStr(k) + (argDef[k] ? ` <${argDef[k]}>`:'')
|
|
1108
|
+
if ([...aLine, item].join(', ').length > 64) {
|
|
1097
1109
|
comments.push(aLine.join(", ") + ", ")
|
|
1098
1110
|
aLine = []
|
|
1099
1111
|
}
|
|
1100
|
-
aLine.push(
|
|
1112
|
+
aLine.push(item)
|
|
1101
1113
|
}
|
|
1102
1114
|
if (aLine.length > 0) {
|
|
1103
1115
|
comments.push(aLine.join(", "))
|
|
@@ -1316,19 +1328,23 @@ function tipsOnRmCallback(key) {
|
|
|
1316
1328
|
}
|
|
1317
1329
|
}
|
|
1318
1330
|
|
|
1319
|
-
async function _requireSource(cmdMatchStr,
|
|
1331
|
+
async function _requireSource(cmdMatchStr, printLog = false) {
|
|
1320
1332
|
cmdMatchStr = trim(cmdMatchStr);
|
|
1321
1333
|
let nullable = false;
|
|
1322
1334
|
if (cmdMatchStr.startsWith("*")) {
|
|
1323
1335
|
nullable = true;
|
|
1324
1336
|
cmdMatchStr = trim(cmdMatchStr.substr(1));
|
|
1325
1337
|
}
|
|
1338
|
+
if (_fs.existsSync(_home + '/' + cmdMatchStr)) {
|
|
1339
|
+
cmdMatchStr = '0x' + md5(cmdMatchStr).substr(0, 8);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1326
1342
|
let cmdMap = filterCmd(cmdMatchStr.split(/\s+/))
|
|
1327
1343
|
if (Object.keys(cmdMap).length !== 1) {
|
|
1328
1344
|
if (nullable) {
|
|
1329
1345
|
return null;
|
|
1330
1346
|
}
|
|
1331
|
-
throw `none
|
|
1347
|
+
throw `none match: ${cmdMatchStr}`
|
|
1332
1348
|
}
|
|
1333
1349
|
let cmdName = Object.values(cmdMap)[0];
|
|
1334
1350
|
|
|
@@ -1336,44 +1352,56 @@ async function _requireSource(cmdMatchStr, ignoreLog = false) {
|
|
|
1336
1352
|
let path = _home + '/' + cmdName
|
|
1337
1353
|
let text = String(_fs.readFileSync(path))
|
|
1338
1354
|
if (cmdName.startsWith('i ')) {
|
|
1339
|
-
|
|
1355
|
+
try {
|
|
1356
|
+
result = await evalText(text, cmdName)
|
|
1357
|
+
} catch (e) {
|
|
1358
|
+
if (nullable) {
|
|
1359
|
+
warn(`require [${cmdMatchStr}] failed`)
|
|
1360
|
+
$log(errorStack(e))
|
|
1361
|
+
return null;
|
|
1362
|
+
} else {
|
|
1363
|
+
throw e
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1340
1366
|
} else if (cmdName.startsWith('e ')) {
|
|
1341
1367
|
result = async (argsStr) => {
|
|
1342
|
-
|
|
1343
|
-
if (ignoreLog) {
|
|
1344
|
-
console.log = () => {}
|
|
1345
|
-
}
|
|
1346
|
-
try {
|
|
1347
|
-
return await runCmd(trim(argsStr), cmdName, text)
|
|
1348
|
-
} finally {
|
|
1349
|
-
if (ignoreLog) {
|
|
1350
|
-
console.log = oriLog
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1368
|
+
return await runCmd(trim(argsStr), cmdName, text)
|
|
1353
1369
|
}
|
|
1354
1370
|
}
|
|
1355
1371
|
if (!vl(result)) {
|
|
1356
1372
|
if (nullable) {
|
|
1357
1373
|
return null;
|
|
1358
1374
|
}
|
|
1359
|
-
throw `invalid
|
|
1375
|
+
throw `invalid result: ${cmdMatchStr}`
|
|
1360
1376
|
}
|
|
1361
|
-
if (
|
|
1377
|
+
if (getType(result) === 'Function' || getType(result) === 'AsyncFunction') {
|
|
1362
1378
|
let tmp = result;
|
|
1363
1379
|
result = (...args) => {
|
|
1364
1380
|
let resp
|
|
1381
|
+
let startTime = Date.now();
|
|
1382
|
+
let pl = () => {
|
|
1383
|
+
if (printLog) {
|
|
1384
|
+
info(`${cmdName} finished in ${Date.now() - startTime}ms`)
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1365
1387
|
try {
|
|
1366
1388
|
resp = tmp(...args)
|
|
1389
|
+
if (getType(resp) === 'Promise') {
|
|
1390
|
+
return resp.then(result => {
|
|
1391
|
+
pl();
|
|
1392
|
+
return Promise.resolve(result);
|
|
1393
|
+
}).catch(e => {
|
|
1394
|
+
pl();
|
|
1395
|
+
return Promise.reject(errorTag(e, cmdName))
|
|
1396
|
+
})
|
|
1397
|
+
} else {
|
|
1398
|
+
pl();
|
|
1399
|
+
return resp;
|
|
1400
|
+
}
|
|
1367
1401
|
} catch (e) {
|
|
1402
|
+
pl();
|
|
1368
1403
|
throw errorTag(e, cmdName);
|
|
1369
1404
|
}
|
|
1370
|
-
if (getType(resp) === 'Promise') {
|
|
1371
|
-
return resp.catch(e => {
|
|
1372
|
-
return Promise.reject(errorTag(e, cmdName))
|
|
1373
|
-
})
|
|
1374
|
-
} else {
|
|
1375
|
-
return resp;
|
|
1376
|
-
}
|
|
1377
1405
|
}
|
|
1378
1406
|
}
|
|
1379
1407
|
return result
|
|
@@ -1400,10 +1428,14 @@ async function _requireSources(...matchItem) {
|
|
|
1400
1428
|
return result
|
|
1401
1429
|
}
|
|
1402
1430
|
|
|
1403
|
-
function evalText($text = '', $cmdName = '', $args = []) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1431
|
+
async function evalText($text = '', $cmdName = '', $args = []) {
|
|
1432
|
+
try {
|
|
1433
|
+
return await evalCode($text, $cmdName, $args,
|
|
1434
|
+
_home, _cmdMap, _requireSources, $data,
|
|
1435
|
+
nextLine, nextText, setTips, delTips, wrapperInput, filterCmd)
|
|
1436
|
+
} catch(e) {
|
|
1437
|
+
throw errorTag(e, $cmdName);
|
|
1438
|
+
}
|
|
1407
1439
|
}
|
|
1408
1440
|
|
|
1409
1441
|
process.on('uncaughtException',function(err){
|
|
@@ -1429,4 +1461,6 @@ process.on('beforeExit', function () {
|
|
|
1429
1461
|
if (!_exit) {
|
|
1430
1462
|
_noAppendNextLine || nextLine();
|
|
1431
1463
|
}
|
|
1432
|
-
});
|
|
1464
|
+
});
|
|
1465
|
+
|
|
1466
|
+
start()
|
package/evalCode.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
const {info: $info, msg: $msg, warn: $warn, error: $error,
|
|
2
2
|
infoStr: $infoStr, msgStr: $msgStr, warnStr: $warnStr, errorStr: $errorStr,
|
|
3
3
|
tableStr: $tableStr, nableStr: $nableStr,
|
|
4
|
-
errorMsg: $errorMsg, errorStack: $errorStack,
|
|
4
|
+
errorMsg: $errorMsg, errorStack: $errorStack,
|
|
5
|
+
importG: $import} = require("./util");
|
|
5
6
|
require = require("./util").requireG;
|
|
6
|
-
module.exports = ($text = '', $cmdName = '', $args = [],
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
8
|
+
$cmdDir, $cmdMap, $require, $data,
|
|
9
|
+
$nextLine, $nextText, $setTips, $delTips,
|
|
10
|
+
$enter, $filterCmd) => {
|
|
10
11
|
const $defArgs = () => $args;
|
|
11
|
-
|
|
12
|
-
return eval(`(async ()=>{try {${$text};
|
|
13
|
-
} catch(e) {
|
|
14
|
-
throw $errorTag(e, $cmdName);
|
|
15
|
-
}
|
|
12
|
+
return await eval(`(async ()=>{${$text};
|
|
16
13
|
})()`)
|
|
17
14
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsir",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "js script manager tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "node cmd/ooa.js --repl"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
10
|
"jsir-see": "cmd/see.js",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"jsir-scd": "cmd/solCd.js",
|
|
15
15
|
"jsir-stt": "cmd/solTt.js",
|
|
16
16
|
"jsir-cleanLog": "cmd/cleanLog.js",
|
|
17
|
-
"jsir-ethPrivateHit": "cmd/ethPrivateHit.js",
|
|
18
17
|
"jsir-staticServer": "cmd/staticServer.js",
|
|
19
18
|
"jsir-dirServer": "cmd/dirServer.js",
|
|
20
19
|
"jsir-stop": "cmd/stop.js",
|
|
@@ -27,7 +26,6 @@
|
|
|
27
26
|
"author": "",
|
|
28
27
|
"license": "ISC",
|
|
29
28
|
"dependencies": {
|
|
30
|
-
"@ethersproject/abi": "^5.5.0",
|
|
31
29
|
"abi-decoder": "^2.4.0",
|
|
32
30
|
"address": "^1.1.2",
|
|
33
31
|
"axios": "^0.20.0",
|
|
@@ -40,9 +38,7 @@
|
|
|
40
38
|
"ethers": "^5.1.0",
|
|
41
39
|
"global-dirs": "^3.0.0",
|
|
42
40
|
"keccak": "^3.0.2",
|
|
43
|
-
"md5": "^2.3.0",
|
|
44
41
|
"pad": "^3.2.0",
|
|
45
|
-
"randomhex": "^0.1.5",
|
|
46
42
|
"server": "^1.0.30",
|
|
47
43
|
"urlencode": "^1.1.0",
|
|
48
44
|
"web3": "^1.6.1",
|
package/util.js
CHANGED
|
@@ -114,8 +114,15 @@ function isArgsMatch(text, args, callback, useMd5) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
function draftQuery(fLine) {
|
|
117
|
+
let results = []
|
|
118
|
+
|
|
119
|
+
let draftPath = getLibDataDir() + "/log/draft.log"
|
|
120
|
+
if (!_fs.existsSync(draftPath)) {
|
|
121
|
+
return results
|
|
122
|
+
}
|
|
123
|
+
|
|
117
124
|
let lines = []
|
|
118
|
-
let text = String(_fs.readFileSync(
|
|
125
|
+
let text = String(_fs.readFileSync(draftPath))
|
|
119
126
|
let temp = []
|
|
120
127
|
for (let line of text.split("\n")) {
|
|
121
128
|
if (!trim(line)) {
|
|
@@ -135,7 +142,6 @@ function draftQuery(fLine) {
|
|
|
135
142
|
lines.push(temp.join('\n'))
|
|
136
143
|
}
|
|
137
144
|
|
|
138
|
-
let results = []
|
|
139
145
|
if (!/^\d+$/.test(fLine)) {
|
|
140
146
|
let items = fLine.split(/\s+/).filter(i => i)
|
|
141
147
|
for (let line of lines) {
|
|
@@ -391,6 +397,20 @@ function requireG(module){
|
|
|
391
397
|
return require(path);
|
|
392
398
|
}
|
|
393
399
|
|
|
400
|
+
async function importG(module) {
|
|
401
|
+
try {
|
|
402
|
+
let result = await import(module);
|
|
403
|
+
if (result) {
|
|
404
|
+
return result
|
|
405
|
+
}
|
|
406
|
+
} catch (e) {}
|
|
407
|
+
let path = globalDirectories.npm.packages + '/' + module + '/index.js';
|
|
408
|
+
if (!fs.existsSync(path)) {
|
|
409
|
+
throw `ERROR: ${module} not found, use [npm install -g ${module}] to install it`;
|
|
410
|
+
}
|
|
411
|
+
return await import(path);
|
|
412
|
+
}
|
|
413
|
+
|
|
394
414
|
function validStr(str, name) {
|
|
395
415
|
if (!vl(str) || typeof str !== 'string') {
|
|
396
416
|
throw "invalid cipher " + name;
|
|
@@ -929,6 +949,9 @@ function wrapRows(rows) {
|
|
|
929
949
|
let temp = []
|
|
930
950
|
for(let key of Object.keys(row)) {
|
|
931
951
|
let val = row[key]
|
|
952
|
+
if (getType(val) !== "String") {
|
|
953
|
+
val = JSON.stringify(val, null, 2)
|
|
954
|
+
}
|
|
932
955
|
let items = String(val).split('\n')
|
|
933
956
|
for(let i = 0; i<items.length; i++) {
|
|
934
957
|
let r = getOr(temp, i, {})
|
|
@@ -941,18 +964,30 @@ function wrapRows(rows) {
|
|
|
941
964
|
}
|
|
942
965
|
|
|
943
966
|
function info(msg) {
|
|
967
|
+
if (typeof msg === 'string' && msg && msg.indexOf('\n') === -1) {
|
|
968
|
+
msg = infoStr(msg)
|
|
969
|
+
}
|
|
944
970
|
console.log(infoStr('[info]'), msg)
|
|
945
971
|
}
|
|
946
972
|
|
|
947
973
|
function msg(msg) {
|
|
974
|
+
if (typeof msg === 'string' && msg && msg.indexOf('\n') === -1) {
|
|
975
|
+
msg = msgStr(msg)
|
|
976
|
+
}
|
|
948
977
|
console.log(msgStr('[msg]'), msg)
|
|
949
978
|
}
|
|
950
979
|
|
|
951
980
|
function warn(msg) {
|
|
981
|
+
if (typeof msg === 'string' && msg && msg.indexOf('\n') === -1) {
|
|
982
|
+
msg = warnStr(msg)
|
|
983
|
+
}
|
|
952
984
|
console.warn(warnStr('[warn]'), msg)
|
|
953
985
|
}
|
|
954
986
|
|
|
955
987
|
function error(msg, tag) {
|
|
988
|
+
if (typeof msg === 'string' && msg && msg.indexOf('\n') === -1) {
|
|
989
|
+
msg = errorStr(msg)
|
|
990
|
+
}
|
|
956
991
|
console.error(errorStr(`[${tag || 'error'}]`), msg)
|
|
957
992
|
}
|
|
958
993
|
|
|
@@ -1015,7 +1050,7 @@ function errorMsg(e) {
|
|
|
1015
1050
|
|
|
1016
1051
|
function getType(obj) {
|
|
1017
1052
|
if (obj === '') {
|
|
1018
|
-
return
|
|
1053
|
+
return 'String';
|
|
1019
1054
|
}
|
|
1020
1055
|
if (!vl(obj)) {
|
|
1021
1056
|
return String(obj)
|
|
@@ -1236,5 +1271,6 @@ module.exports = {
|
|
|
1236
1271
|
iobjDataFile,
|
|
1237
1272
|
iarrayDataFile,
|
|
1238
1273
|
isArgsMatch,
|
|
1239
|
-
draftQuery
|
|
1274
|
+
draftQuery,
|
|
1275
|
+
importG
|
|
1240
1276
|
}
|