【发布时间】:2016-09-02 19:46:33
【问题描述】:
我正在做项目,我想通过 gulp 提交和推送 git,但是当我运行 git task 时遇到了一些问题,所以推送然后任务不等待提交......
任何人都可以帮助我!我想让任务像首先运行提交然后自动推送,并且在完成提交任务之前不要运行推送任务......
Gulp Git 提交和推送的 Gulp 任务!
var gulp = require('gulp'),
runSequence = require('run-sequence'),
gutil = require('gulp-util'),
git = require('gulp-git'),
prompt = require('gulp-prompt');
/* task to commit and push all file on git
******************************************************************/
// git commit task with gulp prompt
gulp.task('gulp:commit', function(){
// just source anything here - we just wan't to call the prompt for now
gulp.src('./*')
.pipe(prompt.prompt({
type: 'input',
name: 'commit',
message: 'Please enter commit message...'
}, function(res){
// now add all files that should be committed
// but make sure to exclude the .gitignored ones, since gulp-git tries to commit them, too
return gulp.src([ '!node_modules/', './*' ], {buffer:false})
.pipe(git.commit(res.commit));
}));
});
// Run git push, remote is the remote repo, branch is the remote branch to push to
gulp.task('gulp:push', ['gulp:commit'], function(cb){
git.push('origin', 'master', cb, function(err){
if (err) throw err;
});
});
// # task completed notification with green color!
gulp.task('gulp:done', ['gulp:push'], function(){
console.log('');
gutil.log(gutil.colors.green('************** Git push is done! **************'));
console.log('');
});
// gulp task to commit and push data on git
gulp.task('git', function(){
runSequence(['gulp:commit', 'gulp:push', 'gulp:done'])
});
【问题讨论】:
标签: javascript node.js gulp gulp-git