crabatool 1.0.159 → 1.0.170

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/index.js CHANGED
@@ -45,9 +45,8 @@ function checkFast(args) {
45
45
  return false;
46
46
  }
47
47
 
48
- // crabatool -update -webPath 项目路径 -host 更新地址
48
+ // crabatool -update -webPath 项目路径 -version可选参数
49
49
  if (args.includes('-update')) {
50
- start.bindConfigByArgv('-host'); // 可选参数
51
50
  require('./tool/upgrade.js').updateCraba();
52
51
  return false;
53
52
  }
@@ -70,14 +69,22 @@ function checkFast(args) {
70
69
  return false;
71
70
  }
72
71
 
73
- // crabatool -upload -host 接收地址 -src 打包平台的父级路径
72
+ // crabatool -upload -host 接收地址 -webPath 平台源码根路径
74
73
  if (args.includes('-upload')) {
75
- start.bindAndCheckConfig('-host');
76
- start.bindAndCheckConfig('-src');
74
+ start.bindAndCheckConfig('-targetPath');
75
+ require('./tool/compress.js').run(); // 打包压缩js和css
77
76
  require('./tool/crabapublish.js').upload();
78
77
  return false;
79
78
  }
80
79
 
80
+ if (args.includes('-mergejs')) {
81
+ start.bindAndCheckConfig('-inNames');
82
+ start.bindAndCheckConfig('-outName');
83
+ start.bindAndCheckConfig('-targetPath');
84
+ require('./tool/compress.js').mergeJs(); // 打包压缩js和css
85
+ return false;
86
+ }
87
+
81
88
 
82
89
  return true;
83
90
  }
package/lib/config.js CHANGED
@@ -9,9 +9,11 @@ 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
+ this.hidejspath = false;
12
13
  this.ignoreCheck = [];
13
14
  this.Version = pg.version;
14
15
  this.Debug = false;
16
+ this.version = 'master';
15
17
  //this.SourceHost = "http://crabadoc.mygjp.com.cn";
16
18
  this.SourceHost = "http://crabadoc.ca.com";
17
19
  //this.SourceHost = "http://127.0.0.1:9998";
package/lib/server.js CHANGED
@@ -11,7 +11,7 @@ app.use(compression()); // 开启压缩
11
11
 
12
12
  // 自定义打包js
13
13
  if (config.modName && config.childModList && config.childModList.length > 0) {
14
- require('../tool/ngptool.js');
14
+ require('../tool/bizAndInit.js');
15
15
  }
16
16
 
17
17
  app.use(utils.redirectUrl);
package/lib/utils.js CHANGED
@@ -293,7 +293,9 @@ class Utils {
293
293
 
294
294
  // 递归创建目录
295
295
  mkdirsSync(dirname) {
296
- if (dirname.indexOf('.') > 0) dirname = path.dirname(dirname);
296
+ if (dirname.indexOf('.') > 0) {
297
+ dirname = path.dirname(dirname);
298
+ }
297
299
  if (fs.existsSync(dirname)) {
298
300
  return true;
299
301
  }
@@ -334,7 +336,9 @@ class Utils {
334
336
 
335
337
  log() {
336
338
  var args = [];
337
- if (config.Debug) args.push(`[${new Date().toString()}]`);
339
+ if (config.Debug) {
340
+ args.push(`[${new Date().toString()}]`);
341
+ }
338
342
  for (var i = 0, count = arguments.length; i < count; i++) {
339
343
  args.push(arguments[i]);
340
344
  }
@@ -360,6 +364,29 @@ class Utils {
360
364
  next();
361
365
  }
362
366
 
367
+ postWeebhooks(msg) {
368
+ var data = {
369
+ "msgtype": "markdown",
370
+ "markdown": {
371
+ "title": "Craba自动化",
372
+ "text": msg
373
+ }
374
+ };
375
+
376
+ axios({
377
+ method: 'post',
378
+ url: config.crabaHooks,
379
+ data: data,
380
+ headers: { 'Content-Type': 'application/json' }
381
+ }).then(function(response) {
382
+ //console.log("推送代码检测状态");
383
+ //console.log(response.data);
384
+ }).catch(function(error) {
385
+ //console.log("推送代码检测失败:" + error.message);
386
+ //console.log(error);
387
+ });
388
+ }
389
+
363
390
  rewriteCrabaJs(req, res, next) {
364
391
  var url = req.originalUrl;
365
392
  //utils.log(url);
@@ -478,8 +505,8 @@ class Utils {
478
505
  }
479
506
 
480
507
  // 解压zip
481
- unzip(zipPath, targetPath, cb) {
482
- compressing.zip.uncompress(zipPath, targetPath)
508
+ unzip(zipPath, targetPath, cb, opts) {
509
+ compressing.zip.uncompress(zipPath, targetPath, opts)
483
510
  .then(function done() {
484
511
  if (cb) cb(); // 解压完成
485
512
  })
@@ -488,12 +515,28 @@ class Utils {
488
515
  });
489
516
  }
490
517
 
518
+ zip(sourcePath, outName, cb, opts) {
519
+ compressing.zip.compressDir(sourcePath, outName, opts)
520
+ .then(function done() {
521
+ if (cb) cb(); // 解压完成
522
+ }).catch(function err() {
523
+ console.log(arguments);
524
+ });
525
+ }
526
+
491
527
  clearComment(content) {
492
528
  var reg1 = /\/\*(\n|.)*?\*\//ig; // 删除 /****/
493
529
  var reg2 = /\/{2,}.*?(\r|\n)/ig; // 删除 //
494
530
  return content.replace(reg1, '').replace(reg2, '');
495
531
  }
496
532
 
533
+ joinPath(p1, temp) {
534
+ if (!p1 || !temp) return temp;
535
+ var s = '';
536
+ if (!p1.endsWith('/') && !temp.startsWith('/')) s = '/';
537
+ return p1 + s + temp;
538
+ }
539
+
497
540
  downloadFile(uri, savePath, callback) {
498
541
  if (!uri || !savePath) throw new Error('uri或savePath不能为空');
499
542
 
@@ -570,6 +613,46 @@ class Utils {
570
613
 
571
614
  return ips.join(',');
572
615
  }
616
+
617
+ addPackageVersion(packagePath) {
618
+ if (!fs.existsSync(packagePath)) {
619
+ return false;
620
+ }
621
+
622
+ var pkg = require(packagePath);
623
+
624
+ var version = pkg.version;
625
+ if (!version) return false;
626
+
627
+ var vs = version.split('.');
628
+ if (vs.length < 3) return false;
629
+
630
+ vs[2] = parseInt(vs[2]) + 1;
631
+
632
+ if (vs[2] > 10000) {
633
+ vs[1] = parseInt(vs[1]) + 1;
634
+ vs[2] = 1;
635
+ }
636
+
637
+ var dt = new Date();
638
+ pkg.updateTime = dt.toString();
639
+
640
+ var versionOk = vs.join(".");
641
+ pkg.version = versionOk;
642
+ console.log("date:" + dt.toString() + "--old:" + version + "-----new:" + versionOk);
643
+
644
+ var content = JSON.stringify(pkg);
645
+ fs.writeFileSync(packagePath, content);
646
+ }
647
+
648
+ readPackage(packagePath) {
649
+ if (!fs.existsSync(packagePath)) {
650
+ return {};
651
+ }
652
+
653
+ var pkg = require(packagePath);
654
+ return pkg;
655
+ }
573
656
  }
574
657
  var utils = new Utils();
575
658
  module = module.exports = utils;
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.159",
3
+ "version": "1.0.170",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "crabatool": "./run.js"
8
8
  },
9
9
  "scripts": {
10
- "start": "node index.js",
10
+ "start": "node run.js",
11
11
  "test": "node ./test/test.js",
12
12
  "run": "node ./test/test.js -run",
13
13
  "checkjs": "node ./test/test.js -checkjs",
14
14
  "beefun": "node ./test/beefun.js -checkjs",
15
+ "upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F:\\CarpaNET_NEW",
16
+ "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",
15
17
  "webPath": "node ./test/test.js -checkjs -webhooks 0 -webPath F:\\newcrabadoc\\www -modName crabadoc -ignoreCheck ueditor,iconfont,biconfont,js\\math.min.js,js\\es6-promise.auto.min.js,js\\craba.rollup.min.js"
16
18
  },
17
19
  "author": "wssf",
@@ -34,7 +36,8 @@
34
36
  "single-line-log": "^1.1.2",
35
37
  "sync-request": "^6.1.0",
36
38
  "uglify-js": "^3.15.1",
37
- "xml-js": "^1.6.11"
39
+ "xml-js": "^1.6.11",
40
+ "uglifycss": "^0.0.29"
38
41
  },
39
42
  "repository": {
40
43
  "type": "git",
package/test/test.js CHANGED
@@ -9,11 +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",
13
- webPath: "F:/shell_master/web/src/main/resources/static/shell",
12
+ webPath: "F:\\jxc\\jxc-web\\src\\main\\resources\\static\\jxc",
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
+ //webPath: "F:/crabaevery/www",
17
17
 
18
18
  //【必填】
19
19
  // 告诉工具当前项目前端服务器端口地址
@@ -21,7 +21,7 @@ var config = {
21
21
 
22
22
  //【ngp必填】【非ngp项目不是必填】
23
23
  // 当前项目模块名称,各组按需修改
24
- modName: "shell", // 如:modName:"jxc"
24
+ modName: "jxc", // 如:modName:"jxc"
25
25
 
26
26
  defaultPage: 'index.html',
27
27
 
@@ -33,7 +33,7 @@ var config = {
33
33
  // 1. 当前模块是由哪些过去的模块合并来的,各组按需修改
34
34
  // 2. 如果配置了子模块清单,工具会自动将所有子模块下的init.js和当前模块的jxc/js/jxc.js,合并打包到:jxc/js/init.js,实际运行过程中只加载:jxc/js/init.js,不会加载子模块下面的init.js,这样就可以大大减少http请求
35
35
  // 3. 同2,biz.js也是相同思路进行合并打包
36
- //childModList: ['recordsheet', 'baseinfo', 'accounting', 'analysiscloud', 'finance'],
36
+ childModList: ['recordsheet', 'baseinfo', 'accounting', 'analysiscloud', 'finance'],
37
37
 
38
38
  // 【不是必填】
39
39
  // 上一步中打包后的文件是否压缩, true为忽略【不压缩】,false为【要压缩】,各组按需修改
@@ -1,12 +1,9 @@
1
1
  var config = require('../lib/config.js');
2
+ var fs = require('fs');
2
3
  var path = require('path');
3
4
  var chokidar = require('chokidar');
4
- var fs = require('fs');
5
- var fork = require('child_process').fork;
6
5
  var utils = require('../lib/utils.js');
7
-
8
- var mergeJs = utils.join(__dirname, 'merge.js');
9
- var compressArgs = config.ignoreCompress ? ['-ignorecompress'] : []; // 是否压缩
6
+ var mergeTool = require('./merge/mergeTool.js');
10
7
 
11
8
  // 打包biz.js
12
9
  function mergeBiz(childPath) {
@@ -16,16 +13,21 @@ function mergeBiz(childPath) {
16
13
  }
17
14
  utils.log('biz.js打包启动:' + bizPath);
18
15
 
19
-
20
-
21
16
  var watchAction = function() {
22
17
  utils.debug('打包中');
23
- // 这里进行文件更改后的操作
24
18
  var bizJs = utils.join(bizPath, '../', 'biz.js');
19
+ mergeTool.run({
20
+ inPath: bizPath,
21
+ outPath: bizJs,
22
+ ext: '.js',
23
+ ignoreCompress: config.ignorecompress
24
+ });
25
+ /*
25
26
  var p = fork(mergeJs, [`${[bizPath]}`, `${[bizJs]}`, compressArgs])
26
27
  p.on('exit', code => {
27
28
  utils.log('打包完成:' + bizJs);
28
29
  });
30
+ */
29
31
  }
30
32
 
31
33
  // 只打包的情况就不监视文件
@@ -41,6 +43,7 @@ function mergeBiz(childPath) {
41
43
  .on('change', path => watchAction({ event: 'change', eventPath: path }))
42
44
  .on('unlink', path => watchAction({ event: 'remove', eventPath: path }));
43
45
  }
46
+
44
47
  watchAction();// 启动就打包一次
45
48
  }
46
49
 
@@ -48,7 +51,7 @@ function mergeBiz(childPath) {
48
51
  function mergeInit() {
49
52
  var modJs = utils.join(config.webPath, '/js/' + config.modName + '.js'); // jxc/js/jxc.js
50
53
  if (!fs.existsSync(modJs)) {
51
- return utils.error(`error 模块对应的资源不存在:${modJs},已经取消打包功能。如需打包,请先将${config.modName}/js/init.js修改为:${config.modName}/js/${config.modName}.js`);
54
+ return utils.error(`error 模块对应的资源不存在:${modJs},已经取消打包init的功能。如需打包,请先将${config.modName}/js/init.js修改为:${config.modName}/js/${config.modName}.js`);
52
55
  }
53
56
 
54
57
  var inits = [];
@@ -56,12 +59,21 @@ function mergeInit() {
56
59
 
57
60
  var watchAction = function() {
58
61
  utils.debug('打包中');
59
- // 这里进行文件更改后的操作
60
62
  var initJs = utils.join(config.webPath, '/js/init.js');
63
+ utils.debug(inits);
64
+ mergeTool.run({
65
+ inPath: inits,
66
+ outPath: initJs,
67
+ ext: '.js',
68
+ ignoreCompress: config.ignorecompress
69
+ });
70
+ /*
71
+ // 这里进行文件更改后的操作
61
72
  var p = fork(mergeJs, [`${[inits]}`, `${[initJs]}`, compressArgs])
62
73
  p.on('exit', code => {
63
74
  utils.log('打包完成:' + initJs);
64
75
  });
76
+ */
65
77
  }
66
78
 
67
79
  var watchJs = function(jsPath) {
@@ -85,7 +97,6 @@ function mergeInit() {
85
97
  config.childModList.forEach(childName => {
86
98
  var childInitPath = utils.join(config.webPath, childName, 'js/init.js');
87
99
  inits.push(childInitPath);
88
- //utils.mkdirsSync(childInitPath);
89
100
  if (!fs.existsSync(childInitPath)) {
90
101
  utils.error('error 监听打包的资源不存在' + childInitPath);
91
102
  }
@@ -99,14 +110,14 @@ function mergeInit() {
99
110
  utils.log('启动打包服务', config.childModList);
100
111
  utils.mkdirsSync(config.webPath);
101
112
 
102
- // 打包当前模块的biz.js
103
- mergeBiz('/js/biz');
104
-
105
113
  // 打包子模块的biz.js
106
114
  config.childModList.forEach(childName => {
107
115
  var childBiz = utils.join(childName, 'js/biz');
108
116
  mergeBiz(childBiz);
109
117
  });
110
118
 
111
- // 打包模块的init.js
119
+ // 打包当前模块的biz.js
120
+ mergeBiz('/js/biz');
121
+
122
+ // 打包所有模块的init.js
112
123
  mergeInit(); // 如果有需要
package/tool/checkjs.js CHANGED
@@ -12,8 +12,10 @@ const upgrade = require('./upgrade.js');
12
12
 
13
13
  // js超过多少kb给与提示
14
14
  var fileSize = 300;
15
+
15
16
  // 默认忽略大小的文件
16
- 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'];
17
+ var blackList = ['agency.js', 'jquery.js', 'craba.min.js', 'crabaEx.min.js', 'crabaNgp.js', 'echarts-all.js', 'echarts.min.js', 'math.min.js', 'craba.rollup.min.js'];
18
+
17
19
  // 语法规则,不能包含这些关键词
18
20
  var dangerousJs = ['\\slet\\s', '\\sconst\\s', '\=\>\\s?\\(?\\{', '\\sasync\\s', '\\sawait\\s', '\\.then\\(', '\\sdebugger\\s'];// 'for\\s*\\(\\s*var\\s*\\w+\\s*in'];
19
21
 
@@ -192,11 +194,16 @@ module.exports.start = async function() {
192
194
  }
193
195
 
194
196
  info.push(`| 超过${fileSize}kb的文件数 | ${bigList.length}个 |${calc(bigList.length, jsFiles.length)}|`);
195
- info.push(`| gspx建议优化数 | ${warnGspxCount}个 |${calc(warnGspxCount, gspxData.count)}|`);
196
- info.push(`| gspx语法错误数 | ${gspxData.errorList.length}个 |${calc(gspxData.errorList.length, gspxData.count)}|`);
197
197
 
198
+ if (warnGspxCount > 0) {
199
+ info.push(`| gspx建议优化数 | ${warnGspxCount}个 |${calc(warnGspxCount, gspxData.count)}|`);
200
+ }
201
+ if (gspxData.errorList.length) {
202
+ info.push(`| gspx语法错误数 | ${gspxData.errorList.length}个 |${calc(gspxData.errorList.length, gspxData.count)}|`);
203
+ }
198
204
 
199
- webhookList.push(`1. 助手版本: ${config.Version} `);
205
+
206
+ webhookList.push(`1. 助手版本:${config.Version} `);
200
207
  if (localVersion.version) {
201
208
  webhookList.push(`1. 平台版本:${localVersion.version}`);
202
209
  webhookList.push(`1. 平台日期:${localVersion.date}`);
@@ -241,11 +248,11 @@ module.exports.start = async function() {
241
248
  if (bigList.length > 0) {
242
249
  webhookList.push(`1. 超过${fileSize}kb的文件数:${bigList.length}个,占比${calc(bigList.length, jsFiles.length)}`);
243
250
  }
244
- //if (warnGspxCount > 0) {
245
- webhookList.push(`9. gspx建议优化数:${warnGspxCount}个,占比${calc(warnGspxCount, gspxData.count)}`);
246
- //}
251
+ if (warnGspxCount > 0) {
252
+ webhookList.push(`1. gspx建议优化数:${warnGspxCount}个,占比${calc(warnGspxCount, gspxData.count)}`);
253
+ }
247
254
  if (gspxData.errorList.length > 0) {
248
- webhookList.push(`10. gspx语法错误数:${gspxData.errorList.length}个,占比${calc(gspxData.errorList.length, gspxData.count)}`);
255
+ webhookList.push(`1. gspx语法错误数:${gspxData.errorList.length}个,占比${calc(gspxData.errorList.length, gspxData.count)}`);
249
256
  }
250
257
 
251
258
  // 代码质量管理需要格式
@@ -408,6 +415,7 @@ async function eslintCheck(content) {
408
415
  }
409
416
 
410
417
  function calc(a, b) {
418
+ if (b <= 0) return '0%';
411
419
  return Math.ceil(a / b * 100) + '%';
412
420
  }
413
421
 
@@ -0,0 +1,149 @@
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 mergeTool = require('./merge/mergeTool.js');
7
+
8
+ var _jsPath = path.join(config.targetPath, 'src/Carpa.Web/js');
9
+ var _tempPath = path.join(config.targetPath, '__build');
10
+ var _zipName = path.join(config.targetPath, 'craba.zip');
11
+ var _tempJsPath = path.join(_tempPath, 'js');
12
+ var _tempSkinPath = path.join(_tempPath, 'skins');
13
+ var _pkgPath = path.join(_jsPath, 'package.json');
14
+ var _blackFilePath = path.join(__dirname, 'merge/black_fun_list.txt');
15
+
16
+ module.exports.run = function() {
17
+ console.log('环境变量:', process.env.REMOTE_BUILD);
18
+
19
+ if (fs.existsSync(_zipName)) {
20
+ fs.unlinkSync(_zipName);
21
+ }
22
+
23
+ if (process.env.REMOTE_BUILD == 'no') {
24
+ utils.addPackageVersion(_pkgPath); // 版本号+1
25
+ }
26
+
27
+ doCompress(); // 打包、压缩、合并js和css到临时目录下
28
+ }
29
+
30
+ module.exports.mergeJs = function() {
31
+ var inNames = config.inNames.split(',');
32
+ inNames = inNames.map((s) => {
33
+ return path.join(config.targetPath, s);
34
+ });
35
+ compressJs(inNames, config.outName);
36
+ }
37
+
38
+ function updateCrabaVersion() {
39
+ var pkg = utils.readPackage(_pkgPath);
40
+
41
+ var crabaJs = path.join(_tempJsPath, 'craba.min.js');
42
+ var content = fs.readFileSync(crabaJs);
43
+ if (content.indexOf('var crabaVersion =') < 0) {
44
+ var vString = '\r\nvar crabaVersion = "' + pkg.version + '";var crabaDate = "' + pkg.updateTime + '";console.log("版本:" + crabaVersion + " 日期:" + crabaDate);';
45
+ content = content + vString;
46
+ fs.writeFileSync(crabaJs, content, 'utf8');
47
+ }
48
+ }
49
+
50
+ function updateAgencyVersion() {
51
+ var pkg = utils.readPackage(_pkgPath);
52
+
53
+ crabaJs = path.join(_tempJsPath, 'agency.js');
54
+ content = fs.readFileSync(crabaJs);
55
+ if (content.indexOf('var agencyVersion=') < 0) {
56
+ vString = '\r\nvar agencyVersion="' + pkg.version + '";';
57
+ content = content + vString;
58
+ fs.writeFileSync(crabaJs, content, 'utf8');
59
+ }
60
+ }
61
+
62
+ function doCompress() {
63
+
64
+ var inNames = ['agency.js'];
65
+ compressCrabaJs(inNames, 'agency.js', null, updateAgencyVersion);
66
+
67
+ // craba.min.js
68
+ inNames = ['type.js', 'craba.js', 'common.js', 'es6.js', 'controls.js', 'required.js', 'listView.js', 'crabaEx.js', 'crabaFC.js', 'crabaMS.js'];
69
+ compressCrabaJs(inNames, 'craba.min.js', updateCrabaVersion);
70
+
71
+ // crabaEx.min.js
72
+ inNames = ['grid.js', 'controlsEx.js', 'treeView.js', 'print.js', 'workflow.js', '../../Carpa.Dress/Dress.js', 'htmlEditor.js'];
73
+ compressCrabaJs(inNames, 'crabaEx.min.js');
74
+
75
+ // echarts
76
+ inNames = ['echarts4-all.js'];
77
+ compressCrabaJs(inNames, 'echarts-all.js');
78
+
79
+ // math.min.js
80
+ utils.copyFile(path.join(_jsPath, '../jsBin/math.min.js'), path.join(_tempJsPath, 'math.min.js'));
81
+
82
+ // crabaNgp.js
83
+ inNames = ['crabaNgp/initMs.js', 'crabaNgp/businessControl.js'];
84
+ compressCrabaJs(inNames, 'crabaNgp.js');
85
+
86
+ //_Sys目录
87
+ utils.copyFiles(path.join(_jsPath, '_Sys'), path.join(_tempPath, '_Sys'));
88
+
89
+ // skins
90
+ var skinPath = path.join(config.targetPath, 'src/Carpa.Web/skins');
91
+ utils.copyFiles(path.join(skinPath, 'ui'), path.join(_tempSkinPath, 'ui'));
92
+ utils.copyFiles(path.join(skinPath, 'font'), path.join(_tempSkinPath, 'font'));
93
+
94
+ // craba.min.css
95
+ inNames = ['iconfont.css', 'craba.min.css'];
96
+ compressAndMergeCss(inNames, skinPath, 'craba.min.css');
97
+ }
98
+
99
+
100
+ function compressCrabaJs(inNames, outName, onEnd) {
101
+ inNames = inNames.map((s) => {
102
+ return path.join(_jsPath, s);
103
+ });
104
+
105
+ var targetJs = utils.join(_tempJsPath, outName);
106
+ compressJs(inNames, targetJs, onEnd)
107
+ }
108
+
109
+ function compressJs(inNames, targetJs, onEnd) {
110
+ mergeTool.run({
111
+ inPath: inNames,
112
+ outPath: targetJs,
113
+ ext: '.js',
114
+ ignoreCompress: config.ignorecompress,
115
+ blackFileName: _blackFilePath,
116
+ hidejspath: config.hidejspath
117
+ });
118
+
119
+ if (onEnd) onEnd();
120
+
121
+ /*
122
+ var p = fork(_mergeJsPath, [`${[inNames]}`, `${[targetJs]}`, _compressArgs, _blackFilePath, config.hidejspath]);
123
+ p.on('exit', () => {
124
+ utils.log('打包完成:' + targetJs);
125
+ if (onEnd) onEnd();
126
+ });
127
+ */
128
+ }
129
+
130
+ function compressAndMergeCss(inNames, rootPath, outName) {
131
+ inNames = inNames.map((s) => {
132
+ return path.join(rootPath, s);
133
+ });
134
+ var targetJs = utils.join(_tempSkinPath, outName);
135
+
136
+ mergeTool.run({
137
+ inPath: inNames,
138
+ outPath: targetJs,
139
+ ext: '.css',
140
+ hidejspath: config.hidejspath,
141
+ ignoreCompress: config.ignorecompress
142
+ });
143
+ /*
144
+ var p = fork(_mergeCssPath, [`${[inNames]}`, `${[targetJs]}`, _compressArgs]);
145
+ p.on('exit', () => {
146
+ utils.log('打包完成:' + targetJs);
147
+ });
148
+ */
149
+ }
@@ -2,13 +2,113 @@
2
2
  var config = require('../lib/config.js');
3
3
  var path = require('path');
4
4
  var fs = require('fs');
5
- var requestSync = require('sync-request');
6
5
  var utils = require('../lib/utils.js');
6
+ var axios = require('axios');
7
+ const FormData = require('form-data');
8
+
9
+ var _tempPath = path.join(config.targetPath, '__build');
10
+ var _zipName = path.join(config.targetPath, 'craba.zip');
11
+ var _jsPath = path.join(config.targetPath, 'src/Carpa.Web/js');
12
+ var _pkgPath = path.join(_jsPath, 'package.json');
7
13
 
8
14
  module.exports.upload = function() {
15
+ doUploadPkg(); // 先上传package版本信息文件,然后上传craba.zip资源包,再然后调用自动化测试
16
+ }
17
+
18
+ function doUploadPkg() {
19
+ var version = config.version || 'master'; // 默认临时目录下
20
+ var host = config.host || config.SourceHost;
21
+ var apis = utils.joinPath(host, '/apis/publish/save');
22
+
23
+ if (process.env.REMOTE_BUILD == 'no') {
24
+ version += '_temp';
25
+ }
26
+
27
+ const formData = new FormData();
28
+ formData.append('my_field', 'my value');
29
+ formData.append('my_file', fs.createReadStream(_pkgPath));
30
+ var headers = formData.getHeaders();
31
+
32
+ axios({
33
+ method: 'POST',
34
+ url: apis,
35
+ data: formData,
36
+ headers: {
37
+ ...headers,
38
+ version: version,
39
+ token: 'wssf2021' // 临时授权码
40
+ }
41
+ }).then(function(response) {
42
+ console.log(response.data);
43
+ doZipCraba();
44
+ }).catch(function(err) {
45
+ console.log(err);
46
+ });
47
+ }
48
+
49
+ function doZipCraba() {
50
+ // 将demo文件一起打包
51
+ utils.copyFiles(path.join(_jsPath, 'demo'), _tempPath);
52
+
53
+ // 打包平台资源
54
+ utils.zip(_tempPath, _zipName, function() {
55
+ console.log('压缩完成');
56
+ doUploadCraba(); // 根据配置上传到服务端指定路径(分支)下
57
+ }, { ignoreBase: true }); // 忽略跟路径
58
+ }
59
+
60
+ function doUploadCraba() {
61
+ console.log('上传资源');
62
+ var version = config.version || 'master'; // 默认临时目录下
63
+ var host = config.host || config.SourceHost;
64
+ var apis = utils.joinPath(host, '/apis/publish/save');
65
+
66
+ if (process.env.REMOTE_BUILD == 'no') {
67
+ version += '_temp';
68
+ }
69
+
70
+ console.log(apis);
71
+
72
+ const formData = new FormData();
73
+ formData.append('my_field', 'my value');
74
+ formData.append('my_file', fs.createReadStream(_zipName));
75
+ var headers = formData.getHeaders();
9
76
 
77
+ utils.postWeebhooks(config.modName + '打包完成,上传资源到:' + version);
78
+
79
+ axios({
80
+ method: 'POST',
81
+ url: apis,
82
+ data: formData,
83
+ headers: {
84
+ ...headers,
85
+ version: version,
86
+ token: 'wssf2021' // 临时授权码
87
+ }
88
+ }).then(function(response) {
89
+ console.log(response.data);
90
+ doAutoTest();
91
+ }).catch(function(err) {
92
+ utils.postWeebhooks(config.modName + '上传资源失败');
93
+ console.log(err);
94
+ });
10
95
  }
11
96
 
12
- module.exports.download = function() {
13
-
97
+ function doAutoTest() {
98
+ if (process.env.REMOTE_BUILD != 'no') {
99
+ return;
100
+ }
101
+
102
+ utils.postWeebhooks(config.modName + '上传资源成功,开始调用自动化测试');
103
+
104
+ var url = 'http://jci.ca.com/job/craba-uitest/buildWithParameters?token=remoteBuild&remoteBuild=yes';
105
+ axios({
106
+ method: 'GET',
107
+ url: url
108
+ }).then(function(response) {
109
+
110
+ }).catch(function(err) {
111
+ utils.postWeebhooks('调用自动化测试失败');
112
+ console.log(err);
113
+ });
14
114
  }