Commit 58cd2667314e86e44467793b4568ae931f55b0b5
1 parent
7da3b27b
线调前端打包压缩工具,兼容linux...
Showing
3 changed files
with
38 additions
and
23 deletions
src/main/resources/fatso/handle_real_ctl.js
| ... | ... | @@ -9,19 +9,22 @@ var fs = require('fs') |
| 9 | 9 | , UglifyJS = require("uglify-js"); |
| 10 | 10 | ; |
| 11 | 11 | |
| 12 | +var platform = process.platform; | |
| 13 | +var iswin = platform=='win32'; | |
| 14 | +var separator = platform=='win32'?'\\':'/'; | |
| 12 | 15 | //不参与的目录 |
| 13 | 16 | var pName = 'bsth_control' |
| 14 | 17 | , path = process.cwd() |
| 15 | 18 | //根目录 |
| 16 | - , root = path.substr(0, path.indexOf('\\src\\main')) | |
| 17 | - , workspace = root.substr(0, root.indexOf('\\' + pName)) | |
| 19 | + , root = path.substr(0, path.indexOf(separator + 'src'+separator+'main')) | |
| 20 | + , workspace = root.substr(0, root.indexOf(separator + pName)) | |
| 18 | 21 | //临时目录 |
| 19 | - , dest = (workspace + '\\' + pName + '@fatso_copy').replace(/\//g, '\\') | |
| 20 | - , _static = '\\src\\main\\resources\\static'; | |
| 22 | + , dest = (workspace + separator + pName + '@fatso_copy')//.replace(/\//g, '\\') | |
| 23 | + , _static = separator + 'src'+separator+'main'+separator+'resources'+separator+'static'; | |
| 21 | 24 | |
| 22 | 25 | |
| 23 | -var mainFile = dest + _static + '\\real_control_v2\\main.html'; | |
| 24 | -var mapFile = dest + _static + '\\real_control_v2\\mapmonitor\\real.html'; | |
| 26 | +var mainFile = dest + _static + separator + 'real_control_v2'+separator+'main.html'; | |
| 27 | +var mapFile = dest + _static + separator + 'real_control_v2'+separator+'mapmonitor'+separator+'real.html'; | |
| 25 | 28 | var realCtl = { |
| 26 | 29 | /** |
| 27 | 30 | * 处理线调首页 |
| ... | ... | @@ -81,7 +84,7 @@ var handleCss = function ($, cb) { |
| 81 | 84 | var data = out.styles; |
| 82 | 85 | var fName = (k + '_' + md5(data)) + '.css'; |
| 83 | 86 | //写入 assets css 目录下 |
| 84 | - var descFile = dest + _static + '\\real_control_v2\\assets\\css\\' + fName; | |
| 87 | + var descFile = dest + _static + separator + 'real_control_v2'+separator+'assets'+separator+'css' + separator + fName; | |
| 85 | 88 | fs.open(descFile, 'a', function (err, fd) { |
| 86 | 89 | |
| 87 | 90 | fs.write(fd, data, function () { |
| ... | ... | @@ -135,7 +138,7 @@ var handleJs = function ($, file, cb) { |
| 135 | 138 | var data = result.code; |
| 136 | 139 | var fName = (k + '_' + md5(data)) + '.js'; |
| 137 | 140 | //写入 assets js 目录下 |
| 138 | - var descFile = dest + _static + '\\real_control_v2\\assets\\js\\' + fName; | |
| 141 | + var descFile = dest + _static + separator + 'real_control_v2'+separator+'assets'+separator+'js' + separator + fName; | |
| 139 | 142 | fs.open(descFile, 'a', function (err, fd) { |
| 140 | 143 | |
| 141 | 144 | fs.write(fd, data, function () { | ... | ... |
src/main/resources/fatso/minifier.js
| ... | ... | @@ -5,12 +5,15 @@ |
| 5 | 5 | var fs = require('fs'); |
| 6 | 6 | var UglifyJS = require("uglify-js"); |
| 7 | 7 | |
| 8 | +var platform = process.platform; | |
| 9 | +var iswin = platform=='win32'; | |
| 10 | +var separator = platform=='win32'?'\\':'/'; | |
| 8 | 11 | var minifier = { |
| 9 | 12 | |
| 10 | 13 | mergeAndMini: function(fileArray,scriptString, root, file){ |
| 11 | 14 | var len = fileArray.length; |
| 12 | 15 | for(var i = 0; i < len; i ++){ |
| 13 | - fileArray[i] = root + fileArray[i].split('/').join('\\'); | |
| 16 | + fileArray[i] = root + fileArray[i].split('/').join(separator); | |
| 14 | 17 | } |
| 15 | 18 | |
| 16 | 19 | var result, indoorRs; | ... | ... |
src/main/resources/fatso/start.js
| ... | ... | @@ -11,18 +11,22 @@ var fs = require('fs') |
| 11 | 11 | ,crypto = require("crypto") |
| 12 | 12 | ,handle_real_ctl = require('./handle_real_ctl'); |
| 13 | 13 | |
| 14 | + | |
| 15 | +var platform = process.platform; | |
| 16 | +var iswin = platform=='win32'; | |
| 17 | +var separator = platform=='win32'?'\\':'/'; | |
| 14 | 18 | //不参与的目录 |
| 15 | 19 | var excludes = ['scheduleApp', 'trafficManage', 'control'] |
| 16 | 20 | ,ep = new EventProxy() |
| 17 | 21 | ,pName = 'bsth_control' |
| 18 | 22 | ,path = process.cwd() |
| 19 | 23 | //根目录 |
| 20 | - ,root = path.substr(0, path.indexOf('\\src\\main')) | |
| 21 | - ,workspace = root.substr(0, root.indexOf('\\' + pName)) | |
| 24 | + ,root = path.substr(0, path.indexOf(separator + 'src'+separator+'main')) | |
| 25 | + ,workspace = root.substr(0, root.indexOf(separator + pName)) | |
| 22 | 26 | //临时目录 |
| 23 | - ,dest = (workspace + '\\' + pName+'@fatso_copy').replace(/\//g,'\\') | |
| 24 | - ,_static = '\\src\\main\\resources\\static' | |
| 25 | - ,_pages = dest + _static + '\\pages'; | |
| 27 | + ,dest = (workspace + separator + pName+'@fatso_copy') | |
| 28 | + ,_static = separator + 'src'+separator+'main'+separator+'resources'+separator+'static' | |
| 29 | + ,_pages = dest + _static + separator + 'pages'; | |
| 26 | 30 | |
| 27 | 31 | |
| 28 | 32 | //创建临时目录 |
| ... | ... | @@ -41,7 +45,7 @@ ep.tail('mvn-clean',function(){ |
| 41 | 45 | //ep.emit('copy-project'); |
| 42 | 46 | //清理target |
| 43 | 47 | logInfo('mvn clean...'); |
| 44 | - cProcess = child_process.exec("mvn clean",{cwd: workspace + '\\' + pName},function(error){ | |
| 48 | + cProcess = child_process.exec("mvn clean",{cwd: workspace + separator + pName},function(error){ | |
| 45 | 49 | if(error) |
| 46 | 50 | logError(error); |
| 47 | 51 | |
| ... | ... | @@ -55,8 +59,13 @@ ep.tail('mvn-clean',function(){ |
| 55 | 59 | //复制项目副本 |
| 56 | 60 | ep.tail('copy-project',function(){ |
| 57 | 61 | logInfo('copy project...'); |
| 58 | - var xcopyCom = 'XCOPY '+ root.replace(/\//g,'\\') + ' ' + dest +' /e /exclude:'+path+'\\exclude.txt'; | |
| 59 | - cProcess = child_process.exec(xcopyCom,{maxBuffer: 5000*1024},function(error){ | |
| 62 | + var xcopyCom; | |
| 63 | + if(iswin) | |
| 64 | + xcopyCom = 'XCOPY '+ root.replace(/\//g,'\\') + ' ' + dest +' /e /exclude:'+path+'\\exclude.txt'; | |
| 65 | + else | |
| 66 | + xcopyCom = 'cp -a ' + root + '/. ' + dest; | |
| 67 | + | |
| 68 | + cProcess = child_process.exec(xcopyCom,{cwd: workspace, maxBuffer: 5000*1024},function(error){ | |
| 60 | 69 | if(error) |
| 61 | 70 | logError(error); |
| 62 | 71 | |
| ... | ... | @@ -79,7 +88,7 @@ ep.tail('minifier-js', function(){ |
| 79 | 88 | //再处理首页 |
| 80 | 89 | ep.emit('handle-index', function(){ |
| 81 | 90 | //递归处理片段 |
| 82 | - walk(dest + _static + '\\pages', function(item){ | |
| 91 | + walk(dest + _static + separator + 'pages', function(item){ | |
| 83 | 92 | ep.emit('handle-fragment', item); |
| 84 | 93 | }, |
| 85 | 94 | function(){ |
| ... | ... | @@ -103,7 +112,7 @@ ep.tail('package-jar', function(file){ |
| 103 | 112 | |
| 104 | 113 | logSuccess('mvn package success'); |
| 105 | 114 | |
| 106 | - console.log(('成功打包在 ' + dest + '\\target 目录下').cyan); | |
| 115 | + console.log(('成功打包在 ' + dest + separator + 'target 目录下').cyan); | |
| 107 | 116 | }); |
| 108 | 117 | |
| 109 | 118 | output(cProcess); |
| ... | ... | @@ -113,7 +122,7 @@ ep.tail('package-jar', function(file){ |
| 113 | 122 | ep.tail('handle-fragment', function(file){ |
| 114 | 123 | //要排除的文件 |
| 115 | 124 | for(var i = 0, ex; ex = excludes[i++];){ |
| 116 | - if(file.indexOf(_pages + '\\' + ex) != -1) | |
| 125 | + if(file.indexOf(_pages + separator + ex) != -1) | |
| 117 | 126 | return false; |
| 118 | 127 | } |
| 119 | 128 | handleJavascript(file, function(mini, $){ |
| ... | ... | @@ -130,12 +139,12 @@ ep.tail('handle-fragment', function(file){ |
| 130 | 139 | |
| 131 | 140 | //处理首页 |
| 132 | 141 | ep.tail('handle-index', function(cb){ |
| 133 | - var index = dest + _static + '\\index.html'; | |
| 142 | + var index = dest + _static + separator + 'index.html'; | |
| 134 | 143 | handleJavascript(index, function(mini, $){ |
| 135 | 144 | var jsMiniText = mini.inside + mini.outside; |
| 136 | 145 | |
| 137 | 146 | var code = md5(jsMiniText); |
| 138 | - fs.open( dest + _static + '\\assets\\js\\' + code + '.js', 'a', function(err, fd){ | |
| 147 | + fs.open( dest + _static + separator + 'assets'+separator+'js' + separator + code + '.js', 'a', function(err, fd){ | |
| 139 | 148 | if(err) |
| 140 | 149 | logError(err); |
| 141 | 150 | |
| ... | ... | @@ -210,7 +219,7 @@ function walk(path ,handleFile, over) { |
| 210 | 219 | console.log('read dir error'.red); |
| 211 | 220 | } else { |
| 212 | 221 | files.forEach(function(item) { |
| 213 | - var tmpPath = path + '\\' + item; | |
| 222 | + var tmpPath = path + separator + item; | |
| 214 | 223 | fs.stat(tmpPath, function(err1, stats) { |
| 215 | 224 | if (err1) { |
| 216 | 225 | console.log('stat error'); | ... | ... |