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,19 +9,22 @@ var fs = require('fs') | ||
| 9 | , UglifyJS = require("uglify-js"); | 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 | var pName = 'bsth_control' | 16 | var pName = 'bsth_control' |
| 14 | , path = process.cwd() | 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 | var realCtl = { | 28 | var realCtl = { |
| 26 | /** | 29 | /** |
| 27 | * 处理线调首页 | 30 | * 处理线调首页 |
| @@ -81,7 +84,7 @@ var handleCss = function ($, cb) { | @@ -81,7 +84,7 @@ var handleCss = function ($, cb) { | ||
| 81 | var data = out.styles; | 84 | var data = out.styles; |
| 82 | var fName = (k + '_' + md5(data)) + '.css'; | 85 | var fName = (k + '_' + md5(data)) + '.css'; |
| 83 | //写入 assets css 目录下 | 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 | fs.open(descFile, 'a', function (err, fd) { | 88 | fs.open(descFile, 'a', function (err, fd) { |
| 86 | 89 | ||
| 87 | fs.write(fd, data, function () { | 90 | fs.write(fd, data, function () { |
| @@ -135,7 +138,7 @@ var handleJs = function ($, file, cb) { | @@ -135,7 +138,7 @@ var handleJs = function ($, file, cb) { | ||
| 135 | var data = result.code; | 138 | var data = result.code; |
| 136 | var fName = (k + '_' + md5(data)) + '.js'; | 139 | var fName = (k + '_' + md5(data)) + '.js'; |
| 137 | //写入 assets js 目录下 | 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 | fs.open(descFile, 'a', function (err, fd) { | 142 | fs.open(descFile, 'a', function (err, fd) { |
| 140 | 143 | ||
| 141 | fs.write(fd, data, function () { | 144 | fs.write(fd, data, function () { |
src/main/resources/fatso/minifier.js
| @@ -5,12 +5,15 @@ | @@ -5,12 +5,15 @@ | ||
| 5 | var fs = require('fs'); | 5 | var fs = require('fs'); |
| 6 | var UglifyJS = require("uglify-js"); | 6 | var UglifyJS = require("uglify-js"); |
| 7 | 7 | ||
| 8 | +var platform = process.platform; | ||
| 9 | +var iswin = platform=='win32'; | ||
| 10 | +var separator = platform=='win32'?'\\':'/'; | ||
| 8 | var minifier = { | 11 | var minifier = { |
| 9 | 12 | ||
| 10 | mergeAndMini: function(fileArray,scriptString, root, file){ | 13 | mergeAndMini: function(fileArray,scriptString, root, file){ |
| 11 | var len = fileArray.length; | 14 | var len = fileArray.length; |
| 12 | for(var i = 0; i < len; i ++){ | 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 | var result, indoorRs; | 19 | var result, indoorRs; |
src/main/resources/fatso/start.js
| @@ -11,18 +11,22 @@ var fs = require('fs') | @@ -11,18 +11,22 @@ var fs = require('fs') | ||
| 11 | ,crypto = require("crypto") | 11 | ,crypto = require("crypto") |
| 12 | ,handle_real_ctl = require('./handle_real_ctl'); | 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 | var excludes = ['scheduleApp', 'trafficManage', 'control'] | 19 | var excludes = ['scheduleApp', 'trafficManage', 'control'] |
| 16 | ,ep = new EventProxy() | 20 | ,ep = new EventProxy() |
| 17 | ,pName = 'bsth_control' | 21 | ,pName = 'bsth_control' |
| 18 | ,path = process.cwd() | 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,7 +45,7 @@ ep.tail('mvn-clean',function(){ | ||
| 41 | //ep.emit('copy-project'); | 45 | //ep.emit('copy-project'); |
| 42 | //清理target | 46 | //清理target |
| 43 | logInfo('mvn clean...'); | 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 | if(error) | 49 | if(error) |
| 46 | logError(error); | 50 | logError(error); |
| 47 | 51 | ||
| @@ -55,8 +59,13 @@ ep.tail('mvn-clean',function(){ | @@ -55,8 +59,13 @@ ep.tail('mvn-clean',function(){ | ||
| 55 | //复制项目副本 | 59 | //复制项目副本 |
| 56 | ep.tail('copy-project',function(){ | 60 | ep.tail('copy-project',function(){ |
| 57 | logInfo('copy project...'); | 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 | if(error) | 69 | if(error) |
| 61 | logError(error); | 70 | logError(error); |
| 62 | 71 | ||
| @@ -79,7 +88,7 @@ ep.tail('minifier-js', function(){ | @@ -79,7 +88,7 @@ ep.tail('minifier-js', function(){ | ||
| 79 | //再处理首页 | 88 | //再处理首页 |
| 80 | ep.emit('handle-index', function(){ | 89 | ep.emit('handle-index', function(){ |
| 81 | //递归处理片段 | 90 | //递归处理片段 |
| 82 | - walk(dest + _static + '\\pages', function(item){ | 91 | + walk(dest + _static + separator + 'pages', function(item){ |
| 83 | ep.emit('handle-fragment', item); | 92 | ep.emit('handle-fragment', item); |
| 84 | }, | 93 | }, |
| 85 | function(){ | 94 | function(){ |
| @@ -103,7 +112,7 @@ ep.tail('package-jar', function(file){ | @@ -103,7 +112,7 @@ ep.tail('package-jar', function(file){ | ||
| 103 | 112 | ||
| 104 | logSuccess('mvn package success'); | 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 | output(cProcess); | 118 | output(cProcess); |
| @@ -113,7 +122,7 @@ ep.tail('package-jar', function(file){ | @@ -113,7 +122,7 @@ ep.tail('package-jar', function(file){ | ||
| 113 | ep.tail('handle-fragment', function(file){ | 122 | ep.tail('handle-fragment', function(file){ |
| 114 | //要排除的文件 | 123 | //要排除的文件 |
| 115 | for(var i = 0, ex; ex = excludes[i++];){ | 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 | return false; | 126 | return false; |
| 118 | } | 127 | } |
| 119 | handleJavascript(file, function(mini, $){ | 128 | handleJavascript(file, function(mini, $){ |
| @@ -130,12 +139,12 @@ ep.tail('handle-fragment', function(file){ | @@ -130,12 +139,12 @@ ep.tail('handle-fragment', function(file){ | ||
| 130 | 139 | ||
| 131 | //处理首页 | 140 | //处理首页 |
| 132 | ep.tail('handle-index', function(cb){ | 141 | ep.tail('handle-index', function(cb){ |
| 133 | - var index = dest + _static + '\\index.html'; | 142 | + var index = dest + _static + separator + 'index.html'; |
| 134 | handleJavascript(index, function(mini, $){ | 143 | handleJavascript(index, function(mini, $){ |
| 135 | var jsMiniText = mini.inside + mini.outside; | 144 | var jsMiniText = mini.inside + mini.outside; |
| 136 | 145 | ||
| 137 | var code = md5(jsMiniText); | 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 | if(err) | 148 | if(err) |
| 140 | logError(err); | 149 | logError(err); |
| 141 | 150 | ||
| @@ -210,7 +219,7 @@ function walk(path ,handleFile, over) { | @@ -210,7 +219,7 @@ function walk(path ,handleFile, over) { | ||
| 210 | console.log('read dir error'.red); | 219 | console.log('read dir error'.red); |
| 211 | } else { | 220 | } else { |
| 212 | files.forEach(function(item) { | 221 | files.forEach(function(item) { |
| 213 | - var tmpPath = path + '\\' + item; | 222 | + var tmpPath = path + separator + item; |
| 214 | fs.stat(tmpPath, function(err1, stats) { | 223 | fs.stat(tmpPath, function(err1, stats) { |
| 215 | if (err1) { | 224 | if (err1) { |
| 216 | console.log('stat error'); | 225 | console.log('stat error'); |