Windwalker
Windwalker

Reputation: 1945

Gulp: abort build, if command line argument missing

I've written a gulp build which pipes several tasks, all depending on a mandatory argument, which is read from command line, using yargs plugin.

Lets say I have

gulp.task('myBuild', function () {
  return gulp.src('./' + <providedSubDir> + '/')

    .pipe(// do something or fail if <providedSubDir> is missing)

    .pipe(gulp.dest('./' + providedSubDir + '/'));
});

How can I now fail if the mandatory parameter providedSubDir is not provided upon call?

Upvotes: 2

Views: 280

Answers (1)

Louis
Louis

Reputation: 151401

Just throw an error if it is not set:

gulp.task('myBuild', function () {
    if (providedSubdir === undefined)
        throw new Error("you need to specify `providedSubdir`");

    // Rest of the task
});

Upvotes: 5

Related Questions