选用Subversion作为SVN提交工具,全程无弹窗(和小乌龟相比~免去用户点击OK操作)。用户体验上升啦 >.<
Subversion下载官网地址:http://subversion.apache.org/
需要配置环境变量:http://blog.sina.com.cn/s/blog_4e7a61b50100dwli.html
配置环境变量后需要重启电脑 (同事说cmd窗口有报错error... >.<)
// 文件名buildUat.js
let exec = require('child_process').exec,
co = require('co'),
path = require('path');
const SVN_URL = 'https://code.ds.XXX.com.cn/svn/gome_bh_jszx/30_Coding/NewDevMode/trunk/market/market-wap';
const userName = "lijinya";
const SVN_PATH = "D:\\MARK"
const SVN_NAME = "market-wap";
const UPDATE_PATH = path.resolve(__dirname, '..');
let arr = new Date().toLocaleString().split(' ');
let yearMonth = arr[0].replace(/-/g, '');
let time = arr[1].replace(/:/g, '').substring(0,4);
let fileName = `dist-${yearMonth}-${time}.zip`;
// 是否存在 压缩包指定目标目录/path
function isExist(){
return new Promise( (resolve, reject) => {
exec(`cd ${SVN_PATH}`, (error) => {
if (error) resolve(false)
resolve(true)
})
})
}
// 创建压缩包指定目标目录/path
function mkDir(){
return new Promise( (resolve, reject) => {
exec(`md ${SVN_PATH}`, (error) => {
if (error) return console.error(error)
console.log('mkDir---------------------- success')
resolve(true)
})
})
}
// checkout代码
function checkout(){
return new Promise((resole, reject) => {
exec(`svn checkout ${SVN_URL} ${SVN_NAME} --username ${userName}`,
{ cwd: `${SVN_PATH}`},
(error) => {
if(error) return console.log(error)
console.log("checkout success-----------------------")
resole()
})
})
}
// 更新代码
function svnUpdata(){
console.log('svnUpdata---------------------- start')
return new Promise( (resolve, reject) => {
exec(`svn update "${UPDATE_PATH}" `, (error) => {
if (error) return console.error(err)
console.log('svnUpdata---------------------- success')
resolve()
})
})
}
// 生成md5的js文件 == 执行build命令
function build(){
return new Promise( (resolve, reject) => {
exec(`node build/build.js`, (error) => {
if (error) return console.error(err)
console.log('buildJs--------------------- success')
resolve()
})
})
}
// 打包规范: dist-20170828-1345.zip
function zip(){
return new Promise( (resolve, reject) => {
exec(`winrar a -r -ep1 ${SVN_PATH}/${SVN_NAME}/${fileName} ./dist/`, (error) => {
if (error) return console.error(err)
console.log('zip---------------------------- success')
resolve()
})
})
}
// 添加:压缩包
function svnAdd(){
return new Promise( (resolve, reject) => {
exec(`svn add ${fileName} `,
{ cwd: `${SVN_PATH}\\${SVN_NAME}`},
(error) => {
if (error) return console.error(error)
console.log('压缩包更新------------------------- success')
resolve()
})
})
}
// 提交:压缩包
function svnCommit(){
return new Promise( (resolve, reject) => {
exec(`svn commit -m "test log message nokunokunoku"`,
{ cwd: `${SVN_PATH}\\${SVN_NAME}`},
(error) => {
if (error) return console.error(error)
console.log('svnCommit------------------------- success')
resolve('svnCommit')
})
})
}
co(function* (){
let flag = yield isExist();
if(!flag){
yield mkDir()
yield checkout()
}
yield svnUpdata()
yield build()
yield zip()
yield svnAdd()
yield svnCommit()
})
// package.json 添加 buildUat指令
"scripts": {
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js",
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"test": "npm run unit",
"lint": "eslint --ext .js,.vue src test/unit/specs",
"buildUat": "node build/buildUat.js"
},
// cmd执行
npm run buildUat