Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtask execution without explicit definition

Does anyone have a solution for automatically running 'subtasks' in gulp?

I'm new to gulp, and currently structure my gulp file like this:

gulp.task('build:ccss', function(cb) {
  ...
}

gulp.task('build:js', function(cb) {
  ...
}

gulp.task('build:img', function(cb) {
  ...
}

gulp.task('build:index', function(cb) {
  ...
}

And then I explicitly define the base task and have it execute the subtasks:

gulp.task('build', ['build:scss', 'build:js', 'build:img', 'build:index']);

I use this structure for several 'groups' of tasks: cleaning, building, linting.

I'm curious if someone has a solution for automatically executing subtasks when the base task is run, without creating an explicit definition as I have.

like image 928
nfarrar Avatar asked Oct 20 '14 15:10

nfarrar


1 Answers

You could use async (or some other control flow library) this way:

var async = require('async');

gulp.task('build', function (callback) {
  async.series([
    function (cb) {

      // example usage should be your build:scss task,
      // notice the call of `cb` on end event

      gulp.src('package.json')
        .pipe(gulp.dest('test/'))
        .on('end', cb);
    },
    function (cb) {
      // same thing with the content of your build:js
    },

    // all your other tasks

  ], callback);
});
like image 106
Preview Avatar answered Oct 10 '22 07:10

Preview