crabatool 1.0.455 → 1.0.457
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 +2 -1
- package/lib/utils.js +10 -0
- package/package.json +21 -19
- package/tool/compress.js +26 -6
package/index.js
CHANGED
|
@@ -204,7 +204,8 @@ async function checkFast(args) {
|
|
|
204
204
|
|
|
205
205
|
if (args.includes('-mergeFiles')) { // 将特定文件压缩后,路径作为key,合并到一个json文件包,减少http请求
|
|
206
206
|
start.bindAndCheckConfig('-inNames');
|
|
207
|
-
start.
|
|
207
|
+
start.bindConfigByArgv('-outName');
|
|
208
|
+
start.bindConfigByArgv('-initJs');
|
|
208
209
|
start.bindConfigByArgv('-targetPath');
|
|
209
210
|
start.bindConfigByArgv('-exp');
|
|
210
211
|
config.mergeFile = true;
|
package/lib/utils.js
CHANGED
|
@@ -49,6 +49,16 @@ class Utils {
|
|
|
49
49
|
constructor() {
|
|
50
50
|
this.cryptoKey = '$wssf20119@.Z+Q$';
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
removePathPrefix(fullPath, prefix) {
|
|
54
|
+
// 规范化路径(统一分隔符为当前系统的分隔符)
|
|
55
|
+
const normalizedFullPath = path.normalize(fullPath);
|
|
56
|
+
const normalizedPrefix = path.normalize(prefix);
|
|
57
|
+
|
|
58
|
+
// 使用 path.relative 计算相对路径
|
|
59
|
+
return path.relative(normalizedPrefix, normalizedFullPath);
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
isLocal(req) {
|
|
53
63
|
//const hostname = os.hostname();
|
|
54
64
|
//console.log(req.headers.host);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crabatool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.457",
|
|
4
4
|
"description": "crabatool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,30 +9,32 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node run.js",
|
|
11
11
|
"test": "node ./test/test.js",
|
|
12
|
-
"run": "node ./test/test.js -run -webPath F
|
|
12
|
+
"run": "node ./test/test.js -run -webPath F:/basicweb/www -refresh true",
|
|
13
13
|
"mergeinitjs": "node ./test/test.js -mergeinitjs",
|
|
14
|
-
"export": "node ./test/test.js -exportgspx -webPath F
|
|
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
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
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",
|
|
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
|
+
"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
|
+
"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",
|
|
20
|
+
"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",
|
|
21
|
+
"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",
|
|
20
22
|
"beefun": "node ./test/beefun.js -checkjs",
|
|
21
|
-
"checkUpdate": "node run.js -checkUpdate -version master -webPath F
|
|
22
|
-
"upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F
|
|
23
|
-
"crabaNgp": "node run.js -mergejs -hidejspath true -targetPath F
|
|
24
|
-
"mergeJs2": "node run.js -mergejs -targetPath -inNames F
|
|
25
|
-
"checkcrabaevery": "node ./test/test.js -checkjs -webPath F
|
|
26
|
-
"biconfont": "node ./test/test.js -iconfont -zipPath F
|
|
27
|
-
"aiconfont": "node ./test/test.js -iconfont -zipPath F
|
|
23
|
+
"checkUpdate": "node run.js -checkUpdate -version master -webPath F:/crabaevery/www",
|
|
24
|
+
"upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F:/CarpaNET_NEW",
|
|
25
|
+
"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",
|
|
26
|
+
"mergeJs2": "node run.js -mergejs -targetPath -inNames F:/CarpaNET_NEW/src/Carpa.Web/js/craba.js,F:/CarpaNET_NEW/src/Carpa.Web/js/controls.js -outName F:/a.js -ignorecompress true",
|
|
27
|
+
"checkcrabaevery": "node ./test/test.js -checkjs -webPath F:/crabaevery/www -modName crabaevery -Debug false",
|
|
28
|
+
"biconfont": "node ./test/test.js -iconfont -zipPath F:/crabaevery/www/biconfont -fontPath F:/crabaevery/www/skins/bicon -prefix .bicon- -fontName biconfont",
|
|
29
|
+
"aiconfont": "node ./test/test.js -iconfont -zipPath F:/crabaevery/www/iconfont -fontPath F:/CarpaNET_NEW/src/Carpa.Web/skins -prefix .aicon- -fontName iconfont",
|
|
28
30
|
"makeHash": "node run.js -makeHash -webPath ./test/ -modName craba -files http://crabadoc.ca.com/js/utils/utils.js,F:/newcrabadoc/www/js/utils/utils.js,./test/test.js,./test/beefun.js,https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js?a=1 -outJson ./hash.json -hashName sha384",
|
|
29
31
|
"makeHash2": "node run.js -makeHash -webPath ./test/ -modName craba -files ./test/ -exts .js -outJson ./hash2.json -hashName sha384",
|
|
30
32
|
"pageHash": "node run.js -pageHash /Test/TestMasterDetail.gspx",
|
|
31
|
-
"addVersion": "node run.js -addVersion -file F
|
|
32
|
-
"gspxHash": "node run.js -gspxHash -webPath F
|
|
33
|
-
"runShell": "node run.js -run -webPath F
|
|
34
|
-
"runShellLocal": "node run.js -run -webPath F
|
|
35
|
-
"runJxc": "node run.js -run -webPath F
|
|
33
|
+
"addVersion": "node run.js -addVersion -file F:/basicweb/www/index.html -exp AUTOVERSION",
|
|
34
|
+
"gspxHash": "node run.js -gspxHash -webPath F:/Beefun/srcs/Beefun",
|
|
35
|
+
"runShell": "node run.js -run -webPath F:/shell-gerrit/web/src/main/resources/static/shell/ -port 10000 -modName shell",
|
|
36
|
+
"runShellLocal": "node run.js -run -webPath F:/shell-gerrit/web/src/main/resources/static/shell/ -port 10000 -modName shell -localLogin true",
|
|
37
|
+
"runJxc": "node run.js -run -webPath F:/jxc/jxc-web/src/main/resources/static/jxc/ -port 10001 -modName jxc",
|
|
36
38
|
"runMacJxc": "node run.js -run -webPath /Users/yj/Desktop/jxc/jxc-web/src/main/resources/static/jxc -port 10001 -modName jxc",
|
|
37
39
|
"testBasicWeb": "node run.js -run -webPath /Users/yj/Public/工作/Code/basicweb/www -port 9977 -refresh true",
|
|
38
40
|
"open-file-watch": "node examples/simple-file-watch.js",
|
package/tool/compress.js
CHANGED
|
@@ -39,7 +39,7 @@ module.exports.mergeFiles = function() {
|
|
|
39
39
|
inNames = inNames.map((s) => {
|
|
40
40
|
return path.join(config.targetPath, s);
|
|
41
41
|
});
|
|
42
|
-
compressFiles(inNames, config.outName);
|
|
42
|
+
compressFiles(inNames, config.outName, config.initJs);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
module.exports.mergeJs = function() {
|
|
@@ -155,14 +155,14 @@ function compressCrabaJs(inNames, outName, onEnd) {
|
|
|
155
155
|
compressJs(inNames, targetJs, onEnd)
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
function compressFiles(inNames, outName) {
|
|
158
|
+
function compressFiles(inNames, outName, initJs) {
|
|
159
159
|
console.log('compressFiles开始,打包文件数:', inNames.length);
|
|
160
160
|
config.hidejspath = true;
|
|
161
161
|
config.ignoreCompress = false;
|
|
162
162
|
|
|
163
163
|
var json = {};
|
|
164
164
|
inNames.forEach(function(filePath) {
|
|
165
|
-
var path2 =
|
|
165
|
+
var path2 = utils.removePathPrefix(filePath, config.webPath);
|
|
166
166
|
if (config.modName) {
|
|
167
167
|
path2 = path.join(config.modName, path2);
|
|
168
168
|
}
|
|
@@ -184,9 +184,29 @@ function compressFiles(inNames, outName) {
|
|
|
184
184
|
json[path2] = content;
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
var resContent = `$app.addRes(${JSON.stringify(json)});`;
|
|
188
|
+
if (initJs) { // 资源包压缩到init.js里面一次性下放
|
|
189
|
+
if (!fs.existsSync(initJs)) {
|
|
190
|
+
console.log('打包失败,init.js不存在', initJs);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
var initJsContent = fs.readFileSync(initJs, 'utf-8');
|
|
194
|
+
var resStart = '/*请不要删除此注释--resStart--*/';
|
|
195
|
+
var resEnd = '/*请不要删除此注释--resEnd--*/';
|
|
196
|
+
var startIndex = initJsContent.indexOf(resStart);
|
|
197
|
+
var endIndex = initJsContent.indexOf(resEnd);
|
|
198
|
+
if (startIndex > -1 && endIndex > -1) {
|
|
199
|
+
initJsContent = initJsContent.slice(0, startIndex + resStart.length) + '\r\n' + resContent + '\r\n' + initJsContent.slice(endIndex);
|
|
200
|
+
} else {
|
|
201
|
+
initJsContent = resStart + '\r\n' + resContent + '\r\n' + resEnd + '\r\n' + initJsContent;
|
|
202
|
+
}
|
|
203
|
+
fs.writeFileSync(initJs, initJsContent);
|
|
204
|
+
console.log('compressFiles完成,资源包追加initjs的方式,路径:', initJs);
|
|
205
|
+
} else {
|
|
206
|
+
utils.mkdirsSync(outName);
|
|
207
|
+
fs.writeFileSync(outName, resContent);
|
|
208
|
+
console.log('compressFiles完成,单独创建资源包的方式,路径:', outName);
|
|
209
|
+
}
|
|
190
210
|
}
|
|
191
211
|
|
|
192
212
|
function compressJs(inNames, targetJs, onEnd) {
|