crabatool 1.0.118 → 1.0.126

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/lib/utils.js CHANGED
@@ -54,6 +54,25 @@ class Utils {
54
54
  return "";
55
55
  }
56
56
 
57
+ searchRootFolter(name, source) {
58
+ if (!path.basename(source)) return null;
59
+ if (fs.existsSync(source)) {
60
+ var files = fs.readdirSync(source);
61
+ //console.log(files);
62
+ for (var i = 0; i < files.length; i++) {
63
+ var fileName = files[i];
64
+ var filePath = utils.join(source, fileName);
65
+ //console.log(filePath);
66
+ var stat = fs.statSync(filePath);
67
+ if (stat.isDirectory()) {
68
+ var basename = path.basename(fileName);
69
+ if (basename == name) return filePath;
70
+ }
71
+ }
72
+ }
73
+ return utils.searchRootFolter(name, utils.join(source, '../'));
74
+ }
75
+
57
76
  format() {
58
77
  // 字符串参数化
59
78
  var args = new Array(arguments.length);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.118",
3
+ "version": "1.0.126",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -40,4 +40,4 @@
40
40
  ],
41
41
  "license": "UNLICENSED",
42
42
  "devDependencies": {}
43
- }
43
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "env": {
3
+ "browser": true
4
+ },
5
+ "extends": [
6
+ "eslint:recommended",
7
+ "plugin:native-ie/ie11",
8
+ "plugin:native-ie/ie10"
9
+ ],
10
+ "parserOptions": {
11
+ "ecmaVersion": "latest",
12
+ "sourceType": "script"
13
+ },
14
+ "rules": {
15
+ "semi": "off",
16
+ "no-redeclare": "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
+ "$Dom": "readonly",
36
+ "$export": "readonly",
37
+ "$skin": "readonly",
38
+ "$step": "readonly",
39
+ "$ms": "readonly",
40
+ "$createDelegate": "readonly",
41
+ "$createControl": "readonly",
42
+ "$uploader": "readonly",
43
+ "$debug": "readonly",
44
+ "$skinUtils": "readonly",
45
+ "$scriptLoader": "readonly",
46
+ "$Message": "readonly",
47
+ "$removeNode": "readonly",
48
+ "$get": "readonly",
49
+ "$agency": "readonly",
50
+ "$createControlFromGspx": "readonly",
51
+ "handleError": "readonly",
52
+ "$jsLoader": "readonly",
53
+ "$create": "readonly",
54
+ "$addHandler": "readonly",
55
+ "$searchUtils": "readonly",
56
+ "$crabaJSON": "readonly",
57
+ "asyncCall": "readonly",
58
+ "$clearHandlers": "readonly",
59
+ "$removeHandler": "readonly",
60
+ "getClientBounds": "readonly",
61
+ "echarts": "readonly",
62
+ "SysConsts": "readonly",
63
+ "math": "readonly",
64
+ "createIterator": "readonly"
65
+ }
66
+ }
package/test/test.js CHANGED
@@ -9,10 +9,11 @@ var crabaTool = require('../index.js'); // 引入craba脚手架工具包
9
9
  var config = {
10
10
  //【必填】
11
11
  // 告诉工具当前项目的端路径地址,填绝对路径哦
12
- webPath: "F:\\jxc\\jxc-web\\src\\main\\resources\\static\\jxc",
12
+ //webPath: "F:\\jxc\\jxc-web\\src\\main\\resources\\static\\jxc",
13
13
  //webPath: "F:/shell_master/web/src/main/resources/static/shell",
14
14
  //webPath: "F:\\newcrabadoc\\www",
15
15
  //webPath: "F:\\CarpaNET_NEW\\src\\Carpa.Web\\js\\",
16
+ webPath: "F:/crabaevery/www",
16
17
 
17
18
  //【必填】
18
19
  // 告诉工具当前项目前端服务器端口地址
@@ -20,7 +21,7 @@ var config = {
20
21
 
21
22
  //【ngp必填】【非ngp项目不是必填】
22
23
  // 当前项目模块名称,各组按需修改
23
- modName: "jxc", // 如:modName:"jxc"
24
+ modName: "shell", // 如:modName:"jxc"
24
25
 
25
26
  defaultPage: 'index.html',
26
27
 
@@ -32,7 +33,7 @@ var config = {
32
33
  // 1. 当前模块是由哪些过去的模块合并来的,各组按需修改
33
34
  // 2. 如果配置了子模块清单,工具会自动将所有子模块下的init.js和当前模块的jxc/js/jxc.js,合并打包到:jxc/js/init.js,实际运行过程中只加载:jxc/js/init.js,不会加载子模块下面的init.js,这样就可以大大减少http请求
34
35
  // 3. 同2,biz.js也是相同思路进行合并打包
35
- childModList: ['recordsheet', 'baseinfo', 'accounting', 'analysiscloud', 'finance'],
36
+ //childModList: ['recordsheet', 'baseinfo', 'accounting', 'analysiscloud', 'finance'],
36
37
 
37
38
  // 【不是必填】
38
39
  // 上一步中打包后的文件是否压缩, true为忽略【不压缩】,false为【要压缩】,各组按需修改
@@ -47,7 +48,16 @@ var config = {
47
48
  globals: ['crabadoc', 'Type', 'CrabaMarkdown', '$doc', 'www', 'crabaJs'],
48
49
 
49
50
  // 告诉助手项目有哪些js忽略语法检查,可以填目录
50
- ignoreCheck: ['js/lib/highlight.min.js', 'js/lib/markdown-it.min.js', 'Pages/Component.min.js'],
51
+ ignoreCheck: [
52
+ 'js/lib/highlight.min.js',
53
+ 'js/lib/markdown-it.min.js',
54
+ 'Pages/Component.min.js',
55
+ '/js/es6-promise.auto.min.js',
56
+ 'iconfont/iconfont.js',
57
+ 'biconfont/iconfont.js',
58
+ 'ueditor',
59
+ 'js'
60
+ ],
51
61
 
52
62
  // 配置js语法检测报告推送地址
53
63
  webhooks: ''
package/tool/checkjs.js CHANGED
@@ -153,6 +153,7 @@ module.exports.start = async function() {
153
153
  status = '有异常';
154
154
  }
155
155
 
156
+ var branchName = getBranchName();
156
157
  var modName = getModName();
157
158
  var id = modName + '_' + new Date().getTime();
158
159
  var webhookList = [];
@@ -169,21 +170,22 @@ module.exports.start = async function() {
169
170
  info.push(`| 平台日期 | ${localVersion.date} |`);
170
171
  }
171
172
  info.push(`| 生成报告时间 | ${new Date().toString()} |`);
173
+ info.push(`| 分支名 | ${branchName} |`);
172
174
  info.push(`| 网站路径 | ${config.webPath} |`);
173
175
  info.push(`| 共检查 | ${jsFiles.length}个js文件 |`);
174
176
  info.push(`| 共检查 | ${gspxData.count}个gspx文件 |`);
175
177
  info.push(`| 忽略目录和文件 | ${config.ignoreCheck ? config.ignoreCheck.join('、') : '无' + ' |'}`);
176
178
 
177
179
  info.push("# 检测结果汇总");
178
- info.push("| 类型 | 数量 |");
179
- info.push("| ------ | ------ |");
180
- info.push(`| 语法异常文件数Error | ${errKeys.length}个 |`);
181
- info.push(`| 语法警告文件数Warn | ${warnKeys.length}个 |`);
182
- info.push(`| 语法提示文件数Info | ${warnKeys.length}个 |`);
183
- info.push(`| 非utf8文件数 | ${notUtf8List.length}个 |`);
184
- info.push(`| 超过${fileSize}kb的文件数 | ${bigList.length}个 |`);
185
- info.push(`| gspx建议优化数 | ${warnGspxCount}个 |`);
186
- info.push(`| gspx语法错误数 | ${gspxData.errorList.length}个 |`);
180
+ info.push("| 类型 | 数量 | 占比 |");
181
+ info.push("| ------ | ------ | ----- |");
182
+ info.push(`| 语法异常文件数Error | ${errKeys.length}个 |${calc(errKeys.length, jsFiles.length)}|`);
183
+ info.push(`| 语法警告文件数Warn | ${warnKeys.length}个 |${calc(warnKeys.length, jsFiles.length)}|`);
184
+ info.push(`| 语法提示文件数Info | ${infoKeys.length}个 |${calc(infoKeys.length, jsFiles.length)}|`);
185
+ info.push(`| 非utf8文件数 | ${notUtf8List.length}个 |${calc(notUtf8List.length, jsFiles.length)}|`);
186
+ info.push(`| 超过${fileSize}kb的文件数 | ${bigList.length}个 |${calc(bigList.length, jsFiles.length)}|`);
187
+ info.push(`| gspx建议优化数 | ${warnGspxCount}个 |${calc(warnGspxCount, gspxData.count)}|`);
188
+ info.push(`| gspx语法错误数 | ${gspxData.errorList.length}个 |${calc(gspxData.errorList.length, gspxData.count)}|`);
187
189
 
188
190
 
189
191
  webhookList.push(`1. 助手版本: ${config.Version} `);
@@ -191,12 +193,13 @@ module.exports.start = async function() {
191
193
  webhookList.push(`1. 平台版本:${localVersion.version}`);
192
194
  webhookList.push(`1. 平台日期:${localVersion.date}`);
193
195
  }
196
+ webhookList.push(`1. 分支名:${branchName}`);
194
197
  webhookList.push(`1. 共检测 ${jsFiles.length}个 js文件 `);
195
198
  webhookList.push(`1. 共检测 ${gspxData.count}个 gspx文件 `);
196
199
 
197
200
  // 输出到钉钉的简易报告
198
201
  //if (errKeys.length > 0) {
199
- webhookList.push(`1. 语法异常文件数Error:${errKeys.length}个`);
202
+ webhookList.push(`1. 语法异常文件数Error:${errKeys.length}个,占比${calc(errKeys.length, jsFiles.length)}`);
200
203
 
201
204
  // 随机显示5个异常文件到钉钉消息
202
205
  var errCount = errKeys.length;
@@ -209,7 +212,7 @@ module.exports.start = async function() {
209
212
  list0.push(fileName);
210
213
  }
211
214
 
212
- webhookList.push(`1. 语法异常文件清单随机5个 \r\n${list0.join('; \r\n')}`);
215
+ webhookList.push(`1. 随机显示部分异常文件清单 \r\n${list0.join('; \r\n')}`);
213
216
  var reportUrl1 = getReportUrl(id, 2);
214
217
  if (reportUrl1) {
215
218
  webhookList.push(`[更多异常...](${reportUrl1})`);
@@ -218,20 +221,20 @@ module.exports.start = async function() {
218
221
 
219
222
  //}
220
223
  //if (warnKeys.length > 0) {
221
- webhookList.push(`7. 语法警告文件数Warn:${warnKeys.length}个`);
224
+ webhookList.push(`7. 语法警告文件数Warn:${warnKeys.length}个,占比${calc(warnKeys.length, jsFiles.length)}`);
222
225
  //}
223
- webhookList.push(`8. 语法提示文件数Info:${infoKeys.length}个`);
226
+ webhookList.push(`8. 语法提示文件数Info:${infoKeys.length}个,占比${calc(infoKeys.length, jsFiles.length)}`);
224
227
  if (notUtf8List.length > 0) {
225
- webhookList.push(`1. 非utf8文件数:${notUtf8List.length}个`);
228
+ webhookList.push(`1. 非utf8文件数:${notUtf8List.length}个,占比${calc(notUtf8List.length, jsFiles.length)}`);
226
229
  }
227
230
  if (bigList.length > 0) {
228
- webhookList.push(`1. 超过${fileSize}kb的文件数:${bigList.length}个`);
231
+ webhookList.push(`1. 超过${fileSize}kb的文件数:${bigList.length}个,占比${calc(bigList.length, jsFiles.length)}`);
229
232
  }
230
233
  //if (warnGspxCount > 0) {
231
- webhookList.push(`9. gspx建议优化数:${warnGspxCount}个`);
234
+ webhookList.push(`9. gspx建议优化数:${warnGspxCount}个,占比${calc(warnGspxCount, gspxData.count)}`);
232
235
  //}
233
236
  if (gspxData.errorList.length > 0) {
234
- webhookList.push(`10. gspx语法错误数:${gspxData.errorList.length}个`);
237
+ webhookList.push(`10. gspx语法错误数:${gspxData.errorList.length}个,占比${calc(gspxData.errorList.length, gspxData.count)}`);
235
238
  }
236
239
 
237
240
  // 代码质量管理需要格式
@@ -385,6 +388,10 @@ async function eslintCheck(content) {
385
388
  return res;
386
389
  }
387
390
 
391
+ function calc(a, b) {
392
+ return Math.ceil(a / b * 100) + '%';
393
+ }
394
+
388
395
  function getMathReuslts(content, nreg, filterFun) {
389
396
  var all = content.matchAll(nreg);
390
397
  var list = [];
@@ -427,6 +434,10 @@ function getReportUrl(id, anchor) {
427
434
  return href;
428
435
  }
429
436
 
437
+ function getBranchName() {
438
+ return config.branchName || 'null'
439
+ }
440
+
430
441
  function getModName() {
431
442
  return config.modName || 'noname';
432
443
  }
package/tool/start.js CHANGED
@@ -84,6 +84,7 @@ class Start {
84
84
  bindConfigByArgv('-ignoreCompress', 'boolean');
85
85
  bindConfigByArgv('-Debug', 'boolean');
86
86
  bindConfigByArgv('-checkgspx', 'boolean');
87
+ //bindConfigByArgv('-branchName');
87
88
  }
88
89
 
89
90
  checkPath() {
@@ -106,6 +107,8 @@ class Start {
106
107
  throw new Error(`请检查craba.js,配置的webPath路径不存在,支持相对路径,路径中用\\双斜杠或单反斜杠/;请检查拼写是否正确:${config.webPath}`);;
107
108
  }
108
109
 
110
+ bindBranchName();
111
+
109
112
  start.checkCraba();
110
113
  }
111
114
 
@@ -188,6 +191,38 @@ var start = new Start();
188
191
  module.exports = start;
189
192
 
190
193
 
194
+ function bindBranchName() {
195
+ var gitPath = utils.searchRootFolter('.git', config.webPath);
196
+ if (!gitPath) return;
197
+ var headPath = utils.join(gitPath, 'HEAD');
198
+ if (!fs.existsSync(headPath)) return;
199
+
200
+ // 读取Head文件内容
201
+ var headStr = fs.readFileSync(headPath).toString().trim();
202
+ var arr = headStr.split('/');
203
+
204
+ // 情况1:取到分支名包含斜杠
205
+ if (arr.length > 1) {
206
+ config.branchName = arr[arr.length - 1]; // 分支名称
207
+ return;
208
+ }
209
+
210
+ // 情况2:取到hash值
211
+
212
+ headPath = utils.join(gitPath, 'FETCH_HEAD');
213
+ if (!fs.existsSync(headPath)) return;
214
+
215
+ // 读取Head文件内容
216
+ var content = fs.readFileSync(headPath).toString().trim();
217
+ arr = content.split('\n');
218
+ var results = arr.filter(function(str) {
219
+ if (str.startsWith(headStr)) return true;
220
+ });
221
+
222
+ if (!results || results.length == 0) return;
223
+
224
+ config.branchName = results[0].split(' ')[1];
225
+ }
191
226
 
192
227
 
193
228
  /*内部私有方法*/