UNPKG

3.71 kBMarkdownView Raw
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
14npm install --save-dev gulp-shell
15```
16
17## Usage
18
19```js
20const gulp = require('gulp')
21const shell = require('gulp-shell')
22
23gulp.task('example', () => {
24 return gulp
25 .src('*.js', { read: false })
26 .pipe(shell(['echo <%= file.path %>']))
27})
28```
29
30Or you can use this shorthand:
31
32```js
33gulp.task('greet', shell.task('echo Hello, World!'))
34```
35
36You 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
46type: `string` or `Array<string>`
47
48A 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
54type: `string`
55
56default: [`process.cwd()`](http://nodejs.org/api/process.html#process_process_cwd)
57
58Sets 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
62type: `object`
63
64By 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
66You can override any environment variables with this option.
67
68For 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
72type: `string`
73
74default: `/bin/sh` on UNIX, and `cmd.exe` on Windows
75
76Change it to `bash` if you like.
77
78#### options.quiet
79
80type: `boolean`
81
82default: `false`
83
84By default, it will print the command output.
85
86#### options.verbose
87
88type: `boolean`
89
90default: `false`
91
92Set to `true` to print the command(s) to stdout as they are executed
93
94#### options.ignoreErrors
95
96type: `boolean`
97
98default: `false`
99
100By default, it will emit an `error` event when the command finishes unsuccessfully.
101
102#### options.errorMessage
103
104type: `string`
105
106default: `` Command `<%= command %>` failed with exit code <%= error.code %> ``
107
108You can add a custom error message for when the command fails.
109This 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
113type: `object`
114
115The 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
122Details changes for each release are documented in the [release notes](https://github.com/sun-zheng-an/gulp-shell/releases).