jsir 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/cmd/oaa.js +73 -32
  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
- $workspaceMap['local'] = localWorkspace;
62
+ global.$workspaceMap = {
63
+ 'local': localWorkspace
64
+ }
64
65
  mkdir(localWorkspace)
65
- for (let workspace of _workspaces) {
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
- _workspaces = Object.values($workspaceMap);
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] === '--repl') {
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
- if (_noAppendNextLine) {
99
- _cmdMap = objDataFile(_cmdMapFile)
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
 
@@ -696,11 +691,13 @@ const keywordDef = {
696
691
  list: {
697
692
  comment: '查看文件列表',
698
693
  exeFn: (args) => {
699
- _cmdMap = arrayToCmdMap(filterCmd(args.length > 0 ? args.join(' '):[',']))
694
+ if (args.length > 0) {
695
+ _cmdMap = arrayToCmdMap(filterCmd(args.length > 0 ? args.join(' '):[',']))
696
+ }
700
697
  listCmd()
701
698
  },
702
699
  args: {
703
- queryParams: '条件参数(param1,param2 param3 ...)'
700
+ queryParams: '条件参数(param1,param2 param3 ...), [,]代表全部'
704
701
  },
705
702
  short: 'l'
706
703
  },
@@ -789,7 +786,7 @@ const keywordDef = {
789
786
  fileIndex: '文件下标',
790
787
  newName: '新名字'
791
788
  },
792
- short: 'r'
789
+ short: 'n'
793
790
  },
794
791
  edit: {
795
792
  comment: '编辑文件',
@@ -895,10 +892,13 @@ const keywordDef = {
895
892
  exeFn: async (args) => {
896
893
  let newWorkspace = args.join(' ')
897
894
  if (newWorkspace) {
898
- _workspaces.push(newWorkspace)
895
+ let workspaces = Object.values($workspaceMap)
896
+ workspaces.push(newWorkspace)
897
+ arrayDataFile(_workspaceConfigFile, () => workspaces)
899
898
  }
900
899
  checkWorkspaces()
901
- let items = _workspaces.map((path, index) => {
900
+ let workspaces = Object.values($workspaceMap)
901
+ let items = workspaces.map((path, index) => {
902
902
  return {
903
903
  index: ' ' + (index + 1),
904
904
  name: getSpaceFromDir(path),
@@ -912,11 +912,36 @@ const keywordDef = {
912
912
  },
913
913
  short: 'w'
914
914
  },
915
+ uninstall: {
916
+ comment: '卸载工作空间',
917
+ exeFn: async (args) => {
918
+ let workspaces = Object.values($workspaceMap)
919
+ let items = workspaces.map((path, index) => {
920
+ return {
921
+ index: ' ' + (index + 1),
922
+ name: getSpaceFromDir(path),
923
+ path
924
+ }
925
+ })
926
+ console.table(items)
927
+ let index = await nextLine(line => line, "index: ")
928
+ let workspace = workspaces[index - 1]
929
+ if (workspace) {
930
+ workspaces = workspaces.filter(i => i !== workspace);
931
+ arrayDataFile(_workspaceConfigFile, () => workspaces);
932
+ checkWorkspaces()
933
+ } else {
934
+ warn('invalid args')
935
+ }
936
+ },
937
+ short: 'u'
938
+ },
915
939
  switch: {
916
940
  comment: '切换工作空间',
917
941
  exeFn: async (args) => {
918
942
  checkWorkspaces()
919
- let items = _workspaces.map((path, index) => {
943
+ let workspaces = Object.values($workspaceMap)
944
+ let items = workspaces.map((path, index) => {
920
945
  return {
921
946
  index: ' ' + (index + 1),
922
947
  name: getSpaceFromDir(path),
@@ -925,9 +950,11 @@ const keywordDef = {
925
950
  })
926
951
  console.table(items)
927
952
  let index = trim(await nextLine(line => line, "switch workspace: "));
928
- if (index && _workspaces[index - 1]) {
929
- let workspace = _workspaces[index - 1];
953
+ if (index && workspaces[index - 1]) {
954
+ let workspace = workspaces[index - 1];
930
955
  initWorkspace(getSpaceFromDir(workspace))
956
+ } else {
957
+ warn('no items')
931
958
  }
932
959
  },
933
960
  short: 'S'
@@ -942,6 +969,25 @@ const keywordDef = {
942
969
  },
943
970
  short: 'a'
944
971
  },
972
+ run: {
973
+ comment: '快捷执行',
974
+ exeFn: async (args) => {
975
+ if (!args[0]) {
976
+ warn('invalid args')
977
+ return
978
+ }
979
+ let cmds = filterCmd('^e ' + toJsirFileName(args[0]).replace(/^[eif]\s+/, '') + '$')
980
+ _cmdMap = arrayToCmdMap(cmds)
981
+ listCmd()
982
+ if (cmds.length === 1) {
983
+ await runCmd('1 ' + args.slice(1).join(' '))
984
+ }
985
+ },
986
+ args: {
987
+ fileNameReg: '文件名称匹配'
988
+ },
989
+ short: 'r'
990
+ },
945
991
  quit: {
946
992
  comment: '退出',
947
993
  exeFn: (args) => {
@@ -1104,17 +1150,12 @@ function getJsirFileSuffix(name) {
1104
1150
 
1105
1151
  function initWorkspace(space) {
1106
1152
  let current = getConfig("workspace");
1107
- if (current && space && current === space) {
1108
- // 值没有改变
1109
- return;
1110
- }
1111
1153
  let workspace = space || current || 'local'
1112
- if (workspace) {
1113
- setConfig("workspace", workspace)
1114
- global.$defaultSpace = workspace;
1115
- } else {
1116
- global.$defaultSpace = workspace;
1154
+ if (!$workspaceMap[current]) {
1155
+ workspace = 'local'
1117
1156
  }
1157
+ setConfig("workspace", workspace)
1158
+ global.$defaultSpace = workspace;
1118
1159
  }
1119
1160
 
1120
1161
  function filterCmd(arg){
@@ -1122,11 +1163,11 @@ function filterCmd(arg){
1122
1163
  let spaceName
1123
1164
  if (arg.indexOf('/') !== -1) {
1124
1165
  let index = arg.indexOf('/');
1125
- spaceName = arg.substring(0, index) || $defaultSpace
1166
+ spaceName = trim(arg.substring(0, index)) || $defaultSpace
1126
1167
  arg = trim(arg.substring(index + 1))
1127
1168
  }
1128
1169
  let cmds = []
1129
- for (let workspace of _workspaces) {
1170
+ for (let workspace of Object.values($workspaceMap)) {
1130
1171
  let spaceTmp = getSpaceFromDir(workspace);
1131
1172
  if (!spaceName || spaceName === spaceTmp) {
1132
1173
  cmds.push(..._filterCmd(workspace, arg));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "js script manager tool",
5
5
  "main": "index.js",
6
6
  "scripts": {