Skip to content

Commit 423b0c8

Browse files
committed
A recipe for passing parameters from the command line
1 parent 2c064bb commit 423b0c8

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

docs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See [the FAQ](FAQ.md) for the answers to commonly asked questions.
1313
* [Working with multiple sources in one task](recipes/using-multiple-sources-in-one-task.md)
1414
* [Mocha test runner with gulp](recipes/mocha-test-runner-with-gulp.md)
1515
* [Rebuild only files that change](recipes/rebuild-only-files-that-change.md)
16+
* [Pass parameters from the command line](recipes/pass-params-from-cli.md)
1617
* [Using external config file](recipes/using-external-config-file.md)
1718
* [Introduction to node.js streams](https://github.com/substack/stream-handbook)
1819

docs/recipes/pass-params-from-cli.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Pass parameters from the command line
2+
## bonus: keeping those tasks DRY
3+
4+
---
5+
6+
`gulpfile.js`
7+
8+
```js
9+
// npm install gulp gulp-if gulp-uglify
10+
var gulp = require('gulp');
11+
var gulpif = require('gulp-if');
12+
var uglify = require('gulp-uglify');
13+
14+
var isProduction = gulp.env.type === 'production';
15+
16+
gulp.task('scripts', function () {
17+
return gulp.src('**/*.js')
18+
.pipe(gulpif(isProduction, uglify())) // only minify if production
19+
.pipe(gulp.dest('dist'));
20+
});
21+
```
22+
23+
---
24+
25+
`cli`
26+
27+
`gulp scripts --type production`

test/tasks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*jshint node:true */
2-
/*global describe:false, it:false, beforeEach:false, afterEach:false */
2+
/*global describe:false, it:false */
33
"use strict";
44

55
var gulp = require('../');

0 commit comments

Comments
 (0)