1 | # gulp-shell
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/gulp-shell.svg)](https://npmjs.org/package/gulp-shell)
|
4 | [![Build Status](https://img.shields.io/travis/sun-zheng-an/gulp-shell/master.svg)](https://travis-ci.org/sun-zheng-an/gulp-shell)
|
5 | [![Coveralls Status](https://img.shields.io/coveralls/sun-zheng-an/gulp-shell/master.svg)](https://coveralls.io/r/sun-zheng-an/gulp-shell)
|
6 | [![Dependency Status](https://img.shields.io/david/sun-zheng-an/gulp-shell.svg)](https://david-dm.org/sun-zheng-an/gulp-shell)
|
7 | [![Downloads](https://img.shields.io/npm/dm/gulp-shell.svg)](https://npmjs.org/package/gulp-shell)
|
8 |
|
9 | > A handy command line interface for gulp
|
10 |
|
11 | ## Installation
|
12 |
|
13 | ```shell
|
14 | npm install --save-dev gulp-shell
|
15 | ```
|
16 |
|
17 | ## Usage
|
18 |
|
19 | ```js
|
20 | const gulp = require('gulp')
|
21 | const shell = require('gulp-shell')
|
22 |
|
23 | gulp.task('example', () => {
|
24 | return gulp
|
25 | .src('*.js', { read: false })
|
26 | .pipe(shell(['echo <%= file.path %>']))
|
27 | })
|
28 | ```
|
29 |
|
30 | Or you can use this shorthand:
|
31 |
|
32 | ```js
|
33 | gulp.task('greet', shell.task('echo Hello, World!'))
|
34 | ```
|
35 |
|
36 | You can find more examples in the [gulpfile](https://github.com/sun-zheng-an/gulp-shell/blob/master/gulpfile.ts) of this project.
|
37 |
|
38 | **WARNING**: Running commands like ~~`gulp.src('').pipe(shell('whatever'))`~~ is [considered as an anti-pattern](https://github.com/sun-zheng-an/gulp-shell/issues/55). **PLEASE DON'T DO THAT ANYMORE**.
|
39 |
|
40 | ## API
|
41 |
|
42 | ### shell(commands, options) or shell.task(commands, options)
|
43 |
|
44 | #### commands
|
45 |
|
46 | type: `string` or `Array<string>`
|
47 |
|
48 | A command can be a [template][] which can be interpolated by some [file][] info (e.g. `file.path`).
|
49 |
|
50 | **WARNING**: [Using command templates can be extremely dangerous](https://github.com/sun-zheng-an/gulp-shell/issues/83). Don't shoot yourself in the foot by ~~passing arguments like `$(rm -rf $HOME)`~~.
|
51 |
|
52 | #### options.cwd
|
53 |
|
54 | type: `string`
|
55 |
|
56 | default: [`process.cwd()`](http://nodejs.org/api/process.html#process_process_cwd)
|
57 |
|
58 | Sets the current working directory for the command. This can be a [template][] which can be interpolated by some [file][] info (e.g. `file.path`).
|
59 |
|
60 | #### options.env
|
61 |
|
62 | type: `object`
|
63 |
|
64 | By default, all the commands will be executed in an environment with all the variables in [`process.env`](http://nodejs.org/api/process.html#process_process_env) and `PATH` prepended by `./node_modules/.bin` (allowing you to run executables in your Node's dependencies).
|
65 |
|
66 | You can override any environment variables with this option.
|
67 |
|
68 | For example, setting it to `{ PATH: process.env.PATH }` will reset the `PATH` if the default one brings your some troubles.
|
69 |
|
70 | #### options.shell
|
71 |
|
72 | type: `string`
|
73 |
|
74 | default: `/bin/sh` on UNIX, and `cmd.exe` on Windows
|
75 |
|
76 | Change it to `bash` if you like.
|
77 |
|
78 | #### options.quiet
|
79 |
|
80 | type: `boolean`
|
81 |
|
82 | default: `false`
|
83 |
|
84 | By default, it will print the command output.
|
85 |
|
86 | #### options.verbose
|
87 |
|
88 | type: `boolean`
|
89 |
|
90 | default: `false`
|
91 |
|
92 | Set to `true` to print the command(s) to stdout as they are executed
|
93 |
|
94 | #### options.ignoreErrors
|
95 |
|
96 | type: `boolean`
|
97 |
|
98 | default: `false`
|
99 |
|
100 | By default, it will emit an `error` event when the command finishes unsuccessfully.
|
101 |
|
102 | #### options.errorMessage
|
103 |
|
104 | type: `string`
|
105 |
|
106 | default: `` Command `<%= command %>` failed with exit code <%= error.code %> ``
|
107 |
|
108 | You can add a custom error message for when the command fails.
|
109 | This can be a [template][] which can be interpolated with the current `command`, some [file][] info (e.g. `file.path`) and some error info (e.g. `error.code`).
|
110 |
|
111 | #### options.templateData
|
112 |
|
113 | type: `object`
|
114 |
|
115 | The data that can be accessed in [template][].
|
116 |
|
117 | [template]: http://lodash.com/docs#template
|
118 | [file]: https://github.com/wearefractal/vinyl
|
119 |
|
120 | ## Changelog
|
121 |
|
122 | Details changes for each release are documented in the [release notes](https://github.com/sun-zheng-an/gulp-shell/releases).
|