Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Last active August 15, 2019 06:17
Show Gist options
  • Save dotherightthing/c255b22387d3a26400e8ba7b970effb8 to your computer and use it in GitHub Desktop.
Save dotherightthing/c255b22387d3a26400e8ba7b970effb8 to your computer and use it in GitHub Desktop.
[Passing command-line parameter to a gulpfile] #gulp

Passing command-line parameter to a gulpfile

/**
* Gulp Task Runner
*/
var minimist = require('minimist');
/**
* Command Line Configuration
* @example
* gulp dist
*
* @see https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-arguments-from-cli.md
* @see https://stackoverflow.com/questions/23023650/is-it-possible-to-pass-a-flag-to-gulp-to-have-it-run-tasks-in-different-ways
*/
var knownOptions = {
string: 'pluginrole',
default: { pluginrole: process.env.NODE_ENV || 'parent' }
};
var options = minimist(process.argv.slice(2), knownOptions);
if (options.pluginrole === 'child') {
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment