gamelover42
gamelover42

Reputation: 375

gulp 4 mulitple SPA task composition with series and parallel

I have a large build that is composed of multiple sub-projects that are all built from a central set of shared gulp scripts.

Say I want to do this (there are other modules that define the actual tasks for the sub-projects):

var apps = [...]; //list of configuration objects for sub-projects in question
function builds() {
  var buildNames = apps.map(function (app) {
    return "release-build-" + app.name;
  });
  return gulp.parallel(buildNames);
}
function tests() {
  var testNames = apps.map(function (app) {
    return "test-" + app.name;
  });
  return gulp.series(testNames);
}
gulp.task("test", tests);
gulp.task("release-build", gulp.series(tests, builds));

In gulp 3 I do the following (the code for the release-build task follows the same pattern as test):

var runSequence = require("run-sequence").use(gulp);
gulp.task("test", function (callback) {
  // Get the test tasks of all children
  var tasks = apps.map(function(app) {
    return "test-" + app.name;
  });
  tasks.push(callback);
  //run tasks sequentially
  return runSequence.apply(null, tasks);
}); 

However when I try to run the new gulp 4 version I get the dreaded:

The following tasks did not complete 'test'
Did you forget to signal async completion?

How can I build my tasks names and pass them to gulp.series() or gulp.parallel() in gulp 4 like I did with run-sequence?

Upvotes: 2

Views: 566

Answers (1)

Sven Schoenung
Sven Schoenung

Reputation: 30564

Your builds and tests functions generate gulp.parallel() and gulp.series() task compositions. What you want to do is assign those generated task compositions as your test and release-build tasks.

What you are currently doing is to assign the builds and tests functions themselves as your tasks instead of their return values.

You need to actually invoke the builds and tests functions. So instead of this:

gulp.task("test", tests);
gulp.task("release-build", gulp.series(tests, builds));

You need to do this:

gulp.task("test", tests());
gulp.task("release-build", gulp.series(tests(), builds()));

Upvotes: 3

Related Questions