crabatool 1.0.280 → 1.0.282

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/hash.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "http://crabadoc.ca.com/js/utils/utils.js": "sha384-yqLsT1eKgMFhyGpdBnVBHom80H3rQ4iCLbg9kAmJ2zuJCF6oCxj1najJz5KPnRS/",
3
+ "F:/newcrabadoc/www/js/utils/utils.js": "sha384-yqLsT1eKgMFhyGpdBnVBHom80H3rQ4iCLbg9kAmJ2zuJCF6oCxj1najJz5KPnRS/",
4
+ "./test/test.js": "sha384-VQy3WyY/3vG+HckZphZEXGAZGOVP/NhqD8fx6wBjMPtfIaX5dUjMOxR+F23VhxAw",
5
+ "./test/beefun.js": "sha384-pkh4Pn8P8Bt2R3KEeN7N2WBZHd7xFWCD8fY2LuCdypHQv1DXLG538f1Jr+pCyJcM",
6
+ "https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js": "sha384-2Un6NCB1ePpHBqkNtvTjXtHbxHbwcNV/f72LUUSB7ysPpPkauvVsVTs61wW7cKq2"
7
+ }
package/index.js CHANGED
@@ -110,5 +110,13 @@ function checkFast(args) {
110
110
  }
111
111
 
112
112
 
113
+ if (args.includes('-makeHash')) {
114
+ start.bindAndCheckConfig('-files');
115
+ start.bindAndCheckConfig('-outJson');
116
+ require('./tool/hash.js').start(); // wps安全改造,工具生成js和css的hash值
117
+ return false;
118
+ }
119
+
120
+
113
121
  return true;
114
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.280",
3
+ "version": "1.0.282",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -16,7 +16,8 @@
16
16
  "checkUpdate": "node run.js -checkUpdate -version master -webPath F:\\crabaevery\\www",
17
17
  "upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F:\\CarpaNET_NEW",
18
18
  "crabaNgp": "node run.js -mergejs -hidejspath true -targetPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\js\\crabaNgp -inNames initMs.js,businessControl.js -outName F:\\CarpaMS\\src\\js\\crabaNgp.js",
19
- "webPath": "node ./test/test.js -checkjs -webhooks 0 -webPath F:\\crabaevery\\www -modName crabaevery"
19
+ "webPath": "node ./test/test.js -checkjs -webhooks 0 -webPath F:\\crabaevery\\www -modName crabaevery",
20
+ "makeHash": "node run.js -makeHash -files http://crabadoc.ca.com/js/utils/utils.js,F:/newcrabadoc/www/js/utils/utils.js,./test/test.js,./test/beefun.js,https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js?a=1 -outJson ./hash.json"
20
21
  },
21
22
  "author": "wssf",
22
23
  "dependencies": {
package/tool/checkjs.js CHANGED
@@ -158,6 +158,10 @@ module.exports.start = async function() {
158
158
  var errKeys = Object.keys(errDatas);
159
159
  var warnKeys = Object.keys(warnDatas);
160
160
  var infoKeys = Object.keys(infoDatas);
161
+ var reportData = {
162
+ projectName: getModName(),
163
+ branchName: getBranchName(),
164
+ }
161
165
  if (errKeys.length > 0 || warnKeys.length > 0 || notUtf8List.length > 0 || warnGspxCount > 0 || gspxData.errorList.length > 0) {
162
166
  status = '有异常';
163
167
  }
@@ -168,6 +172,8 @@ module.exports.start = async function() {
168
172
  var webhookList = [];
169
173
  var info = [];
170
174
  var localVersion = upgrade.getLocalVersion();
175
+ var generateDate = new Date().toString();
176
+ reportData.date = generateDate;
171
177
  info.push(`# ${modName}代码检测报告`);
172
178
  webhookList.push(info[0]);
173
179
 
@@ -178,7 +184,7 @@ module.exports.start = async function() {
178
184
  info.push(`| 平台版本 | ${localVersion.version} |`);
179
185
  info.push(`| 平台日期 | ${localVersion.date} |`);
180
186
  }
181
- info.push(`| 生成报告时间 | ${new Date().toString()} |`);
187
+ info.push(`| 生成报告时间 | ${generateDate} |`);
182
188
  info.push(`| 分支名 | ${branchName} |`);
183
189
  info.push(`| 检测主机 | ${utils.getHostName()}(${utils.getLocalIPs()}) |`);
184
190
  info.push(`| 网站路径 | ${config.webPath} |`);
@@ -206,6 +212,17 @@ module.exports.start = async function() {
206
212
  info.push(`| gspx页面异常数 | ${gspxData.errorList.length}个 |${calc(gspxData.errorList.length, gspxData.count)}|`);
207
213
  }
208
214
 
215
+ reportData.data = {
216
+ errorCount: errKeys.length,
217
+ warnCount: errKeys.length,
218
+ tipCount: errKeys.length,
219
+ fileSize: fileSize,
220
+ fileSizeCount: bigList.length,
221
+ gspxWarnCount: warnGspxCount.length,
222
+ gspxErrorCount: gspxData.errorList.length,
223
+ jsTotal: jsFiles.length,
224
+ gspxTotal: gspxData.count
225
+ }
209
226
 
210
227
  webhookList.push(`1. 助手版本:${config.Version} `);
211
228
  if (localVersion.version) {
@@ -380,6 +397,7 @@ module.exports.start = async function() {
380
397
  var reportUrl = getReportUrl(id);
381
398
  var content = info.concat(detail).join(' \r\n');
382
399
  postReport(id, reportUrl, content, sonar);
400
+ postReportData(reportData)
383
401
 
384
402
  // 推送到钉钉
385
403
  if (status != '无异常') { // 检查结果检查就不发到钉钉了; ps:健康也发到钉钉,鼓励开发继续保持;
@@ -588,4 +606,19 @@ function postWebhooks(id, reportUrl, webhookList) {
588
606
  //console.log(error);
589
607
  });
590
608
  }
609
+ }
610
+
611
+ function postReportData(data) {
612
+ axios({
613
+ method: 'post',
614
+ url: config.reportHost + '/apis/saveReportData',
615
+ data: data,
616
+ headers: { 'Content-Type': 'application/json' }
617
+ }).then(function(response) {
618
+ console.log("推送报告数据");
619
+ //console.log(response.data);
620
+ }).catch(function(error) {
621
+ console.log("推送报告数据:" + error.message);
622
+ //console.log(error);
623
+ });
591
624
  }
package/tool/hash.js ADDED
@@ -0,0 +1,54 @@
1
+
2
+ var config = require('../lib/config.js');
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var utils = require('../lib/utils.js');
6
+ var os = require('os');
7
+ const crypto = require('crypto');
8
+ var requestSync = require('sync-request');
9
+
10
+
11
+ module.exports.start = function() {
12
+ var hash = {};
13
+ var files = config.files.split(',');
14
+ files.forEach(function(f) {
15
+
16
+ console.log(f);
17
+ var content;
18
+ if (f.startsWith('http')) {
19
+ var res = requestSync("GET", f);
20
+ content = res.getBody();
21
+ } else if (fs.existsSync(f)) {
22
+ content = fs.readFileSync(f);
23
+ } else {
24
+ console.error('文件不存在:' + f);
25
+ return;
26
+ }
27
+
28
+ var index = f.indexOf('?');
29
+ if (index > 0) {
30
+ f = f.substr(0, index);
31
+ }
32
+
33
+ // SRI Hash Generator
34
+ // https://www.srihash.org/
35
+
36
+ var hex = sha384(content); // 将文件内容进行hash计算
37
+ hash[f] = 'sha384-' + hex; // 使用 base64 编码 sha384 算法计算出摘要后的 integrity 值的示例
38
+ });
39
+
40
+ utils.mkdirsSync(config.outJson);
41
+ fs.writeFileSync(config.outJson, JSON.stringify(hash));
42
+ }
43
+
44
+ function sha256(str) {
45
+ const hash = crypto.createHash('sha256');
46
+ hash.update(str);
47
+ return hash.digest('base64');
48
+ }
49
+
50
+ function sha384(str) {
51
+ const hash = crypto.createHash('sha384');
52
+ hash.update(str);
53
+ return hash.digest('base64');
54
+ }