jsir 1.3.1 → 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 +370 -351
- package/package.json +2 -3
- package/util.js +8 -2
package/cmd/ooa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
6
|
getInfo, ei, pad, msgStr, getType,
|
|
@@ -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,79 +44,6 @@ try {
|
|
|
45
44
|
|
|
46
45
|
let _noAppendNextLine = true
|
|
47
46
|
|
|
48
|
-
const _mainCmdMap = {
|
|
49
|
-
repl: {
|
|
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
47
|
function initRuntime() {
|
|
122
48
|
global.$lib = {...require('../util')}
|
|
123
49
|
}
|
|
@@ -137,68 +63,14 @@ function getFileOpenExe(fileName) {
|
|
|
137
63
|
return exe || 'idea';
|
|
138
64
|
}
|
|
139
65
|
|
|
140
|
-
|
|
66
|
+
async function start() {
|
|
141
67
|
mkdir(_home)
|
|
142
|
-
if (isMainCmd(['config'])) {
|
|
143
|
-
let fileName = 'config.json';
|
|
144
|
-
let configFile = getLibDataDir() + '/' + fileName;
|
|
145
|
-
ei('vi', [configFile])
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
|
|
149
68
|
dealSourceCmds()
|
|
150
69
|
|
|
151
|
-
if (
|
|
70
|
+
if (_args[0] === '--repl') {
|
|
152
71
|
initRuntime()
|
|
153
72
|
_noAppendNextLine = false
|
|
154
|
-
|
|
155
|
-
if (_noAppendNextLine) {
|
|
156
|
-
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (isMainCmd(['edit', 'rm', 'diff', 'push', 'pull', 'deps'])
|
|
160
|
-
&& _args[1] && !/^\d+$/.test(_args[1])) {
|
|
161
|
-
warn('wrong args')
|
|
162
|
-
return
|
|
163
|
-
}
|
|
164
|
-
if (isMainCmd(['lib'])) {
|
|
165
|
-
initRuntime()
|
|
166
|
-
}
|
|
167
|
-
if (isMainCmd(['add', 'note', 'init'])
|
|
168
|
-
&& (!_args[1] || /^\d+$/.test(_args[1]))) {
|
|
169
|
-
warn('wrong args')
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let argStr = _args.slice(1).map(i => {
|
|
174
|
-
if (/\s+/.test(i) || !i) {
|
|
175
|
-
i = `"${i}"`
|
|
176
|
-
}
|
|
177
|
-
return i
|
|
178
|
-
}).join(' ').replace(/^@/, '')
|
|
179
|
-
if (isMainCmd(['edit', 'rm', 'diff', 'push', 'pull', 'deps']) && !trim(argStr)) {
|
|
180
|
-
_args[0] = '@'
|
|
181
|
-
}
|
|
182
|
-
if (isMainCmd(['file'])) {
|
|
183
|
-
initRuntime()
|
|
184
|
-
}
|
|
185
|
-
let info = _mainCmdMap[_args[0]]
|
|
186
|
-
if (info) {
|
|
187
|
-
for(let cmd of info.cmd) {
|
|
188
|
-
await wrapperInput(`${cmd}${argStr}`)
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
await wrapperInput(`${_args[0]}${argStr}`)
|
|
192
|
-
}
|
|
193
|
-
} else if (_args[0] && _args[0].startsWith('-')) {
|
|
194
|
-
let cols = []
|
|
195
|
-
for (let key of Object.keys(_mainCmdMap)) {
|
|
196
|
-
cols.push({
|
|
197
|
-
cmd: key,
|
|
198
|
-
comment: _mainCmdMap[key].comment
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
console.table(cols)
|
|
73
|
+
console.log(warnStr("You can start with .help"))
|
|
202
74
|
} else if (_args[0]) {
|
|
203
75
|
if (_noAppendNextLine) {
|
|
204
76
|
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
@@ -208,7 +80,7 @@ run(async () => {
|
|
|
208
80
|
i = `"${i}"`
|
|
209
81
|
}
|
|
210
82
|
return i
|
|
211
|
-
}).join(' ')
|
|
83
|
+
}).join(' ')
|
|
212
84
|
if (/^\d+$/.test(_args[0])) {
|
|
213
85
|
if (_args[0] === '0' || (_cmdMap[_args[0]] && ['e ', 'f '].filter(i => _cmdMap[_args[0]].startsWith(i)).length > 0)) {
|
|
214
86
|
initRuntime()
|
|
@@ -219,9 +91,9 @@ run(async () => {
|
|
|
219
91
|
if (_noAppendNextLine) {
|
|
220
92
|
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
221
93
|
}
|
|
222
|
-
|
|
94
|
+
listCmd();
|
|
223
95
|
}
|
|
224
|
-
}
|
|
96
|
+
}
|
|
225
97
|
|
|
226
98
|
async function getFileWatcher(fileName, workFilePath, text) {
|
|
227
99
|
info("workFile open " + workFilePath)
|
|
@@ -454,8 +326,6 @@ function dealSourceCmds() {
|
|
|
454
326
|
_fs.writeFileSync(_home + "/" + item, String(_fs.readFileSync(source + "/" + item)))
|
|
455
327
|
}
|
|
456
328
|
})
|
|
457
|
-
} else {
|
|
458
|
-
warn(`require config.jsLibSource, run [${_setting.name} repo]`)
|
|
459
329
|
}
|
|
460
330
|
}
|
|
461
331
|
|
|
@@ -709,14 +579,12 @@ async function _wrapperInput(str) {
|
|
|
709
579
|
} else {
|
|
710
580
|
await evalText(text)
|
|
711
581
|
}
|
|
712
|
-
} else if (str.match(
|
|
713
|
-
let
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
if (fstr) {
|
|
717
|
-
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)
|
|
718
586
|
} else {
|
|
719
|
-
|
|
587
|
+
help()
|
|
720
588
|
}
|
|
721
589
|
} else if (!str.split(/\s+/)[0].match(/^\d+$/)) {
|
|
722
590
|
_cmdMap = filterCmd(str.split(/\s+/))
|
|
@@ -741,6 +609,18 @@ async function _wrapperInput(str) {
|
|
|
741
609
|
}
|
|
742
610
|
}
|
|
743
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
|
+
|
|
744
624
|
function delTipsByIndex(idxs) {
|
|
745
625
|
let keys = Object.keys($tips)
|
|
746
626
|
let indexKeyMap = {}
|
|
@@ -760,212 +640,336 @@ function delTipsByIndex(idxs) {
|
|
|
760
640
|
delTips(...params)
|
|
761
641
|
}
|
|
762
642
|
|
|
763
|
-
|
|
764
|
-
|
|
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
|
-
let
|
|
796
|
-
if (!
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
_fs.
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
} else if (/^v\d*$/.test(fstr)) {
|
|
804
|
-
let name = _cmdMap[trim(fstr.replace(/^v/, ''))]
|
|
805
|
-
if (!name) {
|
|
806
|
-
warn("no items")
|
|
807
|
-
} else {
|
|
808
|
-
let path = _home + '/' + _cmdMap[trim(fstr.replace(/^v/, ''))]
|
|
809
|
-
let text =trim(trim(str.substring(1)).replace(/^v\d+/, ''))
|
|
810
|
-
if (!text) {
|
|
811
|
-
text = await getCbText()
|
|
812
|
-
}
|
|
813
|
-
if (text) {
|
|
814
|
-
_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)
|
|
815
682
|
}
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
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)
|
|
825
698
|
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
826
699
|
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
827
700
|
if (_fs.existsSync(jsLibDir + '/' + name)) {
|
|
828
|
-
|
|
701
|
+
_fs.unlinkSync(jsLibDir + '/' + name)
|
|
829
702
|
}
|
|
830
703
|
}
|
|
831
|
-
|
|
704
|
+
info(`${path} removed`)
|
|
832
705
|
}
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
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)
|
|
845
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")
|
|
846
744
|
} else {
|
|
847
|
-
|
|
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
|
+
}
|
|
848
755
|
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
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
|
+
}
|
|
865
780
|
}
|
|
781
|
+
info(`${name} pulled`)
|
|
782
|
+
} else {
|
|
783
|
+
warn('require origin workspace')
|
|
866
784
|
}
|
|
867
|
-
|
|
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")
|
|
868
800
|
} else {
|
|
869
|
-
|
|
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')
|
|
807
|
+
}
|
|
870
808
|
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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")
|
|
883
828
|
} else {
|
|
884
|
-
|
|
829
|
+
let path = _home + '/' + name
|
|
830
|
+
await e(`"${getFileOpenExe(name)}" "${path}"`)
|
|
885
831
|
}
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
let name = _cmdMap[trim(fstr.replace(/^c/, ''))]
|
|
899
|
-
if (!name) {
|
|
900
|
-
warn("no items")
|
|
901
|
-
} else {
|
|
902
|
-
let path = _home + '/' + name
|
|
903
|
-
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
904
|
-
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
905
|
-
let sPath = jsLibDir + "/" + name
|
|
906
|
-
await e(`idea diff "${sPath}" "${path}"`)
|
|
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")
|
|
907
844
|
} else {
|
|
908
|
-
|
|
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
|
+
}
|
|
909
853
|
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
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")
|
|
866
|
+
} else {
|
|
867
|
+
let md5Keys = getScriptRequires(name);
|
|
868
|
+
_cmdMap = filterCmd(md5Keys)
|
|
869
|
+
listCmd()
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
args: {
|
|
873
|
+
fileIndex: '文件下标'
|
|
874
|
+
},
|
|
875
|
+
short: 'd'
|
|
876
|
+
},
|
|
877
|
+
history: {
|
|
878
|
+
comment: '查看执行记录',
|
|
879
|
+
exeFn: (args) => {
|
|
880
|
+
hisToCmdMap()
|
|
918
881
|
listCmd()
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
await watchFile(name)
|
|
935
|
-
}
|
|
936
|
-
} else if (fstr === '%') {
|
|
937
|
-
let newRepo = trim(ostr[0])
|
|
938
|
-
let currRepo = getConfig('jsLibSource');
|
|
939
|
-
if (!newRepo) {
|
|
940
|
-
console.log(`current: ${currRepo}`)
|
|
941
|
-
_repos = _repos.filter(i => _fs.existsSync(i))
|
|
942
|
-
for(let i = 0; i<_repos.length; i++) {
|
|
943
|
-
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
|
+
}
|
|
944
897
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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
|
|
948
920
|
}
|
|
949
|
-
newRepo
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
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`)
|
|
956
931
|
}
|
|
957
|
-
arrayDataFile('repos.json', () => _repos)
|
|
958
|
-
dealSourceCmds()
|
|
959
|
-
} else {
|
|
960
|
-
warn(`repo ${newRepo} not exist`)
|
|
961
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;
|
|
962
969
|
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
process.exit(0)
|
|
967
|
-
} else {
|
|
968
|
-
await save(strs)
|
|
970
|
+
}
|
|
971
|
+
if (unMatched) {
|
|
972
|
+
warn("unknown keyword")
|
|
969
973
|
}
|
|
970
974
|
}
|
|
971
975
|
|
|
@@ -1100,11 +1104,12 @@ function getArgComments(argDef) {
|
|
|
1100
1104
|
if (keys.length > 0) {
|
|
1101
1105
|
let aLine = []
|
|
1102
1106
|
for (let k of keys) {
|
|
1103
|
-
|
|
1107
|
+
let item = warnStr(k) + (argDef[k] ? ` <${argDef[k]}>`:'')
|
|
1108
|
+
if ([...aLine, item].join(', ').length > 64) {
|
|
1104
1109
|
comments.push(aLine.join(", ") + ", ")
|
|
1105
1110
|
aLine = []
|
|
1106
1111
|
}
|
|
1107
|
-
aLine.push(
|
|
1112
|
+
aLine.push(item)
|
|
1108
1113
|
}
|
|
1109
1114
|
if (aLine.length > 0) {
|
|
1110
1115
|
comments.push(aLine.join(", "))
|
|
@@ -1323,7 +1328,7 @@ function tipsOnRmCallback(key) {
|
|
|
1323
1328
|
}
|
|
1324
1329
|
}
|
|
1325
1330
|
|
|
1326
|
-
async function _requireSource(cmdMatchStr,
|
|
1331
|
+
async function _requireSource(cmdMatchStr, printLog = false) {
|
|
1327
1332
|
cmdMatchStr = trim(cmdMatchStr);
|
|
1328
1333
|
let nullable = false;
|
|
1329
1334
|
if (cmdMatchStr.startsWith("*")) {
|
|
@@ -1339,7 +1344,7 @@ async function _requireSource(cmdMatchStr, ignoreLog = false) {
|
|
|
1339
1344
|
if (nullable) {
|
|
1340
1345
|
return null;
|
|
1341
1346
|
}
|
|
1342
|
-
throw `none
|
|
1347
|
+
throw `none match: ${cmdMatchStr}`
|
|
1343
1348
|
}
|
|
1344
1349
|
let cmdName = Object.values(cmdMap)[0];
|
|
1345
1350
|
|
|
@@ -1347,44 +1352,56 @@ async function _requireSource(cmdMatchStr, ignoreLog = false) {
|
|
|
1347
1352
|
let path = _home + '/' + cmdName
|
|
1348
1353
|
let text = String(_fs.readFileSync(path))
|
|
1349
1354
|
if (cmdName.startsWith('i ')) {
|
|
1350
|
-
|
|
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
|
+
}
|
|
1351
1366
|
} else if (cmdName.startsWith('e ')) {
|
|
1352
1367
|
result = async (argsStr) => {
|
|
1353
|
-
|
|
1354
|
-
if (ignoreLog) {
|
|
1355
|
-
console.log = () => {}
|
|
1356
|
-
}
|
|
1357
|
-
try {
|
|
1358
|
-
return await runCmd(trim(argsStr), cmdName, text)
|
|
1359
|
-
} finally {
|
|
1360
|
-
if (ignoreLog) {
|
|
1361
|
-
console.log = oriLog
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1368
|
+
return await runCmd(trim(argsStr), cmdName, text)
|
|
1364
1369
|
}
|
|
1365
1370
|
}
|
|
1366
1371
|
if (!vl(result)) {
|
|
1367
1372
|
if (nullable) {
|
|
1368
1373
|
return null;
|
|
1369
1374
|
}
|
|
1370
|
-
throw `invalid
|
|
1375
|
+
throw `invalid result: ${cmdMatchStr}`
|
|
1371
1376
|
}
|
|
1372
1377
|
if (getType(result) === 'Function' || getType(result) === 'AsyncFunction') {
|
|
1373
1378
|
let tmp = result;
|
|
1374
1379
|
result = (...args) => {
|
|
1375
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
|
+
}
|
|
1376
1387
|
try {
|
|
1377
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
|
+
}
|
|
1378
1401
|
} catch (e) {
|
|
1402
|
+
pl();
|
|
1379
1403
|
throw errorTag(e, cmdName);
|
|
1380
1404
|
}
|
|
1381
|
-
if (getType(resp) === 'Promise') {
|
|
1382
|
-
return resp.catch(e => {
|
|
1383
|
-
return Promise.reject(errorTag(e, cmdName))
|
|
1384
|
-
})
|
|
1385
|
-
} else {
|
|
1386
|
-
return resp;
|
|
1387
|
-
}
|
|
1388
1405
|
}
|
|
1389
1406
|
}
|
|
1390
1407
|
return result
|
|
@@ -1444,4 +1461,6 @@ process.on('beforeExit', function () {
|
|
|
1444
1461
|
if (!_exit) {
|
|
1445
1462
|
_noAppendNextLine || nextLine();
|
|
1446
1463
|
}
|
|
1447
|
-
});
|
|
1464
|
+
});
|
|
1465
|
+
|
|
1466
|
+
start()
|
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",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"author": "",
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ethersproject/abi": "^5.5.0",
|
|
30
29
|
"abi-decoder": "^2.4.0",
|
|
31
30
|
"address": "^1.1.2",
|
|
32
31
|
"axios": "^0.20.0",
|
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) {
|