crabatool 1.0.27 → 1.0.30

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.
@@ -4,6 +4,7 @@
4
4
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
+
7
8
  {
8
9
  "type": "pwa-node",
9
10
  "request": "launch",
package/index.js CHANGED
@@ -41,8 +41,14 @@ function bindConfigByArgv(key) {
41
41
  }
42
42
  function checkConfig() {
43
43
  bindConfigByArgv('-webPath');
44
+ bindConfigByArgv('-port');
44
45
  bindConfigByArgv('-modName');
45
46
  bindConfigByArgv('-ignoreCheck');
47
+ bindConfigByArgv('-webhooks');
48
+
49
+ if (config.ignoreCheck && typeof config.ignoreCheck == 'string') {
50
+ config.ignoreCheck = config.ignoreCheck.split(',');
51
+ }
46
52
 
47
53
  if (!config.webPath) {
48
54
  throw new Error('请检查craba.js,必须告诉工具当前项目的前端路径地址,填绝对路径哦');
package/lib/config.js CHANGED
@@ -3,6 +3,9 @@ var os = require('os');
3
3
 
4
4
  class Config {
5
5
  constructor() {
6
+ this.reportHost = "http://crabadoc.ca.com"; // 用于接收检测报告的服务器,可配置的。由于产品没有提供服务,目前统一放到平台的文档服务器
7
+ this.webhooks = "https://oapi.dingtalk.com/robot/send?access_token=ce27b1b1540881540d44c0bd05ba738d865363758892ede137dc1020bd36bd5a";
8
+
6
9
  this.Debug = false;
7
10
  this.Host = "http://crabadoc.mygjp.com.cn";
8
11
  this.TempPath = path.join(os.tmpdir(), '_crabatemp');
package/lib/utils.js CHANGED
@@ -359,18 +359,17 @@ class Utils {
359
359
  }
360
360
 
361
361
  getFiles(options, fileList) {
362
- var ignores = options.ignores;
363
362
  var exts = options.exts;
364
363
  var source = options.source;
365
- if (ignores && !fileList) {
366
- ignores = ignores.map((item) => { return path.join(source, item) });
364
+ if (options.ignores && !fileList) {
365
+ options.ignores = options.ignores.map((item) => { return path.join(source, item) });
367
366
  }
368
367
 
369
368
  if (!fileList) fileList = [];
370
369
  var files = fs.readdirSync(source);
371
370
  files.forEach(function(fileName) {
372
371
  var filePath = path.join(source, fileName);
373
- if (ignores && ignores.includes(filePath)) {
372
+ if (options.ignores && options.ignores.includes(filePath)) {
374
373
  return;
375
374
  }
376
375
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.27",
3
+ "version": "1.0.30",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "test": "node ./test/test.js",
9
9
  "run": "node ./test/test.js -run",
10
10
  "checkjs": "node ./test/test.js -checkjs",
11
- "webPath": "node ./test/test.js -checkjs -webPath F:、\newcrabadoc\\www"
11
+ "webPath": "node ./test/test.js -checkjs -webPath F:\\crabaevery\\www -modName crabademo -ignoreCheck ueditor,iconfont,biconfont,js\\math.min.js,js\\es6-promise.auto.min.js,js\\craba.rollup.min.js"
12
12
  },
13
13
  "author": "wssf",
14
14
  "dependencies": {
File without changes
package/test/test.js CHANGED
@@ -33,6 +33,9 @@ var config = {
33
33
  // 上一步中打包后的文件是否压缩, true为忽略【不压缩】,false为【要压缩】,各组按需修改
34
34
  ignoreCompress: true,
35
35
 
36
+ // 用于保存检查报告的api
37
+ reportHost: 'http://127.0.0.1:9998',
38
+
36
39
  // 配置js语法检测报告推送地址
37
40
  webhooks: 'https://oapi.dingtalk.com/robot/send?access_token=ce27b1b1540881540d44c0bd05ba738d865363758892ede137dc1020bd36bd5a' //'https://oapi.dingtalk.com/robot/send?access_token=37279df60e03ebf25e8eb71230ddb93fe74de99951a8d635d0458e60bfcd44d8'
38
41
  }
package/tool/checkjs.js CHANGED
@@ -1,5 +1,4 @@
1
1
  var utils = require('../lib/utils.js');
2
- var StringBuilder = require("../lib/stringBuilder.js");
3
2
  var config = require('../lib/config.js');
4
3
  var fs = require('fs');
5
4
  var ProgressBar = require('./progressbar.js');
@@ -8,7 +7,7 @@ var path = require('path');
8
7
  var axios = require('axios');
9
8
 
10
9
  module.exports.start = function() {
11
- var jsFiles = utils.getFiles({ source: config.webPath, exts: '.js', ignores: config.ignoresCheck });
10
+ var jsFiles = utils.getFiles({ source: config.webPath, exts: '.js', ignores: config.ignoreCheck });
12
11
 
13
12
  var fileSize = 300;
14
13
  var errList = [];
@@ -67,68 +66,102 @@ module.exports.start = function() {
67
66
  });
68
67
  pb.clear('检验完成');
69
68
 
70
- //var sb = new StringBuilder();
71
- var info = new StringBuilder();
72
- info.push(`# ${config.modName}代码检测报告`);
73
- info.push("");
74
-
69
+ var modName = config.modName || 'noname';
70
+ var info = [];
71
+ info.push(`# ${modName}代码检测报告`);
72
+ info.push("| 名称 | 结果 |");
73
+ info.push("| ------ | ------ |");
74
+ info.push('|生成报告时间|' + new Date().toString() + '|');
75
+ info.push(`|共检查|${jsFiles.length}个js文件|`);
76
+ if (config.ignoreCheck) {
77
+ info.push(`|忽略目录和文件|${config.ignoreCheck.join('、') + '|'}`);
78
+ }
75
79
 
76
- info.push(`**一共检查${jsFiles.length}个js文件**`);
77
- info.push("| 类型 | 数量 |");
78
- info.push("| ----- | ------ |");
80
+ info.push("# 异常报表");
81
+ info.push("| 异常类型 | 数量 |");
82
+ info.push("| ------ | ------ |");
79
83
  info.push(`| 语法异常文件数 | ${errList.length}个 |`);
80
84
  if (notUtf8List.length > 0) info.push(`| 非utf8文件数 | ${notUtf8List.length}个 |`);
85
+ if (bigList.length > 0) info.push(`| 超过${fileSize}kb的文件数 | ${bigList.length}个 |`);
81
86
 
82
87
 
88
+ var detail = [];
83
89
  if (errList.length > 0) {
84
- info.push("");
85
- info.push('**语法异常文件清单如下**');
90
+ detail.push("");
91
+ detail.push('# 语法异常文件清单如下');
86
92
  errList.forEach((s, index) => {
87
93
 
88
- info.push(`# ${s}`);
94
+ detail.push(`## ${index + 1}. ${s}`);
89
95
 
90
96
  var err = errRegList[index];
91
- info.push("| 异常字符 | 位置 |");
92
- info.push("| ----- | ------ |");
97
+ detail.push("| 异常字符 | 位置 |");
98
+ detail.push("| ----- | ------ |");
93
99
  err.list.forEach((item) => {
94
- info.push(`| ${item.char} | ${item.index} |`);
100
+ detail.push(`| ${item.char} | ${item.index} |`);
95
101
  });
96
102
  });
97
103
  }
98
104
 
99
105
  if (notUtf8List.length > 0) {
100
- info.push("");
101
- info.push('**非utf8文件清单如下**');
106
+ detail.push("");
107
+ detail.push('# 非utf8文件清单如下');
102
108
  notUtf8List.forEach((s, index) => {
103
- info.push(`# ${s}`);
109
+ detail.push(`## ${index + 1}. ${s}`);
104
110
  });
105
111
  }
106
112
 
107
113
  if (bigList.length > 0) {
108
- info.push("");
109
- info.push(`**超过${fileSize}kb的文件清单如下**`);
114
+ detail.push("");
115
+ detail.push(`# 超过${fileSize}kb的文件清单如下`);
110
116
  bigList.forEach((s, index) => {
111
- info.push(`# ${s}`);
117
+ detail.push(`## ${index + 1}. ${s}`);
112
118
  });
113
119
  }
114
120
 
115
- //console.log(info.join('\r\n'));
116
-
117
- if (!config.webhooks) {
118
- config.log("::: craba.js里面配置config.webhooks,用于语法检测报告推送地址");
119
- return;
120
- }
121
+ //console.log(detail.join('\r\n'));
122
+ var id = modName + '_' + new Date().getTime();
123
+ var content = info.concat(detail).join(' \n');
124
+ console.log(content);
121
125
 
122
126
  var data = {
123
127
  "msgtype": "markdown",
124
128
  "markdown": {
125
- "title": "代码检测报告",
126
- "text": info.join(' \n')
129
+ "title": modName + " 代码检测报告",
130
+ "id": id,
131
+ "text": content
127
132
  }
128
133
  };
129
- console.log(info.join(' \n'));
130
- //data.markdown.text = data.markdown.text.replaceAll('\\n', '\n');
131
- //console.log(data);
134
+
135
+ var reportUrl = "";
136
+ console.log(config.reportHost);
137
+ if (config.reportHost) {
138
+ axios({
139
+ method: 'post',
140
+ url: config.reportHost + '/apis/saveJsReport',
141
+ data: data,
142
+ headers: { 'Content-Type': 'application/json' }
143
+ }).then(function(response) {
144
+ console.log("保存代码检测状态");
145
+ //console.log(response.data);
146
+ }).catch(function(error) {
147
+ console.log("保存代码检测失败");
148
+ //console.log(error);
149
+ });
150
+ reportUrl = config.reportHost + "/index.html#%2FPages%2FReport%2FJsReport.gspx?id=" + id;
151
+ }
152
+
153
+ console.log(reportUrl);
154
+ //utils.openProcess(reportUrl);
155
+
156
+ //return;
157
+ if (!config.webhooks) {
158
+ config.log("::: craba.js里面配置config.webhooks,用于语法检测报告推送地址");
159
+ return;
160
+ }
161
+
162
+ // 推送到钉钉只推送详情
163
+ info.push(`[报告详情](${reportUrl})`);
164
+ data.markdown.text = info.join(' \n');
132
165
 
133
166
  axios({
134
167
  method: 'post',