gpt4 book ai didi

javascript - Gulp Git 先运行提交任务然后推送任务

转载 作者:数据小太阳 更新时间:2023-10-29 05:35:22 25 4
gpt4 key购买 nike

我正在做项目,我想通过 gulp 提交和推送 git,但是当我运行 git 任务时我遇到了一些问题,所以推送然后任务不等待提交....

任何人都可以帮到我!我想让任务像第一次运行提交然后自动推送并且在完成提交任务之前不运行推送任务....

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'])
});

最佳答案

问题是您要告诉 runSequence 插件并行运行任务。解决方案非常简单:

// gulp task to commit and push data on git
gulp.task('git', function(){
return runSequence('gulp:commit', 'gulp:push', 'gulp:done');
});

这样做可以确保 gulp:push 仅在 gulp:commit 完成后运行,并且在推送完成后 gulp:done> 将运行。

此外,我建议您在 gulp:push 中返回流并在 gulp:done 中使用 done 回调参数,如果您不这样做,gulp 不会不知道这个任务什么时候结束:

// 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
return 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){
return git.push('origin', 'master', cb, function(err){
if (err) throw err;
});
});

// # task completed notification with green color!
gulp.task('gulp:done', ['gulp:push'], function(done){
console.log('');
gutil.log(gutil.colors.green('************** Git push is done! **************'));
console.log('');
done();
});

编辑:您也必须在 gulp:commit 任务中返回流,我更改了答案以向您展示如何操作。

关于javascript - Gulp Git 先运行提交任务然后推送任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37094350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com