jsir 2.2.2 → 2.2.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 CHANGED
@@ -3,15 +3,15 @@ const $lib = require('../deps/util');
3
3
  const {
4
4
  getLibDataDir, trim, regEach, getConfig, mkdir, reget,
5
5
  getCbText, e, sleep, objDataFile, vl, md5, BigNumber,
6
- arrayDataFile, infoStr, warnStr, errorStack,
6
+ arrayDataFile, infoStr, warnStr,
7
7
  getInfo, ei, pad, msgStr, getType,
8
- isArgsMatch, draftQuery, setConfig,
8
+ isMatch, draftQuery, setConfig,
9
9
  getTextComments, importG, requireG,
10
10
  clearConsole, trimText, getFnArgsStr,
11
11
  createConsole, setTips, delTips,
12
12
  getEditor, errorStr, getConfigDir,
13
13
  getFullPath, parseUniqueName, toUniqueName, isJsirFileName, toJsirFileName,
14
- fileJson, fileLock
14
+ fileJson, fileLock, getOr
15
15
  } = $lib;
16
16
  const _args = process.argv.slice(2).map(trim);
17
17
  const evalCode = require('../deps/evalCode')
@@ -42,8 +42,8 @@ let _haveWrapperInput = true
42
42
  let _noAppendNextLine = true
43
43
  let _onLazyTempCode = null
44
44
 
45
- const _onLazyGetMap = {}
46
- const _data = {}
45
+ const _onLazyGetMap = Object.create(null)
46
+ const _data = Object.create(null)
47
47
  const _lazyTime = 5 * 60 * 1000
48
48
  const _dealOnLazyGet = (key, onLazyTempCode) => {
49
49
  if (_noAppendNextLine || !_onLazyGetMap[key]) {
@@ -120,8 +120,8 @@ const $data = {
120
120
  delete _data[key]
121
121
  return val
122
122
  },
123
- keys: () => Object.keys(_data),
124
- have: (key) => vl(_data[key])
123
+ key: () => Object.keys(_data),
124
+ has: (key) => vl(_data[key])
125
125
  }
126
126
  const $file = {
127
127
  json: fileJson,
@@ -534,7 +534,7 @@ function listCmd(tmpMap) {
534
534
  let suffix = getJsirFileSuffix(pair[1])
535
535
  let item = {
536
536
  key: ' ' + i,
537
- name: pair[0] + '/' + name.replace(/^[eif]\s+/, ''),
537
+ name: pair[0] + '/' + name,
538
538
  type: [_types[name.split(/\s+/)[0]] || 'note', suffix].map(trim).join(".")
539
539
  }
540
540
  items.push(item)
@@ -645,8 +645,8 @@ async function dealStar(text) {
645
645
  }
646
646
  let items = text.split(/\s+/);
647
647
  let rows = []
648
- if (_cmdMap[items[0]]) {
649
- rows.push(...await dealStarCmd([], _cmdMap[items[0]], '.'))
648
+ if (_cmdMap.hasOwnProperty(items[0])) {
649
+ rows.push(...await dealStarCmd([], _cmdMap[items[0]], items.slice(1).join(' ')))
650
650
  } else if (items[0].indexOf("/") !== -1) {
651
651
  await dealStartGlobalMode(rows, items, text);
652
652
  } else {
@@ -657,7 +657,7 @@ async function dealStar(text) {
657
657
  await dealStartGlobalMode(rows, items, text);
658
658
  }
659
659
  }
660
- rows = rows.filter(i => !i.name.startsWith('_'));
660
+ rows = rows.filter(i => !i.name || (!i.name.startsWith('_') && i.name.indexOf('._') === -1));
661
661
  if (rows.length === 0) {
662
662
  console.warn("no items")
663
663
  } else {
@@ -679,9 +679,60 @@ function dealStarGlobal(items, text) {
679
679
  return rows;
680
680
  }
681
681
 
682
+ function wrapperClassLine(className, classLines) {
683
+ let str = trimText(classLines.join('\n'))
684
+ let results = []
685
+ for (let line of str.split('\n')) {
686
+ let asyncMethod = false;
687
+ if (line.startsWith("async ")) {
688
+ // 检查是否为异步方法
689
+ asyncMethod = true;
690
+ line = line.replace("async ", "").trim(); // 去除 'async ' 前缀
691
+ }
692
+ const methodMatch = line.match(/^\w+\s*\(/);
693
+ if (methodMatch) {
694
+ let prefix = `function ${className}.`;
695
+ if (asyncMethod) {
696
+ prefix = "async " + prefix;
697
+ }
698
+ results.push(prefix + line.trim());
699
+ continue;
700
+ }
701
+ results.push(line)
702
+ }
703
+ return results;
704
+ }
705
+
706
+ function wrapperClass(lines) {
707
+ let results = [];
708
+ let className = null;
709
+ let inClass = false;
710
+
711
+ let classLines = []
712
+ for (let line of lines) {
713
+ if (line.startsWith("class ")) {
714
+ inClass = true;
715
+ className = reget(line, /^class\s+(\w+)/);
716
+ continue
717
+ } else if (inClass && line.startsWith("}")) {
718
+ inClass = false
719
+ results.push(...wrapperClassLine(className, classLines));
720
+ classLines = []
721
+ continue;
722
+ }
723
+
724
+ if (inClass) {
725
+ classLines.push(line)
726
+ } else {
727
+ results.push(line);
728
+ }
729
+ }
730
+ return results;
731
+ }
732
+
682
733
  function dealStarCmd(rows, cmd, filterStr) {
683
734
  let content = String(fs.readFileSync(getFullPath(cmd)));
684
- let lines = content.split('\n');
735
+ let lines = wrapperClass(content.split('\n'));
685
736
  let capturingFunction = false;
686
737
  let inMultiLineComment = false;
687
738
  let potentialComments = [];
@@ -719,10 +770,10 @@ function dealStarCmd(rows, cmd, filterStr) {
719
770
  }
720
771
 
721
772
  // Check for function start
722
- if ((line.startsWith('function') || line.startsWith('async function'))) {
723
- let _fnName = reget(line, /function\s+(\w+)\s*\(/);
773
+ if ((line.startsWith('function ') || line.startsWith('async function '))) {
774
+ let _fnName = reget(line, /function\s+([\w.]+)\s*\(/);
724
775
  let matchKey = _fnName + "(" + getFnArgsStr(lines.slice(index, index + 9).join("\n")) + ")"
725
- if (isArgsMatch(matchKey, [filterStr])) {
776
+ if (isMatch(matchKey, filterStr)) {
726
777
  fnName = _fnName;
727
778
  fnType = line.startsWith('async') ? 'AsyncFunction' : 'Function';
728
779
  capturingFunction = true;
@@ -741,7 +792,9 @@ function dealStarCmd(rows, cmd, filterStr) {
741
792
  let functionContent = functionLines.join('\n');
742
793
  let commentContent = trimText(comments.join('\n'));
743
794
  let row = getInfo(functionContent, fnName, fnType);
744
- row.value = infoStr(cmd) + ' ' + getCmdMd5Key(parseUniqueName(cmd)[1]) + '\n' + [commentContent, row.value].filter(i => trim(i)).join("\n");
795
+ let pair = parseUniqueName(cmd);
796
+ row.value = infoStr(pair[0] + '/' + trimJsirFileName(pair[1])) + ' ' +
797
+ getCmdMd5Key(parseUniqueName(cmd)[1]) + '\n' + [commentContent, row.value].filter(i => trim(i)).join("\n");
745
798
  rows.push(row);
746
799
 
747
800
  resetState();
@@ -767,7 +820,7 @@ async function dealStarCase(result, matchStrs, cmd) {
767
820
  if (type === 'Function' || type === 'AsyncFunction') {
768
821
  matchKey = key + "(" + getFnArgsStr(String(obj)) + ")";
769
822
  }
770
- if (matchStrs.length === 0 || isArgsMatch(matchKey, [matchStrs.join(' ')])){
823
+ if (matchStrs.length === 0 || isMatch(matchKey, matchStrs.join(' '))){
771
824
  rows.push(getInfo(result[key], key))
772
825
  }
773
826
  }
@@ -914,7 +967,7 @@ const keywordDef = {
914
967
  args: {
915
968
  queryParams: 'string matching, [,] represents all, keywords can be omitted'
916
969
  },
917
- short: 'l'
970
+ short: 'L'
918
971
  },
919
972
  clear: {
920
973
  comment: 'Clear task',
@@ -1024,11 +1077,6 @@ const keywordDef = {
1024
1077
  exeFn: async (args) => {
1025
1078
  let uniqueName = _cmdMap[args[0]];
1026
1079
  if (uniqueName) {
1027
- let isExe = uniqueName &&uniqueName.split("/")[1].startsWith('e ');
1028
- if (!isExe) {
1029
- console.warn("not exe file")
1030
- return;
1031
- }
1032
1080
  let configDir = `${getLibDataDir()}/config`;
1033
1081
  mkdir(configDir)
1034
1082
  ei(getEditor(), [`${configDir}/${md5(uniqueName)}.json`])
@@ -1172,8 +1220,10 @@ const keywordDef = {
1172
1220
  comment: 'Workspace Management',
1173
1221
  exeFn: async (args) => {
1174
1222
  let newWorkspace = args.join(' ')
1223
+ let isSwitch = false
1175
1224
  if (newWorkspace) {
1176
1225
  if ($workspaceMap[newWorkspace]) {
1226
+ isSwitch = true;
1177
1227
  initWorkspace(newWorkspace)
1178
1228
  } else if (newWorkspace.startsWith('-')) {
1179
1229
  let name = newWorkspace.replace(/^-\s*/, '');
@@ -1194,7 +1244,9 @@ const keywordDef = {
1194
1244
  path
1195
1245
  }
1196
1246
  })
1197
- console.table(items)
1247
+ if (!isSwitch) {
1248
+ console.table(items)
1249
+ }
1198
1250
  },
1199
1251
  args: {
1200
1252
  workspacePath: 'New workspace path'
@@ -1292,28 +1344,33 @@ const keywordDef = {
1292
1344
  short: 'N'
1293
1345
  },
1294
1346
  log: {
1295
- comment: 'View log',
1347
+ comment: 'View log (type[[lt][le]], index)',
1296
1348
  exeFn: (args) => {
1297
1349
  let path = `${getLibDataDir()}/log/jsir`
1298
- let type = 'log';
1299
- if (args.length > 1) {
1300
- path = `${getLibDataDir()}/log/${md5(_cmdMap[trim(args[0])])}`
1301
- type = trim(args[1])
1302
- } else if (args.length > 0) {
1303
- if (_cmdMap[args[0]]) {
1304
- path = `${getLibDataDir()}/log/${md5(_cmdMap[trim(args[0])])}`
1350
+ let type = '';
1351
+ for (let arg of args) {
1352
+ if (_cmdMap[arg]) {
1353
+ path = `${getLibDataDir()}/log/${md5(_cmdMap[trim(arg)])}`
1305
1354
  } else {
1306
- type = args[0]
1355
+ type = arg;
1307
1356
  }
1308
1357
  }
1309
- path = path + '.' + type;
1358
+ let suffix = 'log'
1359
+ let cmdStr = 'less -R'
1360
+ if (type.indexOf("e") !== -1) {
1361
+ suffix = 'error'
1362
+ }
1363
+ if (type.indexOf("t") !== -1) {
1364
+ cmdStr = 'tail -n 50 -f'
1365
+ }
1366
+ path = path + '.' + suffix;
1310
1367
  if (!fs.existsSync(path)) {
1311
1368
  console.warn('log file not found')
1312
1369
  return;
1313
1370
  }
1314
- ei('less', [path])
1371
+ ei(cmdStr, [path], true)
1315
1372
  },
1316
- short: 'L'
1373
+ short: 'l'
1317
1374
  }
1318
1375
  }
1319
1376
 
@@ -1562,7 +1619,7 @@ function _filterCmd(dirPath, arg) {
1562
1619
  for (let file of files) {
1563
1620
  file = trim(file)
1564
1621
  let uniqueName = toUniqueName(dirPath + '/' + file)
1565
- isArgsMatch(file, [arg], () => {
1622
+ isMatch(file, arg, () => {
1566
1623
  cmdMap[uniqueName] = null;
1567
1624
  }, true)
1568
1625
  }
@@ -1668,7 +1725,6 @@ async function runCmd(str = '', uniqueName = '', text = '') {
1668
1725
  }
1669
1726
 
1670
1727
  let scriptArgs = await getScriptArgs(argDef, enrichArgs(str.replace(/^\d+\s*/, '')));
1671
- process.argv = [process.argv[0], path, ...(scriptArgs.map(String))]
1672
1728
  return await evalText(text, uniqueName, scriptArgs)
1673
1729
  }
1674
1730
 
@@ -1677,7 +1733,6 @@ async function runScript(uniqueName, oriArgs) {
1677
1733
  let text = String(fs.readFileSync(path))
1678
1734
  let argDef = getArgDef(text)
1679
1735
  let scriptArgs = await getScriptArgs(argDef, oriArgs);
1680
- process.argv = [process.argv[0], path, ...(scriptArgs.map(String))]
1681
1736
  return await evalText(text, uniqueName, scriptArgs)
1682
1737
  }
1683
1738
 
@@ -1686,7 +1741,7 @@ async function getScriptArgs(argDef, oriArgs) {
1686
1741
  oriArgs = oriArgs.map(i => shortDefMap[i] ? shortDefMap[i]:i)
1687
1742
  let argNames = Object.keys(argDef)
1688
1743
  let exactArgs = {}
1689
- let scriptArgs = []
1744
+ let scriptArgs = {}
1690
1745
  for (let i = 0; i<oriArgs.length; i++) {
1691
1746
  let arg = oriArgs[i]
1692
1747
  let needTrans
@@ -1718,9 +1773,7 @@ async function getScriptArgs(argDef, oriArgs) {
1718
1773
  }
1719
1774
  pair[1] = needTrans ? await evalText( 'return ' + pair[1]):pair[1]
1720
1775
 
1721
- let curIdx = scriptArgs.length
1722
- scriptArgs[curIdx] = pair[1]
1723
-
1776
+ let curIdx = Object.keys(scriptArgs).length
1724
1777
  if (argNames[curIdx]) {
1725
1778
  scriptArgs[argNames[curIdx]] = pair[1]
1726
1779
  }
@@ -1747,7 +1800,7 @@ async function getScriptArgs(argDef, oriArgs) {
1747
1800
  }
1748
1801
  if (scriptArgKeys.indexOf(name) === -1 || (reg && !reg.test(scriptArgs[name]))) {
1749
1802
  argAbsent = true
1750
- console.warn(`require ${warnStr(name)}` + (defStr ? ` <${defStr}>`:''))
1803
+ console.warn(`require ${warnStr(name)}` + (defStr ? ` ${defStr}`:''))
1751
1804
  }
1752
1805
  }
1753
1806
  if (argAbsent) {
@@ -1842,9 +1895,8 @@ function getArgDef(text, uniqueName) {
1842
1895
  let argDef = {}
1843
1896
  try {
1844
1897
  argDef = (exeStr ? evalVal(exeStr) : parseArgDef(text)) || {}
1845
- let array = []
1846
1898
  for (let key of Object.keys(argDef)) {
1847
- if (/\s/.test(key) || array.hasOwnProperty(key)) {
1899
+ if (/\s/.test(key)) {
1848
1900
  throw `invalid argName ${warnStr(key)}`
1849
1901
  }
1850
1902
  }
@@ -1887,8 +1939,8 @@ function filterRequire(currSpace, cmdMatchStr) {
1887
1939
  let uName = toUniqueName(cmdMatchStr, currSpace)
1888
1940
  let pr = parseUniqueName(uName)
1889
1941
  let fullPath;
1890
- if (!/^[eif]\s+/.test(pr[1])) {
1891
- uName = pr[0] + "/i " + pr[1]
1942
+ if (!/^[ef]\s+/.test(pr[1])) {
1943
+ uName = pr[0] + "/i " + pr[1].replace(/^f\s+/, '')
1892
1944
  fullPath = getFullPath(uName)
1893
1945
  }
1894
1946
  if (fullPath && fs.existsSync(fullPath)) {
@@ -1980,6 +2032,24 @@ async function evalText($text = '', $cmdName = '', $args = []) {
1980
2032
  $homeDir, $lib, _cmdMap);
1981
2033
  }
1982
2034
 
2035
+ function clearFileLock() {
2036
+ let fileLockMap = getOr(global, `$fileLock`, {})
2037
+ for (let file of Object.keys(fileLockMap)) {
2038
+ fp.rmdir(file)
2039
+ delete fileLockMap[file]
2040
+ }
2041
+ }
2042
+
2043
+ function sigExit() {
2044
+ if (_noAppendNextLine) {
2045
+ delTips();
2046
+ clearFileLock();
2047
+ process.exit(0);
2048
+ } else {
2049
+ nextLine();
2050
+ }
2051
+ }
2052
+
1983
2053
  process.on('uncaughtException',function(err){
1984
2054
  console.error('uncaughtException', err)
1985
2055
  _noAppendNextLine || nextLine()
@@ -1992,14 +2062,8 @@ process.on('rejectionHandled',function(err){
1992
2062
  console.error('rejectionHandled', err)
1993
2063
  _noAppendNextLine || nextLine()
1994
2064
  })
1995
- process.on('SIGINT', function () {
1996
- if (_noAppendNextLine) {
1997
- delTips();
1998
- process.exit(0);
1999
- } else {
2000
- nextLine();
2001
- }
2002
- });
2065
+ process.on('SIGINT', sigExit);
2066
+ process.on('SIGTERM', sigExit);
2003
2067
  process.on('beforeExit', function () {
2004
2068
  if (_noAppendNextLine) {
2005
2069
  delTips();
package/deps/evalCode.js CHANGED
@@ -21,7 +21,7 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
21
21
  $enter, $filterCmd,
22
22
  $currentSpace, $homeDir, $lib, $cmdMap
23
23
  }
24
- const console = $lib.createConsole($cmdName);
24
+ let console = $lib.createConsole($cmdName);
25
25
  return await eval(`(async ()=>{${$text};
26
26
  })()`)
27
27
  }
package/deps/util.js CHANGED
@@ -106,10 +106,10 @@ function errorStr(str) {
106
106
 
107
107
  function tableStr(...args) {
108
108
  return args.map(i => {
109
- if (Array.isArray(i)) {
109
+ if (typeof i === 'object') {
110
110
  return trim(table.getTable(i))
111
111
  } else {
112
- return i
112
+ return i;
113
113
  }
114
114
  }).join("\n")
115
115
  }
@@ -143,48 +143,39 @@ const _console =Object.assign({}, global.console);
143
143
  const _consoleFns= {
144
144
  log: {
145
145
  fn: _console.log,
146
- args: args => args,
147
- $args: args => args
146
+ args: args => args
148
147
  },
149
148
  table: {
150
149
  fn: _console.log,
151
- args: args => [tableStr(...args)],
152
- $args: args => [tableStr(...args)]
150
+ args: args => [tableStr(...args)]
153
151
  },
154
152
  nable: {
155
153
  fn: _console.log,
156
- args: args => [nableStr(...args)],
157
- $args: args => [nableStr(...args)]
154
+ args: args => [nableStr(...args)]
158
155
  },
159
156
  info: {
160
157
  fn: _console.info,
161
- args: args => [infoStr('[info]'), ...dealLevelArgs(infoStr, args)],
162
- $args: args => ['[info]', ...args]
158
+ args: args => [infoStr('[info]'), ...dealLevelArgs(infoStr, args)]
163
159
  },
164
160
  msg: {
165
161
  fn: _console.log,
166
- args: args => [msgStr('[msg]'), ...dealLevelArgs(msgStr, args)],
167
- $args: args => ['[msg]', ...args]
162
+ args: args => [msgStr('[msg]'), ...dealLevelArgs(msgStr, args)]
168
163
  },
169
164
  warn: {
170
165
  fn: _console.warn,
171
166
  args: args => [warnStr('[warn]'), ...dealLevelArgs(warnStr, args)],
172
- $args: args => ['[warn]', ...args]
173
167
  },
174
168
  error: {
175
169
  fn: _console.error,
176
- args: args => [errorStr('[error]'), ...dealLevelArgs(errorStr, args)],
177
- $args: args => ['[error]', ...args]
170
+ args: args => [errorStr('[error]'), ...dealLevelArgs(errorStr, args)]
178
171
  },
179
172
  dir: {
180
173
  fn: _console.dir,
181
- args: args => args,
182
- $args: args => args
174
+ args: args => args
183
175
  },
184
176
  debug: {
185
177
  fn: _console.debug,
186
- args: args => args,
187
- $args: args => args
178
+ args: args => args
188
179
  }
189
180
  }
190
181
 
@@ -193,7 +184,7 @@ function createConfig(uniqueName) {
193
184
  get: getConfig,
194
185
  local: getConfig
195
186
  }
196
- if (uniqueName && uniqueName.split("/")[1].startsWith('e ')) {
187
+ if (uniqueName) {
197
188
  result.local = (key, defaultVal) => {
198
189
  return _getConfig(key, defaultVal, uniqueName);
199
190
  }
@@ -206,8 +197,7 @@ function createConsole(uniqueName) {
206
197
  result.$log = $log;
207
198
  result.$error = $error;
208
199
  result.$draft = draftLog;
209
- let logAble = uniqueName &&uniqueName.split("/")[1].startsWith('e ');
210
- if (logAble) {
200
+ if (uniqueName) {
211
201
  result.$log = createLimitLogger(md5(uniqueName) + '.log', {
212
202
  logInfo: false
213
203
  });
@@ -217,7 +207,7 @@ function createConsole(uniqueName) {
217
207
  });
218
208
  }
219
209
  let quite = false
220
- if (logAble) {
210
+ if (uniqueName) {
221
211
  global.$newInput = false;
222
212
  }
223
213
  for (let key of Object.keys(_consoleFns)) {
@@ -225,8 +215,8 @@ function createConsole(uniqueName) {
225
215
  if (global.$newInput) {
226
216
  quite = true;
227
217
  }
228
- if (logAble && quite) {
229
- let _args = _consoleFns[key].$args(args);
218
+ if (uniqueName && quite) {
219
+ let _args = _consoleFns[key].args(args);
230
220
  if ("error" === key) {
231
221
  result.$log(..._args)
232
222
  result.$error(..._args)
@@ -304,19 +294,37 @@ function isJsirFileName(name) {
304
294
  return /^[^./]*[^./\s]\.[^./\s]+$/.test(name)
305
295
  }
306
296
 
307
- function isArgsMatch(text, args, callback, useMd5) {
297
+ function isMatch(text,
298
+ matchStr, // reg,reg;reg
299
+ callback, // invoke when matched, no args
300
+ useMd5 // '0x' + md5(text).substring(0, 8)) === matchStr
301
+ ) {
308
302
  let match = false
309
- for (let arg of args) {
303
+ let orStrs = matchStr.split(';').map(trim).filter(i => i);
304
+ for (let arg of orStrs) {
310
305
  let r = true
311
306
  for (let str of arg.split(',').map(trim).filter(i => i)) {
307
+ let not = false;
308
+ if (str.startsWith("!")) {
309
+ not = true;
310
+ str = str.substring(1);
311
+ }
312
312
  let reg = new RegExp(str.split(/\s+/).join('\\s+'), 'i')
313
313
  if (useMd5 && /^0x[a-z\d]{8}$/.test(str)) {
314
- if (('0x' + md5(text).substr(0, 8)) !== str) {
314
+ let flag = ('0x' + md5(text).substring(0, 8)) !== str;
315
+ if (not) {
316
+ flag = !flag;
317
+ }
318
+ if (flag) {
315
319
  r = false
316
320
  break
317
321
  }
318
322
  } else {
319
- if (!reg.test(text)) {
323
+ let flag = !reg.test(text);
324
+ if (not) {
325
+ flag = !flag;
326
+ }
327
+ if (flag) {
320
328
  r = false
321
329
  break
322
330
  }
@@ -327,6 +335,9 @@ function isArgsMatch(text, args, callback, useMd5) {
327
335
  break
328
336
  }
329
337
  }
338
+ if (orStrs.length === 0) {
339
+ match = true;
340
+ }
330
341
  if (match && callback) {
331
342
  callback()
332
343
  }
@@ -341,9 +352,10 @@ function parseDraftLog(draftPath) {
341
352
  let temp = [];
342
353
  let startIndex = 0;
343
354
  let head;
355
+ let splitReg = /^---------\d+/;
344
356
 
345
357
  allLines.forEach((line, i) => {
346
- if (line.startsWith("---------")) {
358
+ if (splitReg.test(line)) {
347
359
  if (temp.length > 0) {
348
360
  let fullText = temp.join('\n');
349
361
  lines.push(fullText);
@@ -353,7 +365,7 @@ function parseDraftLog(draftPath) {
353
365
  temp = [];
354
366
  head = line;
355
367
  }
356
- temp.push(line.startsWith("---------") ? warnStr(line) : line);
368
+ temp.push(splitReg.test(line) ? warnStr(line) : line);
357
369
  });
358
370
 
359
371
  if (temp.length > 0) {
@@ -401,7 +413,7 @@ function draftQuery(fLine) {
401
413
  results = lines.slice(- parseInt(filterKeywords));
402
414
  } else {
403
415
  lines.forEach(line => {
404
- if (isArgsMatch(line, [filterKeywords])) {
416
+ if (isMatch(line, filterKeywords)) {
405
417
  results.push(line);
406
418
  }
407
419
  });
@@ -475,12 +487,13 @@ function getEditor() {
475
487
  }
476
488
 
477
489
  function timeStr(fmt, date) {
478
- return dayJs(date || new Date()).format(fmt || 'YYYY/MM/DD HH:mm:ss')
490
+ return dayJs(date || new Date()).format(fmt || 'YYYY-MM-DD HH:mm:ss')
479
491
  }
480
492
 
481
493
  function vl(obj) {
482
- if (typeof obj === 'number') {
483
- return !Number.isNaN(obj)
494
+ let type= typeof obj;
495
+ if (type === 'number') {
496
+ return !Number.isNaN(obj) && Number.isFinite(obj);
484
497
  }
485
498
  if (typeof obj === 'string') {
486
499
  obj = obj.trim()
@@ -582,7 +595,7 @@ function getLogDir() {
582
595
  }
583
596
 
584
597
  function createLimitLogger(fileName, {
585
- maxChars,
598
+ maxChars = 49 * 1024 * 1024,
586
599
  logInfo = true,
587
600
  time = true,
588
601
  error = false
@@ -609,7 +622,7 @@ function createLimitLogger(fileName, {
609
622
  global.$newError = true;
610
623
  }
611
624
  if (time) {
612
- text = `[${timeStr()}] ${text}`
625
+ text = `${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${text}`
613
626
  }
614
627
  syncQueue(() => fp.appendFile(logPath, text + '\n'), logPath)
615
628
  let _minNum = (Date.now()/(1000 * 60 * 10)).toFixed(0)
@@ -736,8 +749,8 @@ function requireG(moduleName){
736
749
  let moduleDir = $workspaceMap[global.$defaultSpace] + '/node_modules'
737
750
  if (module.paths.indexOf(moduleDir) === -1) {
738
751
  module.paths.splice(0, module.paths.length)
739
- module.paths.push(...initModulePaths)
740
752
  module.paths.push(moduleDir)
753
+ module.paths.push(...initModulePaths)
741
754
  }
742
755
  try {
743
756
  let result = require(moduleName);
@@ -757,8 +770,8 @@ async function importG(moduleName) {
757
770
  let moduleDir = $workspaceMap[global.$defaultSpace] + '/node_modules'
758
771
  if (module.paths.indexOf(moduleDir) === -1) {
759
772
  module.paths.splice(0, module.paths.length)
760
- module.paths.push(...initModulePaths)
761
773
  module.paths.push(moduleDir)
774
+ module.paths.push(...initModulePaths)
762
775
  }
763
776
  try {
764
777
  let result = await import(moduleName);
@@ -771,7 +784,7 @@ async function importG(moduleName) {
771
784
  console.log(warnStr(`.npm install ${moduleName}`))
772
785
  throw `${moduleName} not found, use .npm install to add it`;
773
786
  }
774
- return await import(path);
787
+ return await import(require.resolve(path));
775
788
  }
776
789
 
777
790
  function validStr(str, name) {
@@ -966,17 +979,22 @@ async function _fileLock(key, fn) {
966
979
  } catch (e) {
967
980
  return false;
968
981
  }
982
+ let fileLockMap = getOr(global, `$fileLock`, {})
983
+ fileLockMap[file] = true;
969
984
  try {
970
985
  await fn();
971
- try {await fp.rmdir(file)} catch (_){}
972
986
  return true;
973
987
  } catch (e) {
974
- try {await fp.rmdir(file)} catch (_){}
975
988
  throw e;
989
+ } finally {
990
+ try {
991
+ await fp.rmdir(file)
992
+ delete fileLockMap[file]
993
+ } catch (_){}
976
994
  }
977
995
  }
978
996
 
979
- async function fileLock(key, fn, wait = false) {
997
+ async function fileLock(key, fn, wait = true) {
980
998
  `
981
999
  文件锁, 默认一直等待,直到加锁成功执行fn
982
1000
  wait = false, 加锁失败则不执行fn
@@ -987,7 +1005,7 @@ async function fileLock(key, fn, wait = false) {
987
1005
  if (await _fileLock(key, fn)) {
988
1006
  break;
989
1007
  }
990
- await sleep(9);
1008
+ await sleep(49);
991
1009
  }
992
1010
  } else {
993
1011
  await _fileLock(key, fn);
@@ -1098,7 +1116,7 @@ function fileCleaner(path, maxChars) {
1098
1116
  }
1099
1117
  }
1100
1118
 
1101
- function cleanFile(path, maxChars) {
1119
+ function cleanFile(path, maxChars = 9 * 1024 * 1024) {
1102
1120
  `
1103
1121
  进入文件操作队列,不会同步去做
1104
1122
  `
@@ -1123,7 +1141,7 @@ function cleanFile(path, maxChars) {
1123
1141
  }
1124
1142
  await fileLock(path, async () => {
1125
1143
  let content = String(await fp.readFile(path))
1126
- let newContext = content.substr(- (maxChars * 0.9))
1144
+ let newContext = content.slice(-Math.floor(maxChars * 0.7));
1127
1145
  await fp.writeFile(path, newContext)
1128
1146
  }, false)
1129
1147
  }, path)
@@ -1367,14 +1385,14 @@ function range(start, end, step) {
1367
1385
  }
1368
1386
 
1369
1387
  function getOr(obj, key, defaultVal) {
1370
- if (!obj[key]) {
1388
+ if (!vl(obj[key])) {
1371
1389
  obj[key] = defaultVal
1372
1390
  }
1373
1391
  return obj[key]
1374
1392
  }
1375
1393
 
1376
1394
  function getOrFn(obj, key, defaultValFn) {
1377
- if (!obj[key]) {
1395
+ if (!vl(obj[key])) {
1378
1396
  obj[key] = defaultValFn()
1379
1397
  }
1380
1398
  return obj[key]
@@ -1520,7 +1538,6 @@ function getInfo(obj, name, type) {
1520
1538
  }
1521
1539
  info.type = type || getType(obj)
1522
1540
  if (!vl(obj)) {
1523
- info.type = type
1524
1541
  info.value = String(obj);
1525
1542
  return info;
1526
1543
  }
@@ -1564,8 +1581,8 @@ function getInfo(obj, name, type) {
1564
1581
  function getFnArgsStr(str){
1565
1582
  let fnStr = trim(str.split(/=\s*>|(?<=\))\s*{/)[0])
1566
1583
  let argsStr
1567
- if (/[()]/.test(fnStr)) {
1568
- argsStr = fnStr.split(/[()]/)[1]
1584
+ if (fnStr.endsWith(')')) {
1585
+ argsStr = fnStr.substring(fnStr.indexOf("(") + 1, fnStr.length - 1)
1569
1586
  } else {
1570
1587
  argsStr = fnStr
1571
1588
  }
@@ -1793,7 +1810,7 @@ module.exports = {
1793
1810
  errorTag,
1794
1811
  iobjDataFile,
1795
1812
  iarrayDataFile,
1796
- isArgsMatch,
1813
+ isMatch,
1797
1814
  draftQuery,
1798
1815
  getTextComments,
1799
1816
  trimText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "JavaScript Script Management Tool",
5
5
  "main": "index.js",
6
6
  "scripts": {