diff --git a/docs/recipes/README.md b/docs/recipes/README.md index 52c3bcd19..3e822432a 100644 --- a/docs/recipes/README.md +++ b/docs/recipes/README.md @@ -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) diff --git a/docs/recipes/running-shell-commands.md b/docs/recipes/running-shell-commands.md new file mode 100644 index 000000000..5d3447476 --- /dev/null +++ b/docs/recipes/running-shell-commands.md @@ -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 %>')); +}); +```