jsir 1.3.2 → 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.
- package/cmd/{ooa.js → oaa.js} +535 -406
- package/evalCode.js +22 -3
- package/package.json +3 -3
- package/util.js +60 -17
package/evalCode.js
CHANGED
|
@@ -5,10 +5,29 @@ const {info: $info, msg: $msg, warn: $warn, error: $error,
|
|
|
5
5
|
importG: $import} = require("./util");
|
|
6
6
|
require = require("./util").requireG;
|
|
7
7
|
module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
8
|
-
$
|
|
9
|
-
$nextLine, $nextText,
|
|
10
|
-
$
|
|
8
|
+
$require, $data,
|
|
9
|
+
$nextLine, $nextText,
|
|
10
|
+
$setTips, $delTips,
|
|
11
|
+
$enter, $filterCmd,
|
|
12
|
+
$currentSpace, $log,
|
|
13
|
+
$draft, $config,
|
|
14
|
+
$homeDir, $lib) => {
|
|
11
15
|
const $defArgs = () => $args;
|
|
16
|
+
const $context = {
|
|
17
|
+
global, $data,
|
|
18
|
+
$require, $import,
|
|
19
|
+
$info, $msg, $warn, $error,
|
|
20
|
+
$infoStr, $msgStr, $warnStr, $errorStr,
|
|
21
|
+
$tableStr, $nableStr,
|
|
22
|
+
$errorMsg, $errorStack,
|
|
23
|
+
$text, $cmdName, $args,
|
|
24
|
+
$nextLine, $nextText,
|
|
25
|
+
$setTips, $delTips,
|
|
26
|
+
$enter, $filterCmd,
|
|
27
|
+
$currentSpace, $log,
|
|
28
|
+
$draft, $config,
|
|
29
|
+
$homeDir, $lib
|
|
30
|
+
}
|
|
12
31
|
return await eval(`(async ()=>{${$text};
|
|
13
32
|
})()`)
|
|
14
33
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsir",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "js script manager tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "node cmd/
|
|
7
|
+
"test": "node cmd/oaa.js --repl"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
10
|
"jsir-see": "cmd/see.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"jsir-mock": "cmd/mockServer.js",
|
|
21
21
|
"jsir-ethDataServer": "cmd/ethDataServer.js",
|
|
22
22
|
"jsir-configServer": "cmd/configServer.js",
|
|
23
|
-
"jsir": "cmd/
|
|
23
|
+
"jsir": "cmd/oaa.js"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [],
|
|
26
26
|
"author": "",
|
package/util.js
CHANGED
|
@@ -20,15 +20,14 @@ const table = require('console.table')
|
|
|
20
20
|
const _fs = require("fs");
|
|
21
21
|
|
|
22
22
|
let _globalLog = createLimitLogger2(`${setting.name}.log`, null, false)
|
|
23
|
-
|
|
23
|
+
const $log = str => {
|
|
24
24
|
str = trim(str)
|
|
25
25
|
if (str) {
|
|
26
26
|
_globalLog(`[${timeStr()}] ${str}`)
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
const $log = global.$log
|
|
30
29
|
let _globalDraft= createLimitLogger2(`draft.log`, null, false)
|
|
31
|
-
|
|
30
|
+
const $draft = str => {
|
|
32
31
|
if (getType(str) === 'RegExp') {
|
|
33
32
|
let results = draftQuery(trim(str.source))
|
|
34
33
|
return results.map(i => i.split(/\n/).slice(1).join('\n'))
|
|
@@ -36,10 +35,9 @@ global.$draft = str => {
|
|
|
36
35
|
_globalDraft(`---------${timeStr()}\n${str.split("\n").filter(i => trim(i)).join("\n")}`)
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
const $
|
|
40
|
-
global.$fnCache = {}
|
|
38
|
+
const $fnCache = {}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
const $config = {
|
|
43
41
|
_buildId: null,
|
|
44
42
|
build: async function () {
|
|
45
43
|
if ($config._buildId == null) {
|
|
@@ -72,7 +70,6 @@ global.$config = {
|
|
|
72
70
|
setConfig(key, val)
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
|
-
const $config = global.$config
|
|
76
73
|
|
|
77
74
|
async function _buildConfig() {
|
|
78
75
|
try {
|
|
@@ -91,13 +88,13 @@ async function _buildConfig() {
|
|
|
91
88
|
$config._buildId = setTimeout(_buildConfig, 3000);
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
function isArgsMatch(text, args, callback, useMd5) {
|
|
91
|
+
function isArgsMatch(text, args, callback, useMd5, md5Str) {
|
|
95
92
|
let match = false
|
|
96
93
|
for (let arg of args) {
|
|
97
94
|
let r = true
|
|
98
|
-
for (let str of arg.split(',').filter(
|
|
99
|
-
let reg = new RegExp(str, 'i')
|
|
100
|
-
if (!reg.test(text) && !(useMd5 && ('0x' + md5(text).substr(0, 8)) === str)) {
|
|
95
|
+
for (let str of arg.split(',').map(trim).filter(i => i)) {
|
|
96
|
+
let reg = new RegExp(str.split(/\s+/).join('\\s+'), 'i')
|
|
97
|
+
if (!reg.test(text) && !(useMd5 && ('0x' + md5(md5Str || text).substr(0, 8)) === str)) {
|
|
101
98
|
r = false
|
|
102
99
|
break
|
|
103
100
|
}
|
|
@@ -145,7 +142,7 @@ function draftQuery(fLine) {
|
|
|
145
142
|
if (!/^\d+$/.test(fLine)) {
|
|
146
143
|
let items = fLine.split(/\s+/).filter(i => i)
|
|
147
144
|
for (let line of lines) {
|
|
148
|
-
if (isArgsMatch(line, items.filter(item => !/^\d+$/.test(item)))) {
|
|
145
|
+
if (isArgsMatch(line, [items.filter(item => !/^\d+$/.test(item)).join(' ')])) {
|
|
149
146
|
results.push(line)
|
|
150
147
|
}
|
|
151
148
|
}
|
|
@@ -331,13 +328,13 @@ function iarrayDataFile(fileName, fn, fmt) {
|
|
|
331
328
|
}
|
|
332
329
|
function getInitName(fileName) {
|
|
333
330
|
fileName = trim(fileName)
|
|
334
|
-
let
|
|
331
|
+
let homeDir = global.$workspaceMap[$defaultSpace]
|
|
335
332
|
if (!fileName.startsWith("/")) {
|
|
336
333
|
fileName = 'i ' + fileName.replace(/i\s+/, '')
|
|
337
334
|
if (!/\..+/.test(fileName)) {
|
|
338
335
|
fileName = fileName + '.js'
|
|
339
336
|
}
|
|
340
|
-
fileName =
|
|
337
|
+
fileName = homeDir + '/' + fileName
|
|
341
338
|
}
|
|
342
339
|
return fileName;
|
|
343
340
|
}
|
|
@@ -477,10 +474,11 @@ function getConfig(key, defaultVal) {
|
|
|
477
474
|
fs.writeFileSync(configFile, JSON.stringify(config, null, 2))
|
|
478
475
|
}
|
|
479
476
|
|
|
480
|
-
return getVl(config[key], defaultVal)
|
|
477
|
+
return trim(getVl(config[key], defaultVal))
|
|
481
478
|
}
|
|
482
479
|
|
|
483
480
|
function setConfig(key, val) {
|
|
481
|
+
val = trim(val)
|
|
484
482
|
let configInit = {}
|
|
485
483
|
if (key) {
|
|
486
484
|
configInit[key] = val
|
|
@@ -1088,7 +1086,7 @@ function getInfo(obj, key) {
|
|
|
1088
1086
|
value = 'args: ' + value
|
|
1089
1087
|
}
|
|
1090
1088
|
} else if (typeof obj === 'string') {
|
|
1091
|
-
value =
|
|
1089
|
+
value = str.length <= 64 ? str : `${str.substr(0, 64)}...[length: ${str.length}]`
|
|
1092
1090
|
} else {
|
|
1093
1091
|
let len = Object.keys(obj).length;
|
|
1094
1092
|
value = len > 0 ? ('keys: ' + len) : (str.length <= 64 ? str : `${str.substr(0, 64)}...[length: ${str.length}]`);
|
|
@@ -1180,6 +1178,50 @@ function errorTag(e, tag) {
|
|
|
1180
1178
|
return e
|
|
1181
1179
|
}
|
|
1182
1180
|
|
|
1181
|
+
function getTextComments(text) {
|
|
1182
|
+
let results = []
|
|
1183
|
+
text = text.replace(/\r/g, '\n')
|
|
1184
|
+
text = text.replace(/\n+/g, '\n')
|
|
1185
|
+
let lines = text.split(/\n/);
|
|
1186
|
+
|
|
1187
|
+
if (text.startsWith("/*")) {
|
|
1188
|
+
for (let line of lines) {
|
|
1189
|
+
let trimLine = trim(line)
|
|
1190
|
+
if (!trimLine) {
|
|
1191
|
+
continue
|
|
1192
|
+
}
|
|
1193
|
+
if (trimLine.startsWith("/*")) {
|
|
1194
|
+
continue
|
|
1195
|
+
}
|
|
1196
|
+
if (trimLine.endsWith("*/")) {
|
|
1197
|
+
break
|
|
1198
|
+
}
|
|
1199
|
+
results.push(line)
|
|
1200
|
+
}
|
|
1201
|
+
} else {
|
|
1202
|
+
for (let key of ['#', '/', '-', ';']) {
|
|
1203
|
+
if (!text.startsWith(key)) {
|
|
1204
|
+
continue
|
|
1205
|
+
}
|
|
1206
|
+
for (let line of lines) {
|
|
1207
|
+
let trimLine = trim(line)
|
|
1208
|
+
if (!trimLine) {
|
|
1209
|
+
continue
|
|
1210
|
+
}
|
|
1211
|
+
if (trimLine.startsWith(key)) {
|
|
1212
|
+
let line = trimLine.replace(new RegExp(`^[${key}]+`), '');
|
|
1213
|
+
if (trim(line)) {
|
|
1214
|
+
results.push(line)
|
|
1215
|
+
}
|
|
1216
|
+
} else {
|
|
1217
|
+
break
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
return results.map(i => i.replace(/\s+$/, ''))
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1183
1225
|
module.exports = {
|
|
1184
1226
|
run,
|
|
1185
1227
|
reget,
|
|
@@ -1272,5 +1314,6 @@ module.exports = {
|
|
|
1272
1314
|
iarrayDataFile,
|
|
1273
1315
|
isArgsMatch,
|
|
1274
1316
|
draftQuery,
|
|
1275
|
-
importG
|
|
1317
|
+
importG,
|
|
1318
|
+
getTextComments
|
|
1276
1319
|
}
|