index | npm-run-all | run-s | run-p | Node API |
---|
A Node module to run given npm-scripts in parallel or sequential.
const runAll = require("npm-run-all");
runAll(["clean", "lint", "build:*"], {parallel: false})
.then(() => {
console.log("done!");
})
.catch(err => {
console.log("failed!");
});
runAll(["build:* -- --watch"], {parallel: true})
.then(() => {
console.log("done!");
})
.catch(err => {
console.log("failed!");
});
let promise = runAll(patterns, options);
Run npm-scripts.
string|string[]
-- Glob-like patterns for script names.object
boolean
--
The flag to avoid interleaving output by delaying printing of each command's output until it has finished.
This option is valid only with options.parallel
option.
Default is false
.string[]
--
An argument list to replace argument placeholders (such as {1}
, {2}
). If pattern text has {1}
, it's replaced by options.arguments[0]
.
Default is an empty array.boolean
--
The flag to continue executing other/subsequent scripts even if a script threw an error.
Returned Promise
object will be rejected if one or more scripts threw error(s).
Default is false
.boolean
--
The flag to run scripts in parallel.
Default is false
.number
--
The maximum number of parallelism.
This option is valid only with options.parallel
option.
Default is Number.POSITIVE_INFINITY
.string
--
The path to npm.
Default is process.env.npm_execpath
or "npm"
.object|null
--
The map-like object to overwrite package configs.
Keys are package names.
Every value is a map-like object (Pairs of variable name and value).
e.g. {"npm-run-all": {"test": 777, "test2": 333}}
Default is null
.boolean
--
Set the flag to print the task name as a prefix on each line of output.
Tools in scripts may stop coloring their output if this option is given.
Default is false
.boolean
--
Set the flag to print the task name before running each task.
Default is false
.boolean
--
Set the flag to kill all npm-scripts when a npm-script finished with zero.
This option is valid only with options.parallel
option.
Default is false
.boolean
--
The flag to set silent
to the log level of npm.
Default is false
.stream.Readable|null
--
The readable stream to send to the stdin of npm-scripts.
Default is nothing.
Set process.stdin
in order to send from stdin.stream.Writable|null
--
The writable stream to receive from the stdout of npm-scripts.
Default is nothing.
Set process.stdout
in order to print to stdout.stream.Writable|null
--
The writable stream to receive from the stderr of npm-scripts
Default is nothing.
Set process.stderr
in order to print to stderr.string[]|null
--
The string array of all script names.
If this is null
, it reads from package.json
in the current directory.
Default is null
.runAll
returns a promise that will becomes fulfilled when all scripts are completed.
The promise will become rejected when any of the scripts exit with a non-zero code.
The promise gives results
to the fulfilled handler.
results
is an array of objects which have 2 properties: name
and code
.
The name
property is the name of a npm-script.
The code
property is the exit code of the npm-script. If the npm-script was not executed, the code
property is undefined
.
runAll(["clean", "lint", "build"])
.then(results => {
console.log(`${results[0].name}: ${results[0].code}`); // clean: 0
console.log(`${results[1].name}: ${results[1].code}`); // lint: 0
console.log(`${results[2].name}: ${results[2].code}`); // build: 0
});
options.stdin
, options.stdout
, or options.stderr
in parallel mode, please configure max listeners by emitter.setMaxListeners(n) properly.process.stdXXX.isTTY
is false
, please configure max listeners of the process.stdXXX
properly. In that case, npm-run-all
uses piping to connect to child processes.process.stdXXX.isTTY
is true
, npm-run-all
uses inherit
option, so the configuration is unnecessary.