UNPKG

4.88 kBMarkdownView Raw
1| [index](../README.md) | [npm-run-all](npm-run-all.md) | run-s | [run-p](run-p.md) | [Node API](node-api.md) |
2|-----------------------|-------------------------------|-------|-------------------|-------------------------|
3
4# `run-s` command
5
6A CLI command to run given npm-scripts sequentially.
7This command is the shorthand of `npm-run-all -s`.
8
9```
10Usage:
11 $ run-s [--help | -h | --version | -v]
12 $ run-s [OPTIONS] <tasks>
13
14 Run given npm-scripts sequentially.
15
16 <tasks> : A list of npm-scripts' names and Glob-like patterns.
17
18Options:
19 -c, --continue-on-error - Set the flag to continue executing subsequent
20 tasks even if a task threw an error. 'run-s'
21 itself will exit with non-zero code if one or
22 more tasks threw error(s).
23 --npm-path <string> - - - Set the path to npm. Default is the value of
24 environment variable npm_execpath.
25 If the variable is not defined, then it's "npm."
26 In this case, the "npm" command must be found in
27 environment variable PATH.
28 -l, --print-label - - - - Set the flag to print the task name as a prefix
29 on each line of output. Tools in tasks may stop
30 coloring their output if this option was given.
31 -n, --print-name - - - - Set the flag to print the task name before
32 running each task.
33 -s, --silent - - - - - - Set 'silent' to the log level of npm.
34
35 Shorthand aliases can be combined.
36 For example, '-clns' equals to '-c -l -n -s'.
37
38Examples:
39 $ run-s build:**
40 $ run-s lint clean build:**
41 $ run-s --silent --print-name lint clean build:**
42 $ run-s -sn lint clean build:**
43```
44
45### npm-scripts
46
47It's `"scripts"` field of `package.json`.
48For example:
49
50```json
51{
52 "scripts": {
53 "clean": "rimraf dist",
54 "lint": "eslint src",
55 "build": "babel src -o lib"
56 }
57}
58```
59
60We can run a script with `npm run` command.
61On the other hand, this `run-s` command runs multiple scripts sequentially.
62
63The following 2 commands are the same.
64The `run-s` command is shorter.
65
66```
67$ run-s clean lint build
68$ npm run clean && npm run lint && npm run build
69```
70
71**Note:** If a script exited with a non-zero code, the following scripts are not run.
72
73### Glob-like pattern matching for script names
74
75We can use [glob]-like patterns to specify npm-scripts.
76The difference is one -- the separator is `:` instead of `/`.
77
78```
79$ run-s build:*
80```
81
82In this case, runs sub scripts of `build`. For example: `build:html`, `build:js`.
83But, doesn't run sub-sub scripts. For example: `build:js:index`.
84
85```
86$ run-s build:**
87```
88
89If we use a globstar `**`, runs both sub scripts and sub-sub scripts.
90
91`run-s` reads the actual npm-script list from `package.json` in the current directory, then filters the scripts by glob-like patterns, then runs those.
92
93### Run with arguments
94
95We can enclose a script name or a pattern in quotes to use arguments.
96The following 2 commands are the same.
97
98```
99$ run-s start:server "delay 3000" start:client
100$ npm run start:server && npm run delay 3000 && npm run start:client
101```
102
103When we use a pattern, arguments are forwarded to every matched script.
104
105### Argument placeholders
106
107We can use placeholders to give the arguments preceded by `--` to scripts.
108
109```
110$ run-s build "start-server -- --port {1}" -- 8080
111```
112
113This is useful to pass through arguments from `npm run` command.
114
115```json
116{
117 "scripts": {
118 "start": "run-s build \"start-server -- --port {1}\" --"
119 }
120}
121```
122
123```
124$ npm run start 8080
125
126> example@0.0.0 start /path/to/package.json
127> run-s build "start-server -- --port {1}" -- "8080"
128```
129
130There are the following placeholders:
131
132- `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd.
133- `{@}` -- All arguments.
134- `{*}` -- All arguments as combined.
135
136Those 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).
137
138### Known Limitations
139
140- If `--print-label` option is given, some tools in scripts might stop coloring their output.
141 Because some coloring library (e.g. [chalk]) will stop coloring if `process.stdout` is not a TTY.
142 `run-s` 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>
143 For example, [eslint] stops coloring under `run-s --print-label`. But [eslint] has `--color` option to force coloring, we can use it.
144
145[glob]: https://www.npmjs.com/package/glob#glob-primer
146[chalk]: https://www.npmjs.com/package/chalk
147[eslint]: https://www.npmjs.com/package/eslint