Created
March 26, 2014 09:19
-
-
Save otakustay/9779506 to your computer and use it in GitHub Desktop.
build with svn revision
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svnInfoOutput = ''; | |
var svnInfo = require('child_process').exec( | |
'svn info', | |
function (err) { | |
var svnRevision; | |
if (err) { | |
// 如果没装svn命令行,获取不到版本号,就用时间戳了 | |
svnRevision = +new Date(); | |
console.warn( | |
'\033[31m' | |
+ 'SVN client not found, ' | |
+ 'use timestamp as version number, ' | |
+ 'this may cause MD5 diferrence when deploy' | |
+ '\033[0m' | |
); | |
} | |
else { | |
// 获取svn版本号 | |
svnRevision = /Revision: (\d+)/.exec(svnInfoOutput)[1]; | |
console.log('SVN is at revision ' + svnRevision); | |
} | |
console.log('Started building'); | |
var startTime = new Date(); | |
var args = ['build', '.', '--revision=' + svnRevision]; | |
// Windows下必须用`cmd /c edp build . --revision=xxx`这么来,直接执行报错, | |
// 使用`process.env.comspec`可以判断是否为Windows平台了 | |
if (process.env.comspec) { | |
args.unshift('edp'); | |
args.unshift('/c'); | |
} | |
// 把svn版本号传给edp build命令 | |
var build = require('child_process').spawn( | |
process.env.comspec || 'edp', | |
args.concat(process.argv.slice(2)), | |
{ stdio: 'inherit' } | |
); | |
build.on( | |
'error', | |
function (err) { | |
console.log('Encountered error:', err); | |
process.exit(); | |
} | |
); | |
build.on( | |
'close', | |
function (err) { | |
console.log('done within ' + (new Date() - startTime) + 'ms'); | |
} | |
); | |
} | |
); | |
svnInfo.stdout.on('data', function (data) { svnInfoOutput += data; }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 获取命令行传过来的svn版本号 | |
var args = {}; | |
(function () { | |
for (var i = 4; i < process.argv.length; i++) { | |
var arg = process.argv[i]; | |
console.log(arg); | |
var pair = arg.split('='); | |
var key = pair[0].substring(2); | |
var value = pair[1]; | |
args[key] = value; | |
} | |
}()); | |
var svnRevision = args.revision || ''; | |
// 重点就在2个PathMapper上,其它的Processor随便加 | |
exports.getProcessors = function () { | |
return [ | |
new PathMapper({ | |
replacements: [ | |
{ type: 'html', tag: 'link', attribute: 'href', extnames: pageEntries }, | |
{ type: 'html', tag: 'img', attribute: 'src', extnames: pageEntries }, | |
{ type: 'html', tag: 'script', attribute: 'src', extnames: pageEntries }, | |
{ type: 'html', tag: 'a', attribute: 'href', extnames: pageEntries }, | |
{ extnames: moduleEntries, replacer: 'module-config' }, | |
{ extnames: 'css,less', replacer: 'css' } | |
], | |
from: 'src', | |
to: 'asset-' + svnRevision | |
}), | |
new PathMapper({ | |
replacements: [ | |
{ type: 'html', tag: 'link', attribute: 'href', extnames: pageEntries }, | |
{ type: 'html', tag: 'img', attribute: 'src', extnames: pageEntries }, | |
{ type: 'html', tag: 'script', attribute: 'src', extnames: pageEntries }, | |
{ type: 'html', tag: 'a', attribute: 'href', extnames: pageEntries }, | |
{ extnames: moduleEntries, replacer: 'module-config' }, | |
{ extnames: 'css,less', replacer: 'css' } | |
], | |
from: 'dep', | |
to: 'dep-' + svnRevision | |
}), | |
new AddCopyright(), | |
new ReplaceDebug({ | |
exclude: ['*.tpl.html'] | |
}) | |
]; | |
}; | |
/** | |
* builder主模块注入processor构造器的方法 | |
* | |
* @param {Object} processors | |
*/ | |
exports.injectProcessor = function (processors) { | |
for (var key in processors) { | |
global[key] = processors[key]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment