Skip to content

Commit

Permalink
Merge pull request #629 from superlukas/patch-1
Browse files Browse the repository at this point in the history
Sexier option parsing example
  • Loading branch information
phated committed Sep 14, 2014
2 parents 75b0d59 + e3e06fa commit 2c0d3cd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions docs/recipes/pass-arguments-from-cli.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# Pass arguments from the command line

```js
// npm install --save-dev gulp yargs gulp-if gulp-uglify
// npm install --save-dev gulp gulp-if gulp-uglify minimist

var args = require('yargs').argv;
var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var isProduction = args.type === 'production';
var minimist = require('minimist');

var knownOptions = {
string: 'env',
default: { env: process.env.NODE_ENV || 'production' }
};

var options = minimist(process.argv.slice(2), knownOptions);

gulp.task('scripts', function() {
return gulp.src('**/*.js')
.pipe(gulpif(isProduction, uglify())) // only minify in production
.pipe(gulpif(options.env === 'production', uglify())) // only minify in production
.pipe(gulp.dest('dist'));
});
```

The run gulp with:
Then run gulp with:

```sh
$ gulp scripts --type production
$ gulp scripts --env development
```

0 comments on commit 2c0d3cd

Please sign in to comment.