A wrapper for child_process for nodejs CLI apps
npm install @node-cli/run!npm
> @node-cli/run is a dead-simple script runner for nodejs command-line applications.
``sh`
> cd your-project
> npm install --save-dev @node-cli/run
`js`
import { run } from "@node-cli/run";
const { stdout, stderr } = await run("npm config ls");
run(command, options) ⇒ Promise | Promise
Runs a shell command asynchronously and returns both stdout and stderr. If the command fails to run (invalid command or the commands status is anything but 0), the call will throw an exception. The exception can be ignored if the options.ignoreError flag is true.
| Argument | Type | Default |
| -------------------- | ------- | ------- |
| command | String | "" |
| options | Object | { } |
| options.ignoreError | Boolean | false |
| options.streamOutput | Boolean | false |
If ignoreError is used, the method will not throw but will instead return an object with the keys exitCode and shortMessage.
#### Examples
##### Basic usage
`js`
import { run } from "@node-cli/run";
const { stdout, stderr } = await run("npm run build");
##### Multiple commands
`js`
import { run } from "@node-cli/run";
const { stdout, stderr } = await run(
"git add -A && git commit -a -m 'First commit'"
);
##### Stream output
`js`
import { run } from "@node-cli/run";
await run("npm run build", {
streamOutput: true
});
##### Ignore error
`js``
import { run } from "@node-cli/run";
const { exitCode, shortMessage } = await runCommand("ls /not-a-folder", {
ignoreError: true
});
// -> exitCode is 1 and shortMessage is "Command failed with exit code 1: ls /not-a-folder"
MIT © Arno Versini