If you use gulp
as build tool for your web projects, you might have wondered how to pass custom flags to your tasks from CLI.
Well, with a lil’ help from the node package minimist, you can add this neat feature!
// gulpfile.js
var gulp = require('gulp');
var options = require('minimist')(process.argv);
gulp.task('show-flags', function () {
console.log(options);
});
$ gulp show-flags -abc --foo bar --bar=foo --zoo
# '_' contains unparsed args
> { _: [...], a: true,
b: true,
c: true,
foo: 'bar',
bar: 'foo',
zoo: true }
Usage of flag options is up to you to define your tasks. It's now time to substitute your old:
$ gulp build-dev with gulp build --env=dev