-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Add recipe for running shell commands with child_process or gul…
…p-exec
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %>')); | ||
}); | ||
``` |