Created
February 28, 2015 07:40
-
-
Save LeezQ/61f3881ae0cba88b7af4 to your computer and use it in GitHub Desktop.
gulpfile 示例文件,带 svn 提交
This file contains 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
/** | |
* system modules | |
* @type {[type]} | |
*/ | |
var fs = require('fs'); | |
var exec = require('child_process').exec; | |
/** | |
* gulp node modules | |
* @type {[type]} | |
*/ | |
var gulp = require('gulp'); | |
var source = require('vinyl-source-stream'); | |
var streamify = require('gulp-streamify'); | |
var uglify = require('gulp-uglify'); | |
var rootPath = './dist/src'; | |
// var svnPath = '/Users/leezq/Sites/www.mogujie.com/public/marketing/'; | |
var svnPath = '/data/app/www.mogujie.com/public/marketing/'; | |
var paths = { | |
scripts: [] | |
}; | |
var files = fs.readdirSync(rootPath); | |
files.forEach(function(file) { | |
paths.scripts.push(rootPath + '/' + file); | |
}); | |
gulp.task('js', function() { | |
for (var i = 0; i < paths.scripts.length; i++) { | |
gulp.src(paths.scripts[i]) | |
.pipe(gulp.dest(svnPath + 'src')) | |
.pipe(streamify(uglify())) | |
.pipe(gulp.dest('./dist/')) | |
.pipe(gulp.dest(svnPath)); | |
} | |
}); | |
gulp.task('svn', ['js'], function() { | |
var t = new Date().getTime(); | |
console.log('======= svn up ======'); | |
exec('svn up ' + svnPath, function(err, stdout, stderr) { | |
console.log(stdout); | |
if(stderr) { | |
console.log(stderr); | |
} | |
console.log(svnPath); | |
exec('svn st ' + svnPath, function(err, stdout, stderr) { | |
// 如果有需要 svn add 的文件 | |
var addFiles = stdout.match(/\?.*/g); | |
if (addFiles) { | |
for (var i = 0; i < addFiles.length; i++) { | |
var file = addFiles[i].replace('\?', '').trim(); | |
console.log('add file : ' + file); | |
exec('svn add ' + file, function(err, stdout, stderr) { | |
console.log(stdout); | |
console.log(stderr); | |
}); | |
}; | |
} | |
// 如果有需要 svn add 的文件 | |
var commitFiles = stdout.match(/(A|M).*/g); | |
if (commitFiles) { | |
console.log('======= svn commit ======'); | |
exec('svn ci -m"beile: file ' + '" ' + svnPath , function (err, stdout, stderr) { | |
console.log(stdout); | |
console.log(stderr); | |
console.log('time cost: ' + (new Date().getTime() - t) / 1000 ); | |
}); | |
}; | |
console.log('======= time cost: ' + (new Date().getTime() - t) / 1000 + 's ======='); | |
// console.log(stderr); | |
}); | |
}); | |
}); | |
gulp.task('default', ['svn']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment