crabatool 1.0.457 → 1.0.458

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/tool/compress.js +28 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.457",
3
+ "version": "1.0.458",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,7 +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
+ "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 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",
17
17
  "mergeJxcFiles": "node ./test/test.js -mergeFiles -modName jxc -webPath F:/jxc/jxc-web/src/main/resources/static/jxc/ -targetPath F:/jxc/jxc-web/src/main/resources/static/jxc/ -inNames skins/blueSky/skin.css,js/wpsSettings.js,baseinfo/js/qiniu.min.js,baseinfo/js/baseinfo.constant.js,baseinfo/js/grid.ext.js,finance/js/finance.constant.js,baseinfo/js/lockScreen.js -initJs F:/jxc/jxc-web/src/main/resources/static/jxc/js/init.js",
18
18
  "mergeSaleFiles": "node ./test/test.js -mergeFiles -modName sale -webPath F:/sale/web/src/main/resources/static/sale/ -targetPath F:/sale/web/src/main/resources/static/sale/ -inNames skins/style/ColorSelectCss.css,skins/blueSky/skin.css,js/jquery.min.js,analysiscloud/js/wpsSettings.js,shopsale/js/payway.js,shopsale/js/billposter.js,eshoporder/eshopsaleorder/RetailHomeData.gspx,eshoporder/eshopsaleorder/RetailHomeData.js -initJs F:/sale/web/src/main/resources/static/sale/js/init.js",
19
19
  "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",
package/tool/compress.js CHANGED
@@ -265,12 +265,39 @@ function compressCss(inNames, targetCss) {
265
265
  return content;
266
266
  }
267
267
 
268
+ function removeXMLComments(xml) {
269
+ return xml.replace(/<!--[\s\S]*?-->/g, '');
270
+ }
271
+
272
+ function safeXmlMinify(xml) {
273
+ return xml
274
+ .replace('xmlns="Craba.UI"', 'xmlns="urn:Craba.UI"')
275
+ .replace(/>\s+</g, '><') // 移除标签间空白
276
+ .replace(/\s+/g, ' ') // 压缩多余空白
277
+ .replace(/\s?=\s?/g, '=') // 移除等号周围空白
278
+ .replace(/(\w)="([^"]*)"(\w)/g, '$1="$2" $3') // 属性间加空格
279
+ .replace(/(\/>)</g, '$1 <'); // 自闭合标签后加空格
280
+ }
281
+
268
282
  function compressGspx(filePath) {
269
283
  if (!fs.existsSync(filePath)) {
270
284
  return '';
271
285
  }
272
286
  const xmlMinifier = require('xml-minifier');
273
287
  let xml = fs.readFileSync(filePath, 'utf8');
274
- let minified = xmlMinifier.minify(xml);
288
+ xml = removeXMLComments(xml); // 手动替换注释,xml-minifier的removeComments没有生效的
289
+ xml = safeXmlMinify(xml);
290
+ return xml.trim();
291
+
292
+ /*
293
+ let minified = xmlMinifier.minify(xml, {
294
+ collapseWhitespace: true, // 折叠空白
295
+ removeComments: true, // 移除注释
296
+ removeEmptyAttributes: false,// 移除空属性
297
+ removeEmptyTags: false, // 保留空标签
298
+ preserveAttributeSpaces: true, // 保留属性之间的空白【关键】
299
+ trim: true // 修剪文本
300
+ });
275
301
  return minified;
302
+ */
276
303
  }