最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - gulp.series() doesn't run tasks - Stack Overflow

programmeradmin1浏览0评论

I can't figure out why gulp.series() is not firing in my callback function.

I'm trying to grab a string from a user input with gulp-prompt and invoke a build and deployment function with gulp.series(). My tasks within gulp.series() don't fire at all.

gulp.task('test', function(){
  const prompt = require('gulp-prompt');
  return gulp.src('test.js')
    .pipe(prompt.prompt({
        type: 'checkbox',
        name: 'env',
        message: 'which environment do you want to deploy to?',
        choices: ['qa','prod']
    },function(res){
      //console.dir(res.env);
        var env = res.env;
        console.log(env);
        console.log('hi');
        gulp.series('clean', 'patternlab:build', 'tag-version', deployWeb.bind(this, env), function(done){
          done();
        });
    }));
});

I can't figure out why gulp.series() is not firing in my callback function.

I'm trying to grab a string from a user input with gulp-prompt and invoke a build and deployment function with gulp.series(). My tasks within gulp.series() don't fire at all.

gulp.task('test', function(){
  const prompt = require('gulp-prompt');
  return gulp.src('test.js')
    .pipe(prompt.prompt({
        type: 'checkbox',
        name: 'env',
        message: 'which environment do you want to deploy to?',
        choices: ['qa','prod']
    },function(res){
      //console.dir(res.env);
        var env = res.env;
        console.log(env);
        console.log('hi');
        gulp.series('clean', 'patternlab:build', 'tag-version', deployWeb.bind(this, env), function(done){
          done();
        });
    }));
});
Share Improve this question edited Oct 6, 2016 at 18:20 Sven Schoenung 30.6k8 gold badges67 silver badges70 bronze badges asked Oct 6, 2016 at 17:13 jmdesigner81jmdesigner81 1533 silver badges12 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 19

Calling gulp.series('task1', 'task2') does not run task1 and task2. All it does is return a new function. Only once you call that function are the tasks actually executed.

That means in your case you need to do the following:

var runTasks = gulp.series('clean', 'patternlab:build',
                           'tag-version', deployWeb.bind(this, env));
runTasks();

The whole function(done){ done(); } part that you had in your code doesn't really make much sense and isn't needed for gulp.series().

Sven Schoenung's answer is correct.

If you don't want to add a new variable, just make it a self-calling JS function like,

gulp.series('clean', 'patternlab:build', 'tag-version', deployWeb.bind(this, env))();
发布评论

评论列表(0)

  1. 暂无评论