crabatool 1.0.448 → 1.0.449

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
@@ -194,6 +194,16 @@ async function checkFast(args) {
194
194
  return false;
195
195
  }
196
196
 
197
+ if (args.includes('-mergeFiles')) { // 将特定文件压缩后,路径作为key,合并到一个json文件包,减少http请求
198
+ start.bindAndCheckConfig('-inNames');
199
+ start.bindAndCheckConfig('-outName');
200
+ start.bindConfigByArgv('-targetPath');
201
+ start.bindConfigByArgv('-exp');
202
+ config.mergeFile = true;
203
+ require('./tool/compress.js').mergeFiles(); // 打包压缩js和css
204
+ return false;
205
+ }
206
+
197
207
  if (args.includes('-mergejs')) {
198
208
  start.bindAndCheckConfig('-inNames');
199
209
  start.bindAndCheckConfig('-outName');
@@ -206,7 +216,7 @@ async function checkFast(args) {
206
216
  if (args.includes('-mergecss')) {
207
217
  start.bindAndCheckConfig('-inNames');
208
218
  start.bindAndCheckConfig('-outName');
209
- start.bindAndCheckConfig('-targetPath');
219
+ start.bindConfigByArgv('-targetPath');
210
220
  start.bindConfigByArgv('-exp');
211
221
  require('./tool/compress.js').mergeCss(); // 打包压缩js和css
212
222
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.448",
3
+ "version": "1.0.449",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,6 +13,7 @@
13
13
  "mergeinitjs": "node ./test/test.js -mergeinitjs",
14
14
  "export": "node ./test/test.js -exportgspx -webPath F:\\Beefun\\srcs",
15
15
  "checkjs": "node ./test/test.js -checkjs",
16
+ "mergeFiles": "node ./test/test.js -mergeFiles -modName shell -webPath F:\\shell-gerrit\\web\\src\\main\\resources\\static\\shell\\ -targetPath F:\\shell-gerrit\\web\\src\\main\\resources\\static\\shell\\ -inNames js\\crabaNgp.js,skins\\craba.min.css,skins\\blueSky\\skin.css,skins\\shell.css,pages\\RetailHome.gspx,pages\\RetailHome.js,basics\\Company.gspx,basics\\Company.js,basics\\PicUploadForm.gspx,basics\\PicUploadForm.js,js\\innerNotice.js,Main.gspx,Main.js,js\\init.js,js\\timingCollector.js,js\\help.plug.js -outName F:\\shell-gerrit\\web\\src\\main\\resources\\static\\shell\\shell.res.js",
16
17
  "checkiconfont": "node ./test/test.js -checkiconfont -webPath F:\\crabaevery\\www -modName crabaevery -reportHost http://127.0.0.1:9998 -ignoreFiles biconfont\\iconfont.js,iconfont\\iconfont.js -cssFiles skins\\retail\\skin.css",
17
18
  "checkiconfontBf": "node ./test/test.js -checkiconfont -webPath F:\\Beefun\\srcs -modName beefun -reportHost http://127.0.0.1:9998 -ignoreFiles biconfont\\iconfont.js,iconfont\\iconfont.js",
18
19
  "checkiconfontCraba": "node ./test/test.js -checkiconfont -webPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\js -modName craba -reportHost http://127.0.0.1:9998 -ignoreFiles biconfont\\iconfont.js,iconfont\\iconfont.js -cssFiles ../skins/craba.min.css",
@@ -69,7 +70,8 @@
69
70
  "sync-request": "^6.1.0",
70
71
  "uglify-js": "^3.15.1",
71
72
  "uglifycss": "^0.0.29",
72
- "xml-js": "^1.6.11"
73
+ "xml-js": "^1.6.11",
74
+ "xml-minifier": "^1.0.1"
73
75
  },
74
76
  "repository": {
75
77
  "type": "git",
package/tool/compress.js CHANGED
@@ -34,6 +34,14 @@ module.exports.run = function() {
34
34
  doCompress(); // 打包、压缩、合并js和css到临时目录下
35
35
  }
36
36
 
37
+ module.exports.mergeFiles = function() {
38
+ var inNames = config.inNames.split(',');
39
+ inNames = inNames.map((s) => {
40
+ return path.join(config.targetPath, s);
41
+ });
42
+ compressFiles(inNames, config.outName);
43
+ }
44
+
37
45
  module.exports.mergeJs = function() {
38
46
  var inNames = config.inNames.split(',');
39
47
  inNames = inNames.map((s) => {
@@ -50,7 +58,6 @@ module.exports.mergeCss = function() {
50
58
  compressCss(inNames, config.outName);
51
59
  }
52
60
 
53
-
54
61
  function updateCrabaVersion() {
55
62
  var pkg = utils.readPackage(_pkgPath);
56
63
 
@@ -148,13 +155,39 @@ function compressCrabaJs(inNames, outName, onEnd) {
148
155
  compressJs(inNames, targetJs, onEnd)
149
156
  }
150
157
 
158
+ function compressFiles(inNames, outName) {
159
+ console.log('compressFiles开始,打包文件数:', inNames.length);
160
+ config.hidejspath = true;
161
+ config.ignoreCompress = false;
162
+
163
+ var json = {};
164
+ inNames.forEach(function(filePath) {
165
+ var path2 = filePath.replace(config.webPath, '');
166
+ path2 = path.join(config.modName, path2).replaceAll('\\', '/');
167
+ var ext = path.extname(filePath).toLowerCase();
168
+ var content = '';
169
+ if (ext == '.js') {
170
+ content = compressJs(filePath);
171
+ } else if (ext == '.css') {
172
+ content = compressCss(filePath);
173
+ } else if (ext == '.gspx') {
174
+ content = compressGspx(filePath);
175
+ }
176
+ json[path2] = content;
177
+ });
178
+
179
+ utils.mkdirsSync(outName);
180
+ fs.writeFileSync(outName, `$app.addRes(${JSON.stringify(json)},'${config.modName}')`);
181
+ console.log('compressFiles完成,资源包路径:', outName);
182
+ }
183
+
151
184
  function compressJs(inNames, targetJs, onEnd) {
152
- mergeTool.run({
185
+ var content = mergeTool.run({
153
186
  inPath: inNames,
154
187
  outPath: targetJs,
155
188
  ext: '.js',
156
189
  ignoreCompress: config.ignoreCompress,
157
- blackFileName: _blackFilePath,
190
+ blackFileName: targetJs ? _blackFilePath : null,
158
191
  hidejspath: config.hidejspath
159
192
  });
160
193
 
@@ -165,6 +198,7 @@ function compressJs(inNames, targetJs, onEnd) {
165
198
  console.log('compress完成', inNames, targetJs);
166
199
  console.log('\r\n');
167
200
 
201
+ return content;
168
202
  /*
169
203
  var p = fork(_mergeJsPath, [`${[inNames]}`, `${[targetJs]}`, _compressArgs, _blackFilePath, config.hidejspath]);
170
204
  p.on('exit', () => {
@@ -190,7 +224,7 @@ function compressAndMergeCss(inNames, rootPath, outName) {
190
224
  }
191
225
 
192
226
  function compressCss(inNames, targetCss) {
193
- mergeTool.run({
227
+ var content = mergeTool.run({
194
228
  inPath: inNames,
195
229
  outPath: targetCss,
196
230
  ext: '.css',
@@ -200,5 +234,12 @@ function compressCss(inNames, targetCss) {
200
234
 
201
235
  console.log('compress完成', inNames, targetCss);
202
236
  console.log('\r\n');
237
+ return content;
238
+ }
203
239
 
240
+ function compressGspx(filePath) {
241
+ const xmlMinifier = require('xml-minifier');
242
+ let xml = fs.readFileSync(filePath, 'utf8');
243
+ let minified = xmlMinifier.minify(xml);
244
+ return minified;
204
245
  }
@@ -26,7 +26,7 @@ var config = require('../../lib/config.js');
26
26
  var __cachePath = path.join(os.tmpdir(), '__crabatoolcache', config.version);
27
27
 
28
28
  module.exports.run = function(opts) {
29
- if (!opts.inPath || !opts.outPath) {
29
+ if (!opts.inPath) {
30
30
  throw ("args参数不能为空");
31
31
  }
32
32
 
@@ -44,7 +44,7 @@ module.exports.run = function(opts) {
44
44
  utils.log("blackFileName:" + options.blackFileName);
45
45
 
46
46
  var startT = new Date();
47
- buildFolder(options);
47
+ var content = buildFolder(options);
48
48
  var endT = new Date();
49
49
 
50
50
  var fcount = options.__filesContent.length;
@@ -53,6 +53,7 @@ module.exports.run = function(opts) {
53
53
  }
54
54
 
55
55
  utils.debug(`打包完成${options.outPath}\t 耗时:${endT.getTime() - startT.getTime()}毫秒\t合并文件数:${fcount}个\r\n\r\n`);
56
+ return content;
56
57
  }
57
58
 
58
59
 
@@ -98,6 +99,10 @@ function buildFolder(options) {
98
99
  content = content.replaceAll(key, value);
99
100
  });
100
101
  }
102
+ // 没有输出文件,直接返回压缩后的文件
103
+ if (!options.outPath) {
104
+ return content;
105
+ }
101
106
 
102
107
  var fileOutPath = options.outPath;
103
108
  fileOutPath = getAbsPath(fileOutPath);
@@ -515,12 +515,12 @@ class OpenFileWatcher {
515
515
  console.log(` ${encodingText} | ${sizeText} | ${eslintText} | ${compatText}`);
516
516
 
517
517
  // 如果有严重问题,显示详细信息
518
- if (eslintSummary.status === 'error' || eslintSummary.errors > 0) {
519
- console.log(chalk.red(' 严重问题详情:'));
520
- eslintSummary.issues.filter(issue => issue.severity === 'error').forEach(issue => {
521
- console.log(chalk.red(` 第${issue.line}行: ${issue.message}`));
522
- });
523
- }
518
+ // if (eslintSummary.status === 'error' || eslintSummary.errors > 0) {
519
+ // console.log(chalk.red(' 严重问题详情:'));
520
+ // eslintSummary.issues.filter(issue => issue.severity === 'error').forEach(issue => {
521
+ // console.log(chalk.red(` 第${issue.line}行: ${issue.message}`));
522
+ // });
523
+ // }
524
524
 
525
525
  // 如果有兼容性问题,显示详情
526
526
  if (compatSummary.hasES6 && compatSummary.samples.length > 0) {
@@ -557,20 +557,20 @@ class OpenFileWatcher {
557
557
  const errors = [];
558
558
 
559
559
  // 添加ESLint严重错误
560
- if (eslintSummary.issues) {
561
- eslintSummary.issues.forEach(issue => {
562
- if (issue.severity === 'error') {
563
- errors.push({
564
- type: issue.type,
565
- severity: issue.severity,
566
- line: issue.line,
567
- column: issue.column,
568
- message: issue.message,
569
- ruleId: issue.ruleId
570
- });
571
- }
572
- });
573
- }
560
+ // if (eslintSummary.issues) {
561
+ // eslintSummary.issues.forEach(issue => {
562
+ // if (issue.severity === 'error') {
563
+ // errors.push({
564
+ // type: issue.type,
565
+ // severity: issue.severity,
566
+ // line: issue.line,
567
+ // column: issue.column,
568
+ // message: issue.message,
569
+ // ruleId: issue.ruleId
570
+ // });
571
+ // }
572
+ // });
573
+ // }
574
574
 
575
575
  // 添加兼容性严重错误
576
576
  if (compatSummary.issues) {