等待以前的gulp任务完成

时间:2015-08-15 15:01:06

标签: git deployment gulp

我正在尝试使用gulp和gulp-git自动化我的部署过程,但是我遇到了一个问题,我推送到git,然后尝试清理构建文件,但它在推送完成之前运行。有没有办法强制gulp等到上一个命令完成?或者直到满足其他一些条件?或者我只是以错误的方式接近这个?

这是我的gulp脚本:

var gulp = require('gulp');
var git = require('gulp-git');
var minifyCss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var runSequence = require('run-sequence');

//Main Deploy Task
gulp.task('deploy', function(){
    runSequence(
        'deploy-branch',
        'minify-css',
        'minify-js',
        'commit-all',
        'git-push',
        'clear-static',
        'master-branch',
        'remove-deploying'
        );
});

//Creates a branch called deploying
gulp.task('deploy-branch',function(){
    git.checkout('deploying', {args:'-b'}, function(err){
        if (err) throw err;
    });
});

//Minifies css
gulp.task('minify-css',function(){
    return gulp.src('static/**/**/*.css')
        .pipe(minifyCss({compatibility: 'ie8'}))
        .pipe(gulp.dest('static')); //Return in place
});

//Minifies js
gulp.task('minify-js',function(){
    return gulp.src('static/**/**/*.js')
        .pipe(uglify({mangle: false}))
        .pipe(gulp.dest('static'));
});

//Commit
gulp.task('commit-all', function(){
    return gulp.src('./static/*')
        .pipe(git.commit('deploying commit'));
});

//Pushes to the remote repo
gulp.task('git-push',function(){
    git.push('production', 'deploying', function(err){
        if (err) throw err;
    });
});

//Clear Minified Files
gulp.task('clear-static',function(){
    gulp.src('static/*')
        .pipe(git.checkoutFiles());
});

//Returns to master branch
gulp.task('master-branch',function(){
    git.checkout('master', function(err){
        if (err) throw err;
    });
});

//Deletes Deploying Branch
gulp.task('remove-deploying',function(){
    //Delete deploying branch
    git.branch('deploying', {args:'-D'}, function(err){
        if (err) throw err;
    });
});

0 个答案:

没有答案