crabatool 1.0.81 → 1.0.83

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/.eslintrc.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2015": false
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:native-ie/ie11",
9
+ "plugin:native-ie/ie10"
10
+ ],
11
+ "parserOptions": {
12
+ "ecmaVersion": "latest",
13
+ "sourceType": "script"
14
+ },
15
+ "rules": {
16
+ "semi": "off",
17
+ "no-unused-vars": "off",
18
+ "missingSemi": "off"
19
+ },
20
+ "globals": {
21
+ "Sys": "readonly",
22
+ "Craba": "readonly",
23
+ "Type": "readonly",
24
+ "$app": "readonly",
25
+ "$common": "readonly",
26
+ "$settings": "readonly",
27
+ "$craba": "readonly",
28
+ "$msg": "readonly",
29
+ "$print": "readonly",
30
+ "$notify": "readonly",
31
+ "$cache": "readonly",
32
+ "$user": "readonly",
33
+ "$userCache": "readonly",
34
+ "$dom": "readonly",
35
+ "$export": "readonly",
36
+ "$skin": "readonly",
37
+ "$step": "readonly",
38
+ "$ms": "readonly",
39
+ "$createDelegate": "readonly",
40
+ "$createControl": "readonly",
41
+ "$uploader": "readonly",
42
+ "$debug": "readonly",
43
+ "$skinUtils": "readonly",
44
+ "$scriptLoader": "readonly",
45
+ "$removeNode": "readonly",
46
+ "$get": "readonly",
47
+ "$agency": "readonly",
48
+ "$createControlFromGspx": "readonly",
49
+ "handleError": "readonly",
50
+ "$jsLoader": "readonly"
51
+ }
52
+ }
package/lib/config.js CHANGED
@@ -9,7 +9,7 @@ class Config {
9
9
  this.crabaHooks = "https://oapi.dingtalk.com/robot/send?access_token=ce27b1b1540881540d44c0bd05ba738d865363758892ede137dc1020bd36bd5a";
10
10
  //this.webhooks = "https://oapi.dingtalk.com/robot/send?access_token=37279df60e03ebf25e8eb71230ddb93fe74de99951a8d635d0458e60bfcd44d8";
11
11
  this.checkgspx = true; // 检查gspx
12
-
12
+ this.ignoreCheck = [];
13
13
  this.Version = pg.version;
14
14
  this.Debug = false;
15
15
  //this.SourceHost = "http://crabadoc.mygjp.com.cn";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.81",
3
+ "version": "1.0.83",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,23 +12,25 @@
12
12
  },
13
13
  "author": "wssf",
14
14
  "dependencies": {
15
+ "@jslint-org/jslint": "^2022.5.20",
16
+ "axios": "^0.27.2",
15
17
  "chokidar": "^3.5.3",
18
+ "compressing": "^1.6.0",
16
19
  "compression": "^1.7.4",
20
+ "crypto": "^1.0.1",
17
21
  "express": "^4.17.3",
22
+ "htmlparser2": "^8.0.1",
23
+ "iconv-jschardet": "^2.0.26",
18
24
  "iconv-lite": "^0.5.2",
19
- "uglify-js": "^3.15.1",
20
- "readline-sync": "^1.4.10",
21
- "single-line-log": "^1.1.2",
22
- "crypto": "^1.0.1",
23
25
  "nodejs-websocket": "^1.7.2",
26
+ "readline-sync": "^1.4.10",
24
27
  "request": "^2.88.2",
28
+ "single-line-log": "^1.1.2",
25
29
  "sync-request": "^6.1.0",
26
- "axios": "^0.27.2",
27
- "iconv-jschardet": "^2.0.26",
28
- "compressing": "^1.6.0",
29
- "@jslint-org/jslint": "^2022.5.20",
30
- "htmlparser2": "^8.0.1",
31
- "xml-js": "^1.6.11"
30
+ "uglify-js": "^3.15.1",
31
+ "xml-js": "^1.6.11",
32
+ "eslint": "^8.18.0",
33
+ "eslint-plugin-native-ie": "^0.1.2"
32
34
  },
33
35
  "repository": {
34
36
  "type": "git",
@@ -37,5 +39,6 @@
37
39
  "keywords": [
38
40
  "crabatool"
39
41
  ],
40
- "license": "UNLICENSED"
42
+ "license": "UNLICENSED",
43
+ "devDependencies": {}
41
44
  }
@@ -0,0 +1,70 @@
1
+ [
2
+ {
3
+ "filePath": "<text>",
4
+ "messages": [
5
+ {
6
+ "ruleId": "native-ie/no-let",
7
+ "severity": 2,
8
+ "message": "Do not use let.",
9
+ "line": 13,
10
+ "column": 9,
11
+ "nodeType": "VariableDeclaration",
12
+ "messageId": "disallow-let",
13
+ "endLine": 13,
14
+ "endColumn": 20
15
+ },
16
+ {
17
+ "ruleId": "no-unused-vars",
18
+ "severity": 2,
19
+ "message": "'a' is assigned a value but never used.",
20
+ "line": 13,
21
+ "column": 13,
22
+ "nodeType": "Identifier",
23
+ "messageId": "unusedVar",
24
+ "endLine": 13,
25
+ "endColumn": 14
26
+ },
27
+ {
28
+ "ruleId": "native-ie/no-const",
29
+ "severity": 2,
30
+ "message": "Do not use const.",
31
+ "line": 14,
32
+ "column": 9,
33
+ "nodeType": "VariableDeclaration",
34
+ "messageId": "disallow-const",
35
+ "endLine": 14,
36
+ "endColumn": 22
37
+ },
38
+ {
39
+ "ruleId": "no-unused-vars",
40
+ "severity": 2,
41
+ "message": "'b' is assigned a value but never used.",
42
+ "line": 14,
43
+ "column": 15,
44
+ "nodeType": "Identifier",
45
+ "messageId": "unusedVar",
46
+ "endLine": 14,
47
+ "endColumn": 16
48
+ },
49
+ {
50
+ "ruleId": "no-unused-vars",
51
+ "severity": 2,
52
+ "message": "'index' is defined but never used.",
53
+ "line": 36,
54
+ "column": 53,
55
+ "nodeType": "Identifier",
56
+ "messageId": "unusedVar",
57
+ "endLine": 36,
58
+ "endColumn": 58
59
+ }
60
+ ],
61
+ "suppressedMessages": [],
62
+ "errorCount": 5,
63
+ "fatalErrorCount": 0,
64
+ "warningCount": 0,
65
+ "fixableErrorCount": 0,
66
+ "fixableWarningCount": 0,
67
+ "source": "Type.registerNamespace('crabadoc.Admin');\\r\\ncrabadoc.Admin.AQAction = function() {\\r\\n crabadoc.Admin.AQAction.initializeBase(this);\\r\\n this.mdRender = new CrabaMarkdown({ isSidebar: false });\\r\\n this.apiName = 'aq';\\r\\n this.pageName = 'AQ';\\r\\n};\\r\\n\\r\\ncrabadoc.Admin.AQAction.prototype = {\\r\\n initialize: function() {\\r\\n crabadoc.Admin.AQAction.callBaseMethod(this, 'initialize');\\r\\n\\r\\n let a = 10;\\r\\n const b = 10;\\r\\n\\r\\n var tree = this.get_form().tree;\\r\\n var newNode = tree.get_rootNode().addNode('老文档', { id: 9999, text: '老文档' });\\r\\n newNode._haschild = true;\\r\\n newNode.collapse();\\r\\n },\\r\\n\\r\\n dispose: function() {\\r\\n crabadoc.Admin.AQAction.callBaseMethod(this, 'dispose');\\r\\n },\\r\\n\\r\\n doExpandClick: function(node) {\\r\\n $common.ajax({\\r\\n url: '/apis/aq/getOldDocs',\\r\\n complete: function(response) {\\r\\n if (response.get_statusCode() == 200) {\\r\\n var list = response.get_object();\\r\\n if (list && list.length > 0) {\\r\\n list.sort(function(info1, info2) {\\r\\n return info1.time - info2.time;\\r\\n });\\r\\n list.forEach(function(info, index) {\\r\\n node.addChild(info.text, info, false, true);\\r\\n });\\r\\n }\\r\\n }\\r\\n }\\r\\n });\\r\\n }\\r\\n};\\r\\ncrabadoc.Admin.AQAction.registerClass('crabadoc.Admin.AQAction', crabadoc.Admin.ComListAction);\\r\\n",
68
+ "usedDeprecatedRules": []
69
+ }
70
+ ]
package/test/test.js CHANGED
@@ -41,6 +41,8 @@ var config = {
41
41
 
42
42
  Debug: true,
43
43
 
44
+ globals: ['crabadoc', 'Type', 'CrabaMarkdown', '$doc', 'www', 'crabaJs'],
45
+
44
46
  // 配置js语法检测报告推送地址
45
47
  webhooks: ''
46
48
  //https://oapi.dingtalk.com/robot/send?access_token=ce27b1b1540881540d44c0bd05ba738d865363758892ede137dc1020bd36bd5a
package/tool/checkjs.js CHANGED
@@ -6,11 +6,13 @@ var jschardet = require('iconv-jschardet');
6
6
  var path = require('path');
7
7
  var axios = require('axios');
8
8
  var gspx = require('./checkgspx.js');
9
+ var eslint = require('eslint');
10
+
9
11
 
10
12
  // js超过多少kb给与提示
11
13
  var fileSize = 300;
12
14
  // 默认忽略大小的文件
13
- var sizeBlackList = ['craba.min.js', 'crabaEx.min.js', 'crabaNgp.js', 'echarts-all.js', 'echarts.min.js', 'math.min.js'];
15
+ var blackList = ['agency.js', 'craba.min.js', 'crabaEx.min.js', 'crabaNgp.js', 'echarts-all.js', 'echarts.min.js', 'math.min.js', 'craba.rollup.min.js'];
14
16
  // 语法规则,不能包含这些关键词
15
17
  var dangerousJs = ['\\slet\\s', '\\sconst\\s', '\=\>\\s?\\(?\\{', '\\sasync\\s', '\\sawait\\s', '\\.then\\(', '\\sdebugger\\s'];
16
18
 
@@ -34,7 +36,7 @@ var warnTagsInfo = {
34
36
  }
35
37
 
36
38
 
37
- module.exports.start = function() {
39
+ module.exports.start = async function() {
38
40
  var jsFiles = utils.getFiles({ source: config.webPath, exts: '.js', ignores: config.ignoreCheck });
39
41
 
40
42
  var errList = [];
@@ -45,23 +47,18 @@ module.exports.start = function() {
45
47
 
46
48
  // 开始检测
47
49
  var pb = new ProgressBar('检查进度', jsFiles.length);
48
- jsFiles.forEach(function(filePath) {
49
- pb.value++;
50
- pb.render({ value: pb.value, text: filePath });
50
+ //jsFiles.forEach(async function(filePath) {
51
+ for (var i = 0; i < jsFiles.length; i++) {
52
+ var filePath = jsFiles[i];
53
+ var basename = path.basename(filePath);
54
+ if (blackList.includes(basename)) continue;
51
55
 
52
56
  var byte = fs.readFileSync(filePath);
53
- var stats = fs.statSync(filePath);
54
-
55
- // 简化文件路径
56
- filePath = filePath.replace(config.webPath, '');
57
-
58
- // 检查大小
59
- if (stats.size / 1024 > fileSize && sizeBlackList.length > 0 && !sizeBlackList.includes(path.basename(filePath))) {
60
- bigList.push(`${filePath} ${parseInt(stats.size / 1024)}kb`);
61
- }
57
+ var content = byte.toString();
58
+ // eslint检查
59
+ var eslintResults = await eslintCheck(content);
62
60
 
63
61
  // 检查编码
64
- var content = byte.toString();
65
62
  var ret = jschardet.detect(byte);
66
63
  if (utils.isUtf8(byte, ret.encoding) || ret.encoding == 'UTF-8') {
67
64
  utf8List.push(filePath);
@@ -74,24 +71,49 @@ module.exports.start = function() {
74
71
  content = utils.toUtf8(byte);
75
72
  }
76
73
  }
74
+ pb.value++;
75
+ pb.render({ value: pb.value, text: filePath });
76
+
77
+
78
+ var stats = fs.statSync(filePath);
79
+
80
+ // 简化文件路径
81
+ filePath = filePath.replace(config.webPath, '');
82
+
83
+ // 检查大小
84
+ if (stats.size / 1024 > fileSize) {
85
+ bigList.push(`${filePath} ${parseInt(stats.size / 1024)}kb`);
86
+ }
77
87
 
88
+ var errInfo = { list: [] };
89
+ if (eslintResults.length > 0 && eslintResults[0].errorCount > 0) {
90
+ var res = eslintResults[0];
91
+ errList.push(filePath);
92
+ errRegList.push(errInfo);
93
+
94
+ res.messages.forEach((item) => {
95
+ errInfo.list.push({ char: item.ruleId + ',' + item.messageId, line: item.line, endLine: item.endLine, column: item.column, msg: item.message });
96
+ });
97
+ }
98
+ continue;
78
99
  // ------检查语法1--------
79
- var errInfo = { list: null };
80
100
  var reg = new RegExp(dangerousJs.join('|'), 'ig');
81
101
  if (reg.test(content)) { // 先检查是否有危险字符
82
102
  var noComment = utils.clearComment(content);// 去掉注释的代码再查一遍;因为js里面有些危险字符是被注释了的
83
103
 
84
104
  // 二次检查
85
105
  if (reg.test(noComment)) {
86
- errList.push(filePath); // 记录该js有异常
106
+ if (errInfo.list.length == 0) {
107
+ errList.push(filePath); // 记录该js有异常
108
+ errRegList.push(errInfo);
109
+ }
87
110
 
88
111
  var nreg = new RegExp(dangerousJs.join('|'), 'ig');
89
112
  var elist = getMathReuslts(noComment, nreg);
90
- errInfo.list = elist;
91
- errRegList.push(errInfo);
113
+ errInfo.list = errInfo.list.concat(elist);
92
114
  }
93
115
  }
94
- });
116
+ }
95
117
  pb.clear('检验完成');
96
118
 
97
119
  // 检查gspx
@@ -161,11 +183,11 @@ module.exports.start = function() {
161
183
  detail.push(`${index + 1}. ${s}`);
162
184
 
163
185
  var err = errRegList[index];
164
- detail.push("| 异常字符 | 位置 |");
165
- detail.push("| ----- | ------ |");
186
+ detail.push("| 异常字符 | 行号 | 列号 | 说明 |");
187
+ detail.push("| ----- | ------ | ---- | ---- |");
166
188
  err.list.forEach((item) => {
167
- detail.push(`| ${item.char.trim()} | ${item.index} |`);
168
- sonar.issues.push(getSonarEntity('语法异常', modName, item.char.trim(), s, -1, item.index));
189
+ detail.push(`| ${item.char.trim()} | ${item.line || '-'} | ${item.column || '-'} | ${item.msg || '-'} |`);
190
+ sonar.issues.push(getSonarEntity('语法异常', modName, item.char.trim(), s, -1, item.line, item.column, item.endLine));
169
191
  });
170
192
  });
171
193
  }
@@ -239,6 +261,20 @@ module.exports.start = function() {
239
261
  }
240
262
  }
241
263
 
264
+ async function eslintCheck(content) {
265
+ var options = { overrideConfig: { globals: { 'crabadoc': 'readonly' } } };
266
+ var globals = config.globals;
267
+ if (globals) {
268
+ globals.forEach(key => {
269
+ options.overrideConfig.globals[key] = 'readonly';
270
+ });
271
+ }
272
+ var lint = new eslint.ESLint(options);
273
+ var res = await lint.lintText(content);
274
+ //console.log(res);
275
+ return res;
276
+ }
277
+
242
278
  function getMathReuslts(content, nreg, filterFun) {
243
279
  var all = content.matchAll(nreg);
244
280
  var list = [];
@@ -246,14 +282,14 @@ function getMathReuslts(content, nreg, filterFun) {
246
282
  while (!v.done) {
247
283
  var value = v.value[0];
248
284
  if (!filterFun || filterFun(value)) {
249
- list.push({ "char": value, "index": v.value.index });
285
+ list.push({ "char": value, "column": v.value.index });
250
286
  }
251
287
  v = all.next();
252
288
  }
253
289
  return list;
254
290
  }
255
291
 
256
- function getSonarEntity(type, modName, message, filePath, line, col) {
292
+ function getSonarEntity(type, modName, message, filePath, line, column, endLine) {
257
293
  var entity = {
258
294
  "engineId": modName,
259
295
  "ruleId": "no-undef", // 规则名称,例如不使用const
@@ -261,9 +297,9 @@ function getSonarEntity(type, modName, message, filePath, line, col) {
261
297
  "message": message, // 提示信息
262
298
  "filePath": filePath, // 所在文件
263
299
  "textRange": {
264
- "startLine": line, // 起始行号
265
- "endLine": line, // 行号
266
- "endColumn": col // 结束字符位置
300
+ "startLine": line || 0, // 起始行号
301
+ "endLine": endLine || 0, // 行号
302
+ "endColumn": column || 0 // 结束字符位置
267
303
  }
268
304
  },
269
305
  "type": type,
@@ -299,6 +335,7 @@ function postReport(id, reportUrl, content, sonar) {
299
335
  method: 'post',
300
336
  url: config.reportHost + '/apis/saveJsReport',
301
337
  data: data,
338
+ maxBodyLength: Infinity,
302
339
  headers: { 'Content-Type': 'application/json' },
303
340
 
304
341
  // proxy: { // 配置代理地址
@@ -309,7 +346,7 @@ function postReport(id, reportUrl, content, sonar) {
309
346
  console.log("保存报告ok");
310
347
  //console.log(response.data);
311
348
  }).catch(function(error) {
312
- console.log("保存报告失败,network error");
349
+ console.log("保存报告失败," + error.message);
313
350
  //console.log(error);
314
351
  });
315
352
 
@@ -343,8 +380,8 @@ function postWebhooks(id, reportUrl, webhookList) {
343
380
  console.log("推送代码检测状态");
344
381
  console.log(response.data);
345
382
  }).catch(function(error) {
346
- console.log("推送代码检测失败");
347
- console.log(error);
383
+ console.log("推送代码检测失败:" + error.message);
384
+ //console.log(error);
348
385
  });
349
386
 
350
387
  // 如果业务配置的推送地址不是平台群,需要统一推送到平台,汇总一下问题,方便后期统筹
@@ -356,10 +393,10 @@ function postWebhooks(id, reportUrl, webhookList) {
356
393
  headers: { 'Content-Type': 'application/json' }
357
394
  }).then(function(response) {
358
395
  console.log("推送代码检测状态");
359
- console.log(response.data);
396
+ //console.log(response.data);
360
397
  }).catch(function(error) {
361
- console.log("推送代码检测失败");
362
- console.log(error);
398
+ console.log("推送代码检测失败:" + error.message);
399
+ //console.log(error);
363
400
  });
364
401
  }
365
402
  }
package/tool/start.js CHANGED
@@ -24,7 +24,7 @@ class Start {
24
24
  "1. 启动服务。\t\t\t\t主要包含:自动合并打包init.js和biz.js,查看本地平台的版本",
25
25
  "2. 更新当前项目的平台,然后启动服务。\t主要包含:从<内网>拉取环境相关资源,再拷贝到webPath路径下覆盖老文件,替代手工操作,同时解决npm不稳定问题",
26
26
  "3. 查询最新平台版本和日期。\t\t主要包含:从<内网>拉取最新平台版本,开发好及时更新补丁",
27
- "4. 校验当前项目前端js语法和兼容性,以及gspx检查。\t主要包含:对本地js语法做一次初步预检避免上线后才发现问题;比如:编码、let、const、=>、async、await、then、缺function",
27
+ "4. 校验当前项目jsgspx语法。\t\t主要包含:对本地js语法做一次初步预检避免上线后才发现问题;比如:编码、let、const、=>、async、await、then、缺function",
28
28
  "5. 打包当前项目前端所有js。\t\t主要包含:前端es6语法的打包和js的统一压缩处理",
29
29
  "6. 安装或更新IDEA环境。\t\t\t主要包含:从<内网>拉取环境相关资源,包括智能语法、新增页面模板、更多新功能",
30
30
  "7. 安装或更新vscode环境。\t\t主要包含:从<内网>拉取环境相关资源,包括智能语法、新增页面模板、ctrl+alt+n、alt+j快捷键",
@@ -80,6 +80,7 @@ class Start {
80
80
  bindConfigByArgv('-webhooks');
81
81
  bindConfigByArgv('-progress');
82
82
  bindConfigByArgv('-childModList', 'array');
83
+ bindConfigByArgv('-globals', 'array');
83
84
  bindConfigByArgv('-ignoreCompress', 'boolean');
84
85
  bindConfigByArgv('-Debug', 'boolean');
85
86
  bindConfigByArgv('-checkgspx', 'boolean');