Skip to content

Commit 98b9504

Browse files
committed
Docs: Add recipe for running shell commands with child_process or gulp-exec
1 parent f7e7d4c commit 98b9504

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/recipes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
* [Exports as tasks](exports-as-tasks.md)
2828
* [Rollup with rollup-stream](rollup-with-rollup-stream.md)
2929
* [Run gulp task via cron job](cron-task.md)
30+
* [Running shell commands](running-shell-commands.md)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Running Shell Commands
2+
3+
Sometimes it is helpful to be able to call existing command line tools from gulp.
4+
5+
There are 2 ways to handle this: node's [`child_process`](https://nodejs.org/api/child_process.html)
6+
built-in module or [`gulp-exec`](https://github.com/robrich/gulp-exec) if you need to integrate the
7+
command with an existing pipeline.
8+
9+
```js
10+
'use strict';
11+
12+
var cp = require('child_process');
13+
var gulp = require('gulp');
14+
15+
gulp.task('reset', function() {
16+
// In gulp 4, you can return a child process to signal task completion
17+
return cp.execFile('git checkout -- .');
18+
});
19+
```
20+
21+
```js
22+
'use strict';
23+
24+
var gulp = require('gulp');
25+
var exec = require('gulp-exec');
26+
27+
gulp.task('reset', function() {
28+
return gulp.src('./**/**')
29+
.pipe(exec('git checkout -- <%= file.path %>'));
30+
});
31+
```

0 commit comments

Comments
 (0)