javascriptnode.jsrun-sequence

using a dynamic list of gulp tasks in run-sequence


I am creating some gulp tasks with dynamic task names. These tasks need to be run in order, not parallel. I am putting the task names in an array, but I am getting an error from run-sequence. I assume this error is a problem with how I am listing the tasks from the array in my run-sequence code.

This is what I'm doing:

var taskNames = ['task1', 'task2', 'task3']

Then for run sequence I'm trying to do this:

gulp.task('run-dynamic-tasks', function(){
  runSequence(
    taskNames.join(", \n"),
    function(){
      browserSync.reload();
    }
  );
});

This does not work and gives this error:

Error: Task task1,

task2,

task3 is not configured as a task on gulp. If this is a submodule (error continues)

Please note, if there is only one task in the array, such as:

var taskNames = ['task1']

then this code works.

I believe this is probably a javascript mistake, as opposed to run-sequence or node.

thank you for any and all help, Scott


Solution

  • Turns out this is indeed a basic javascript problem. I should have been using function.apply

    Final gulp.task is this:

    gulp.task('run-dynamic-tasks', function(){
      runSequence.apply(null, taskNamesArray);
    });