1 | | [index](../README.md) | npm-run-all | [run-s](run-s.md) | [run-p](run-p.md) | [Node API](node-api.md) |
|
2 | |-----------------------|-------------|-------------------|-------------------|-------------------------|
|
3 |
|
4 | # `npm-run-all` command
|
5 |
|
6 | ```
|
7 | Usage:
|
8 | $ npm-run-all [--help | -h | --version | -v]
|
9 | $ npm-run-all [tasks] [OPTIONS]
|
10 |
|
11 | Run given npm-scripts in parallel or sequential.
|
12 |
|
13 | <tasks> : A list of npm-scripts' names and Glob-like patterns.
|
14 |
|
15 | Options:
|
16 | -c, --continue-on-error - Set the flag to continue executing
|
17 | other/subsequent tasks even if a task threw an
|
18 | error. 'npm-run-all' itself will exit with
|
19 | non-zero code if one or more tasks threw error(s)
|
20 | --max-parallel <number> - Set the maximum number of parallelism. Default is
|
21 | unlimited.
|
22 | --npm-path <string> - - - Set the path to npm. Default is the value of
|
23 | environment variable npm_execpath.
|
24 | If the variable is not defined, then it's "npm."
|
25 | In this case, the "npm" command must be found in
|
26 | environment variable PATH.
|
27 | -l, --print-label - - - - Set the flag to print the task name as a prefix
|
28 | on each line of output. Tools in tasks may stop
|
29 | coloring their output if this option was given.
|
30 | -n, --print-name - - - - Set the flag to print the task name before
|
31 | running each task.
|
32 | -p, --parallel <tasks> - Run a group of tasks in parallel.
|
33 | e.g. 'npm-run-all -p foo bar' is similar to
|
34 | 'npm run foo & npm run bar'.
|
35 | -r, --race - - - - - - - Set the flag to kill all tasks when a task
|
36 | finished with zero. This option is valid only
|
37 | with 'parallel' option.
|
38 | -s, --sequential <tasks> - Run a group of tasks sequentially.
|
39 | --serial <tasks> e.g. 'npm-run-all -s foo bar' is similar to
|
40 | 'npm run foo && npm run bar'.
|
41 | '--serial' is a synonym of '--sequential'.
|
42 | --silent - - - - - - - - Set 'silent' to the log level of npm.
|
43 |
|
44 | Examples:
|
45 | $ npm-run-all --serial clean lint build:**
|
46 | $ npm-run-all --parallel watch:**
|
47 | $ npm-run-all clean lint --parallel "build:** -- --watch"
|
48 | $ npm-run-all -l -p start-server start-browser start-electron
|
49 | ```
|
50 |
|
51 | ### npm-scripts
|
52 |
|
53 | It's `"scripts"` field of `package.json`.
|
54 | For example:
|
55 |
|
56 | ```json
|
57 | {
|
58 | "scripts": {
|
59 | "clean": "rimraf dist",
|
60 | "lint": "eslint src",
|
61 | "build": "babel src -o lib"
|
62 | }
|
63 | }
|
64 | ```
|
65 |
|
66 | We can run a script with `npm run` command.
|
67 | On the other hand, this `npm-run-all` command runs multiple scripts in parallel or sequential.
|
68 |
|
69 | ### Run scripts sequentially
|
70 |
|
71 | ```
|
72 | $ npm-run-all clean lint build
|
73 | ```
|
74 |
|
75 | This is same as `npm run clean && npm run lint && npm run build`.
|
76 |
|
77 | **Note:** If a script exited with non zero code, the following scripts are not run.
|
78 | If `--continue-on-error` option is given, this behavior will be disabled.
|
79 |
|
80 | ### Run scripts in parallel
|
81 |
|
82 | ```
|
83 | $ npm-run-all --parallel lint build
|
84 | ```
|
85 |
|
86 | This is similar to `npm run lint & npm run build`.
|
87 |
|
88 | **Note1:** If a script exited with a non-zero code, the other scripts and those descendant processes are killed with `SIGTERM` (On Windows, with `taskkill.exe /F /T`).
|
89 | If `--continue-on-error` option is given, this behavior will be disabled.
|
90 |
|
91 | **Note2:** `&` operator does not work on Windows' `cmd.exe`. But `npm-run-all --parallel` works fine there.
|
92 |
|
93 | ### Run a mix of sequential and parallel scripts
|
94 |
|
95 | ```
|
96 | $ npm-run-all clean lint --parallel watch:html watch:js
|
97 | ```
|
98 |
|
99 | 1. First, this runs `clean` and `lint` sequentially / serially.
|
100 | 2. Next, runs `watch:html` and `watch:js` in parallel.
|
101 |
|
102 | ```
|
103 | $ npm-run-all a b --parallel c d --sequential e f --parallel g h i
|
104 | ```
|
105 | or
|
106 |
|
107 | ```
|
108 | $ npm-run-all a b --parallel c d --serial e f --parallel g h i
|
109 | ```
|
110 |
|
111 | 1. First, runs `a` and `b` sequentially / serially.
|
112 | 2. Second, runs `c` and `d` in parallel.
|
113 | 3. Third, runs `e` and `f` sequentially / serially.
|
114 | 4. Lastly, runs `g`, `h`, and `i` in parallel.
|
115 |
|
116 | ### Glob-like pattern matching for script names
|
117 |
|
118 | We can use [glob]-like patterns to specify npm-scripts.
|
119 | The difference is one -- the separator is `:` instead of `/`.
|
120 |
|
121 | ```
|
122 | $ npm-run-all --parallel watch:*
|
123 | ```
|
124 |
|
125 | In this case, runs sub scripts of `watch`. For example: `watch:html`, `watch:js`.
|
126 | But, doesn't run sub-sub scripts. For example: `watch:js:index`.
|
127 |
|
128 | ```
|
129 | $ npm-run-all --parallel watch:**
|
130 | ```
|
131 |
|
132 | If we use a globstar `**`, runs both sub scripts and sub-sub scripts.
|
133 |
|
134 | `npm-run-all` reads the actual npm-script list from `package.json` in the current directory, then filters the scripts by glob-like patterns, then runs those.
|
135 |
|
136 | ### Run with arguments
|
137 |
|
138 | We can enclose a script name or a pattern in quotes to use arguments.
|
139 | The following 2 commands are similar.
|
140 |
|
141 | ```
|
142 | $ npm-run-all --parallel "build:* -- --watch"
|
143 | $ npm run build:aaa -- --watch & npm run build:bbb -- --watch
|
144 | ```
|
145 |
|
146 | When we use a pattern, arguments are forwarded to every matched script.
|
147 |
|
148 | ### Argument placeholders
|
149 |
|
150 | We can use placeholders to give the arguments preceded by `--` to scripts.
|
151 |
|
152 | ```
|
153 | $ npm-run-all build "start-server -- --port {1}" -- 8080
|
154 | ```
|
155 |
|
156 | This is useful to pass through arguments from `npm run` command.
|
157 |
|
158 | ```json
|
159 | {
|
160 | "scripts": {
|
161 | "start": "npm-run-all build \"start-server -- --port {1}\" --"
|
162 | }
|
163 | }
|
164 | ```
|
165 |
|
166 | ```
|
167 | $ npm run start 8080
|
168 |
|
169 | > example@0.0.0 start /path/to/package.json
|
170 | > npm-run-all build "start-server -- --port {1}" -- "8080"
|
171 | ```
|
172 |
|
173 | There are the following placeholders:
|
174 |
|
175 | - `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd.
|
176 | - `{@}` -- All arguments.
|
177 | - `{*}` -- All arguments as combined.
|
178 |
|
179 | Those are similar to [Shell Parameters](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters). But please note arguments are enclosed by double quotes automatically (similar to npm).
|
180 |
|
181 | ### Known Limitations
|
182 |
|
183 | - If `--print-label` option is given, some tools in scripts might stop coloring their output.
|
184 | Because some coloring library (e.g. [chalk]) will stop coloring if `process.stdout` is not a TTY.
|
185 | `npm-run-all` changes the `process.stdout` of child processes to a pipe in order to add labels to the head of each line if `--print-label` option is given.<br>
|
186 | For example, [eslint] stops coloring under `npm-run-all --print-label`. But [eslint] has `--color` option to force coloring, we can use it. For anything [chalk] based you can set the environment variable `FORCE_COLOR=1` to produce colored output anyway.
|
187 |
|
188 | [glob]: https://www.npmjs.com/package/glob#glob-primer
|
189 | [chalk]: https://www.npmjs.com/package/chalk
|
190 | [eslint]: https://www.npmjs.com/package/eslint
|