Skip to content

Commit

Permalink
Docs: Add recipe for running shell commands with child_process or gul…
Browse files Browse the repository at this point in the history
…p-exec
  • Loading branch information
phated committed Dec 31, 2017
1 parent f7e7d4c commit 98b9504
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
* [Exports as tasks](exports-as-tasks.md)
* [Rollup with rollup-stream](rollup-with-rollup-stream.md)
* [Run gulp task via cron job](cron-task.md)
* [Running shell commands](running-shell-commands.md)
31 changes: 31 additions & 0 deletions docs/recipes/running-shell-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Running Shell Commands

Sometimes it is helpful to be able to call existing command line tools from gulp.

There are 2 ways to handle this: node's [`child_process`](https://nodejs.org/api/child_process.html)
built-in module or [`gulp-exec`](https://github.com/robrich/gulp-exec) if you need to integrate the
command with an existing pipeline.

```js
'use strict';

var cp = require('child_process');
var gulp = require('gulp');

gulp.task('reset', function() {
// In gulp 4, you can return a child process to signal task completion
return cp.execFile('git checkout -- .');
});
```

```js
'use strict';

var gulp = require('gulp');
var exec = require('gulp-exec');

gulp.task('reset', function() {
return gulp.src('./**/**')
.pipe(exec('git checkout -- <%= file.path %>'));
});
```

0 comments on commit 98b9504

Please sign in to comment.