UNPKG

4.02 kBMarkdownView Raw
1gulp-run
2==================================================
3Use shell commands in your gulp or vinyl pipeline.
4
5Many Unix commands are built around the idea of piping. Let's take advantage of that in our Gulp pipeline! This plugin is inspired by [gulp-shell] and [gulp-spawn] and attempts to improve upon their great work.
6
7
8Usage
9--------------------------------------------------
10
11### `var run = require('gulp-run')`
12
13
14API
15--------------------------------------------------
16
17### `var cmd = run(command, [options])`
18
19Gets a through stream for a shell command to which you can pipe vinyl files. For each file piped, a new process is spawned, the file is read into the processes's stdin, and a file containing the processes's stdout is pushed.
20
21Additionally, `./node_modules/.bin` is prepended to the PATH for the child process, so you have access to all the binaries provided by your module's dependencies.
22
23### Arguments
241. `command` *(String)*: The command to run. It can be a [template] interpolating the vinyl file
25 as the variable `file`.
262. `[options]` *(Object)*:
27 - `env` *(Object)*: The environmental variables for the child process. Defaults to
28 `process.env`. The path `node_modules/.bin` is automatically prepended to the PATH.
29 - `cwd` *(String)*: The initial working directory for the child process. Defaults to
30 `process.cwd()`.
31 - `silent` *(Boolean)*: If true, do not print the command's output. This is the same as
32 setting verbosity to 1. Defaults to `false`.
33 - `verbosity` *(Number)*: Sets the verbosity level. Defaults to `2`.
34 - `0` never outputs anything.
35 - `1` outputs basic logs.
36 - `2` outputs basic logs and the stdout of the child process.
37
38#### Returns
39*(Stream.Transform in Object Mode)*: The through stream you so desire.
40
41#### Example
42```javascript
43gulp.task('even-lines', function () {
44 gulp.src('path/to/input/*') // Get input files.
45 .pipe(run('awk "NR % 2 == 0"')) // Use awk to extract the even lines.
46 .pipe(gulp.dest('path/to/output')) // Profit.
47})
48```
49
50
51### `cmd.exec([callback])`
52
53Executes the command immediately, returning the output as a vinyl stream. Unless the `silent` option is true, the output is tee'd to `process.stdout` with each line prepended by the string **"[*title*] "** where *title* is the command's name.
54
55The name of the file pushed down the pipe is the first word of the command. See [gulp-rename] if you need more flexibility.
56
57#### Arguments
581. `[callback]` *(Function)*: Execution is asynchronous. The callback is called once the
59 command's stdout has closed.
60
61#### Returns
62*(Stream.Readable in Object Mode)*: A stream containing exactly one vinyl file. The file's contents is the stdout stream of the command.
63
64#### Example
65```javascript
66gulp.task('hello-world', function () {
67 run('echo Hello World').exec() // prints "[echo] Hello World\n"
68 .pipe(gulp.dest('output')) // Writes "Hello World\n" to output/echo
69})
70```
71
72
73The ISC License
74--------------------------------------------------
75
76Copyright (c) 2014 Chris Barrick <cbarrick1@gmail.com>
77
78Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
79
80THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
81
82
83
84[gulp-rename]: https://github.com/hparra/gulp-rename
85[gulp-shell]: https://github.com/sun-zheng-an/gulp-shell
86[gulp-spawn]: https://github.com/hparra/gulp-spawn
87[template]: http://lodash.com/docs#template