@xarc/run
npm run enhanced.
- Compatible with npm run for [npm scripts]
- Run them concurrently or serially
- Extend them with JavaScript
- Group them with namespace
- and more
Running [npm scripts]
This module provides a command xrun to run all your [npm scripts] in package.json.
And you can run multiple of them concurrently or serially.
Some examples below:
| what you want to do | npm command | xrun command | | ----------------------------------- | -------------- | ------------------------- | | run test | npm run test | xrun test | | run lint and test concurrently | N/A | xrun lint test | | run lint and then test serially | N/A | xrun --serial lint test |
Alias for the options:
- -s: --serial
Running JavaScript tasks
You can write your tasks in JavaScript and run them with xrun.
This is useful when a shell script is too long to fit in a JSON string, or when it's not easy to do something with shell script.
These APIs are provided: concurrent, serial, exec, env, and load.
Put your tasks in a file xrun-tasks.js and xrun will load it automatically.
An example xrun-tasks.js:
const { load, exec, concurrent, serial } = require("@xarc/run");
load({
//
// define a task hello, with a string definition
// because a string is the task's direct value, it will be executed as a shell command.
//
hello: "echo hello",
//
// define a task world, using a JavaScript function to print something
//
world: () => console.log("world"),
//// the hello and world tasks defined above, and 3rd one is a shell command defined with exec. // because the 3rd one is not a direct value of a task, it has to use exec to define a shell command. // serialTask: serial("hello", "world", exec("echo hi from exec")), // // define a task concurrentTask, that will execute the three tasks concurrently // concurrentTask: concurrent("hello", "world", exec("echo hi from exec")), // // define a task nesting, that does complex nesting of concurrent/serial constructs // nesting: concurrent(serial("hello", "world"), serial("serialTask", concurrent("hello", "world"))) });