jsir 1.1.2 → 1.1.4

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 (3) hide show
  1. package/cmd/ooa.js +45 -13
  2. package/package.json +1 -2
  3. package/sql.js +0 -11
package/cmd/ooa.js CHANGED
@@ -133,7 +133,7 @@ run(async () => {
133
133
 
134
134
  if (['run', 'edit', 'rm', 'diff', 'push', 'pull'].indexOf(_args[0]) !== -1
135
135
  && _args[1] && !/^\d+$/.test(_args[1])) {
136
- let name = `e ${_args[1]}.js`
136
+ let name = toJsirFileName(`e ${_args[1]}`)
137
137
  let path = _home + '/' + name
138
138
  if (_fs.existsSync(path)) {
139
139
  _cmdMap = {
@@ -204,7 +204,7 @@ async function fileLine(name) {
204
204
  }
205
205
  let tempDir = getLibDataDir() + "/ooa"
206
206
  mkdir(tempDir)
207
- let workFile = `${tempDir}/f ${name}.js`;
207
+ let workFile = `${tempDir}/f ${toJsirFileName(name)}`;
208
208
  if (!_fs.existsSync(workFile)) {
209
209
  _fs.writeFileSync(workFile, '');
210
210
  }
@@ -307,8 +307,7 @@ async function dealInitData() {
307
307
  continue;
308
308
  }
309
309
  let filePath = _home + "/" + file;
310
- let initDataName = file.replace(/^i\s+/, '')
311
- .replace(/\.js$/, '')
310
+ let initDataName = trimJsirFileName(file.replace(/^i\s+/, ''))
312
311
  .split(/\s+/).filter(item => item).join("_");
313
312
  let text = String(_fs.readFileSync(filePath))
314
313
  $i[initDataName] = null
@@ -408,7 +407,7 @@ function dealSourceCmds() {
408
407
  mkdir(source)
409
408
  }
410
409
  if (source && _fs.existsSync(source)) {
411
- _fs.readdirSync(source).filter(item => item.endsWith('.js')).forEach(item => {
410
+ _fs.readdirSync(source).filter(isJsirFileName).forEach(item => {
412
411
  if (!_fs.existsSync(_home + "/" + item)) {
413
412
  _fs.writeFileSync(_home + "/" + item, String(_fs.readFileSync(source + "/" + item)))
414
413
  }
@@ -419,7 +418,7 @@ function dealSourceCmds() {
419
418
  }
420
419
 
421
420
  async function save(args) {
422
- let path = `${_home}/${args.join(' ')}.js`
421
+ let path = `${_home}/${toJsirFileName(args.join(' '))}`
423
422
  if (_fs.existsSync(path)) {
424
423
  warn('already exist')
425
424
  return
@@ -508,11 +507,12 @@ function listCmd() {
508
507
 
509
508
  text = text1
510
509
  }
511
- let name = _cmdMap[i].replace(/\.js$/, '')
510
+ let name = trimJsirFileName(_cmdMap[i])
511
+ let suffix = getJsirFileSuffix(_cmdMap[i])
512
512
  let item = {
513
513
  key: prefix.join('') + i,
514
514
  name: name.replace(/^[eif]\s+/, ''),
515
- type: _types[name.split(/\s+/)[0]] || 'note'
515
+ type: [_types[name.split(/\s+/)[0]] || 'note', suffix].map(trim).join(".")
516
516
  }
517
517
  items.push(item)
518
518
 
@@ -657,7 +657,7 @@ async function wrapperInput(str) {
657
657
  if (_cmdMap[strs[0]]) {
658
658
  putHis(_cmdMap[strs[0]])
659
659
  let path = _home + '/' + _cmdMap[strs[0]]
660
- let fileName = _cmdMap[strs[0]].replace(/\.js$/, '');
660
+ let fileName = trimJsirFileName(_cmdMap[strs[0]]);
661
661
  let firstName = trim(fileName).split(/\s+/)[0]
662
662
  if (firstName === 'f') {
663
663
  await fileLine(fileName.replace(/^\s*f\s*/, ''))
@@ -735,7 +735,7 @@ async function dealKeyword(str, strs, fstr, ostr) {
735
735
  } else {
736
736
  let newName =trim(ostr.join(" "))
737
737
  if (newName) {
738
- newName = newName + ".js"
738
+ newName = toJsirFileName(newName)
739
739
  if (rename(_home + '/' + name, _home + '/' + newName)) {
740
740
  info(`${_home + '/' + newName} renamed`)
741
741
  }
@@ -838,7 +838,6 @@ async function dealKeyword(str, strs, fstr, ostr) {
838
838
  }
839
839
  }
840
840
 
841
-
842
841
  function getComments(text, cols = [], col) {
843
842
  let docLines = []
844
843
  text = trim(text)
@@ -873,16 +872,49 @@ function getComments(text, cols = [], col) {
873
872
  }
874
873
  }
875
874
 
875
+ function toJsirFileName(name) {
876
+ name = trim(name)
877
+ if (isJsirFileName(name)) {
878
+ return name;
879
+ }
880
+ name = name + '.js'
881
+ if (!isJsirFileName(name)) {
882
+ throw `invalid name`
883
+ }
884
+ return name
885
+ }
886
+
887
+ function isJsirFileName(name) {
888
+ name = trim(name)
889
+ return /^[^.]*[^.\s]\.[^.\s]+$/.test(name)
890
+ }
891
+
892
+ function trimJsirFileName(name) {
893
+ name = trim(name)
894
+ if (isJsirFileName(name)) {
895
+ return trim(name.replace(/\.[^.\s]+$/, ''))
896
+ }
897
+ return name
898
+ }
899
+
900
+ function getJsirFileSuffix(name) {
901
+ name = trim(name)
902
+ if (isJsirFileName(name)) {
903
+ return trim(name.split('.').slice(-1))
904
+ }
905
+ return ''
906
+ }
907
+
876
908
  function filterCmd(args){
877
909
  let cmdMap = {}
878
910
  let files = _fs.readdirSync(_home)
879
911
  let i = 1
880
912
  for (let file of files) {
881
913
  file = trim(file)
882
- let fileName = file.replace(/\.js$/, '')
883
- if (!file.endsWith('.js') || !fileName) {
914
+ if (!isJsirFileName(file)) {
884
915
  continue
885
916
  }
917
+ let fileName = trimJsirFileName(file)
886
918
  isArgsMatch(fileName, args, () => {
887
919
  if (Object.values(cmdMap).indexOf(file) === -1) {
888
920
  cmdMap[i] = file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,7 +31,6 @@
31
31
  "abi-decoder": "^2.3.0",
32
32
  "address": "^1.1.2",
33
33
  "axios": "^0.20.0",
34
- "better-sqlite3": "^7.4.3",
35
34
  "bignumber.js": "^9.0.0",
36
35
  "chokidar": "^3.5.2",
37
36
  "console.table": "^0.10.0",
package/sql.js DELETED
@@ -1,11 +0,0 @@
1
- const {getLibDataDir, mkdir, createLimitLogger} = require('./util');
2
- const Database = require('better-sqlite3');
3
- let dataDir = getLibDataDir()
4
- let dbDir = dataDir + '/db'
5
- mkdir(dbDir)
6
-
7
- function getDb(name) {
8
- let dbFile = dbDir + '/' + name
9
- return new Database(dbFile, { verbose: createLimitLogger(name + '.dblog') });
10
- }
11
-