crabatool 1.0.349 → 1.0.351

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.349",
3
+ "version": "1.0.351",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "start": "node run.js",
11
11
  "test": "node ./test/test.js",
12
12
  "run": "node ./test/test.js -run",
13
+ "mergeinitjs":"node ./test/test.js -mergeinitjs",
13
14
  "export": "node ./test/test.js -exportgspx -webPath F:\\Beefun\\srcs",
14
15
  "checkjs": "node ./test/test.js -checkjs",
15
16
  "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/test/test.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ npx crabatool -mergejs -ignoreCompress true -targetPath /Users/yj/Desktop/CarpaNET/src/Carpa.Web/js -inNames type.js,craba.js,common.js,es6.js,controls.js,required.js,drag.js,listView.js,crabaEx.js,crabaFC.js,crabaMS.js -outName /Users/yj/Public/工作/Code/newJsBin/craba.min.js -clearCache true
4
+ # crabatool -mergejs -ignoreCompress true -targetPath /Users/yj/Desktop/CarpaNET/src/Carpa.Web/js -inNames grid.js,controlsEx.js,treeView.js,print.js,../../../src/Carpa.Dress/Dress.js,workflow.js,crabaeditor.js -outName /Users/yj/Public/工作/Code/newJsBin/crabaEx.min.js
5
+ # crabatool -mergejs -ignoreCompress true -targetPath /Users/yj/Desktop/CarpaNET/src/Carpa.Web/js -inNames crabaNgp/initMS.js,crabaNgp/businessControl.js -outName /Users/yj/Public/工作/Code/newJsBin/crabaNgp.js
6
+ # crabatool -mergecss -ignoreCompress true -targetPath /Users/yj/Desktop/CarpaNET/src/Carpa.Web/skins -inNames iconfont.css,craba.min.css -outName /Users/yj/Public/工作/Code/newJsBin/craba.min.css
@@ -12,6 +12,7 @@ function mergeBiz(childPath) {
12
12
  return utils.error('biz.js关联打包的路径不存在,如需打包请先创建目录:' + bizPath);
13
13
  }
14
14
  utils.log('biz.js打包启动:' + bizPath);
15
+ utils.log('ignoreCompress=' + config.ignoreCompress)
15
16
 
16
17
  var watchAction = function() {
17
18
  utils.debug('打包中');
package/tool/compress.js CHANGED
@@ -159,7 +159,7 @@ function compressAndMergeCss(inNames, rootPath, outName) {
159
159
  });
160
160
 
161
161
  var targetCss = utils.join(_tempSkinPath, outName);
162
- compressCss(inNames, targetCss, onEnd);
162
+ compressCss(inNames, targetCss);
163
163
  /*
164
164
  var p = fork(_mergeCssPath, [`${[inNames]}`, `${[targetJs]}`, _compressArgs]);
165
165
  p.on('exit', () => {
@@ -168,7 +168,7 @@ function compressAndMergeCss(inNames, rootPath, outName) {
168
168
  */
169
169
  }
170
170
 
171
- function compressCss(inNames, targetCss, onEnd) {
171
+ function compressCss(inNames, targetCss) {
172
172
  mergeTool.run({
173
173
  inPath: inNames,
174
174
  outPath: targetCss,
@@ -176,8 +176,4 @@ function compressCss(inNames, targetCss, onEnd) {
176
176
  hidejspath: config.hidejspath,
177
177
  ignoreCompress: config.ignoreCompress
178
178
  });
179
-
180
- if (onEnd) {
181
- onEnd();
182
- }
183
179
  }
@@ -40,6 +40,7 @@ module.exports.run = function(opts) {
40
40
 
41
41
  utils.debug("输入文件清单:" + options.inPath);
42
42
  utils.debug("输出文件:" + options.outPath);
43
+ utils.log("ignoreCompress:" + options.ignoreCompress);
43
44
 
44
45
  var startT = new Date();
45
46
  buildFolder(options);
@@ -79,8 +80,7 @@ function buildFolder(options) {
79
80
  if (ext != options.ext) return; // .js或.css
80
81
 
81
82
  if (!checkFileCache(stats, filePath, options)) { // 检查文件是否修改过,且是否上次压缩过缓存
82
- copyFileToCache1(filePath, stats);
83
- compressFile(filePath, options);
83
+ compressFile(filePath, options, null, stats);
84
84
  }
85
85
  });
86
86
 
@@ -167,14 +167,7 @@ function replaceBlackFunction(content, options) {
167
167
  return content;
168
168
  }
169
169
 
170
- function getCachePath1(filePath) {
171
- var fileName = path.basename(filePath);
172
- var hashName = utils.getHashCode(path.dirname(filePath));
173
- var cachePath = path.join(__cachePath, 'source', hashName, fileName);
174
- return cachePath;
175
- }
176
-
177
- function getCachePath2(filePath) {
170
+ function getCachePath(filePath) {
178
171
  var fileName = path.basename(filePath);
179
172
  var hashName = utils.getHashCode(path.dirname(filePath));
180
173
  var cachePath = path.join(__cachePath, 'compress', hashName, fileName);
@@ -182,12 +175,12 @@ function getCachePath2(filePath) {
182
175
  }
183
176
 
184
177
  function checkFileCache(stats1, filePath, options) {
185
- if (config.clearCache) {
178
+ if (config.clearCache || options.ignoreCompress) {
186
179
  utils.debug('不使用缓存');
187
180
  return false;
188
181
  }
189
182
 
190
- var cachePath = getCachePath1(filePath);
183
+ var cachePath = getCachePath(filePath);
191
184
  utils.debug('检查缓存:' + cachePath);
192
185
  if (!fs.existsSync(cachePath)) {
193
186
  utils.debug('没有缓存:' + cachePath);
@@ -206,7 +199,7 @@ function checkFileCache(stats1, filePath, options) {
206
199
  }
207
200
 
208
201
  function writeCacheFile(filePath, options) {
209
- var cachePath = getCachePath2(filePath);
202
+ var cachePath = getCachePath(filePath);
210
203
  if (!fs.existsSync(cachePath)) {
211
204
  utils.debug("缓存文件不存在");
212
205
  return false;
@@ -218,9 +211,7 @@ function writeCacheFile(filePath, options) {
218
211
  return true;
219
212
  }
220
213
 
221
- function compressFile(filePath, options, filePath2) {
222
- utils.debug("压缩和合并文件:" + filePath);
223
-
214
+ function compressFile(filePath, options, filePath2, stats) {
224
215
  var content = fs.readFileSync(filePath);
225
216
  content = content.toString().replace(__bom, '');
226
217
 
@@ -231,6 +222,7 @@ function compressFile(filePath, options, filePath2) {
231
222
 
232
223
  // 压缩js或css文件
233
224
  if (!options.ignoreCompress) {
225
+ utils.debug("压缩文件:" + filePath);
234
226
  content = utils.toUtf8(content);
235
227
  if (options.ext == '.js') {
236
228
  content = UglifyJS.minify(content, compressOptions).code;
@@ -241,7 +233,7 @@ function compressFile(filePath, options, filePath2) {
241
233
  });
242
234
  }
243
235
 
244
- copyByteToCache2(filePath, content);
236
+ copyByteToCache(filePath, content, stats);
245
237
  }
246
238
  }
247
239
 
@@ -253,19 +245,10 @@ function compressFile(filePath, options, filePath2) {
253
245
  utils.debug('文件打包完成:' + filePath + '\r\n');
254
246
  }
255
247
 
256
-
257
- function copyFileToCache1(filePath, stats) {
258
- var cachePath = getCachePath1(filePath);
259
- utils.debug("拷贝到缓存1:" + cachePath);
248
+ function copyByteToCache(filePath, content, stats) {
249
+ var cachePath = getCachePath(filePath);
260
250
  utils.mkdirsSync(cachePath);
261
-
262
- fs.copyFileSync(filePath, cachePath);
263
- fs.utimesSync(cachePath, stats.atime, stats.mtime); // 必须同步文件时间
264
- }
265
-
266
- function copyByteToCache2(filePath, content) {
267
- var cachePath = getCachePath2(filePath);
268
- utils.mkdirsSync(cachePath);
269
- utils.debug("拷贝到缓存2:" + cachePath);
251
+ utils.debug("拷贝到缓存:" + cachePath);
270
252
  fs.writeFileSync(cachePath, content, 'utf8');
253
+ fs.utimesSync(cachePath, stats.atime, stats.mtime); // 必须同步文件时间
271
254
  }