Organize npm package.json scripts into groups of easy to manage commands (CLI tool designed for use in npm package.json scripts)
run-scripts-util reads the runScriptsConfig
settings in your package.son to get
groups (arrays) of commands to execute.
Turn the traditional hard-to-follow commands:
"scripts": {
"clean": "rimraf build dist",
"compile-ts": "tsc",
"compile-less": "lessc src/web-app/style.less build/web-app/style.css",
"compile-html": "replacer src/web-app --ext=.html build/web-app",
"graphics": "copy-folder src/graphics build/web-app/graphics",
"pretest": "npm run clean && npm run compile-ts && npm run compile-less && npm run compile-html && npm run graphics",
"test": "mocha spec"
},
into easy-to-read named groups (arrays) of commands:
"runScriptsConfig": {
"clean": [
"rimraf build dist"
],
"compile": [
"tsc",
"lessc src/web-app/style.less build/web-app/style.css",
"replacer src/web-app --ext=.html build/web-app",
"copy-folder src/graphics build/web-app/graphics"
]
},
"scripts": {
"pretest": "run-scripts clean compile",
"test": "mocha spec"
},
Each group of commands is executed in order, and the commands within each group are by default executed in serial (synchronously) but can optionally be executed in parallel (asynchronously).
Install package for node:
$ npm install --save-dev run-scripts-util
Use run-scripts
in the "scripts"
section of your package.json file and add a
parameter naming the key in runScriptsConfig
holding the group (array) of commands to
execute.
Example package.json scripts:
"scripts": {
"build": "run-scripts clean compile",
},
Command-line flags:
Flag | Description | Value |
---|---|---|
--continue-on-error |
Do not throw an exception if a task exits with an error status. | N/A |
--note |
Place to add a comment only for humans. | string |
--only |
Execute just one command in the group (starts with 1). | number |
--parallel |
Execute all commands within each group asynchronously. | N/A |
--quiet |
Suppress informational messages. | N/A |
--verbose |
Add script group name to informational messages. | N/A |
Examples:
-
run-scripts clean compile
Executes theclean
group of commands and then execute thecompile
group fo commands. -
run-scripts clean compile --quiet
Does not display information messages. -
run-scripts clean compile --quiet '--note=Listen to silence'
Notes are handy for adding a short comment. -
run-scripts compile --verbose --only=2
Executes just the second command in thecompile
group. -
run-scripts lint watch --parallel
Executes all thelint
commands in parallel and then after all the commands are finished executes thewatch
commands in parallel.
Note: Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows.
To comment out a command prepend two slashes (//
) to the command.
In the example below, the first tsc
command will be skipped while the tsc --verbose
command will be executed:
"runScriptsConfig": {
"compile": [
"//tsc",
"tsc --verbose",
"lessc src/web-app/style.less build/web-app/style.css"
]
}
To manually run a single command, use npx
from the terminal plus the --only
flag.
For example, to run the third command in the compile
group by itself:
$ npx run-scripts compile --only=3
Even though run-scripts-util is primarily intended for build scripts, the package can be used programmatically in ESM and TypeScript projects.
Example:
import { runScripts } from 'run-scripts-util';
const options = { quiet: false };
runScripts.exec('compile', options);
runScripts.execParallel('watch', options);
See the TypeScript Declarations at the top of run-scripts.ts for documentation.
CLI Build Tools for package.json
- ๐ add-dist-header:ย Prepend a one-line banner comment (with license notice) to distribution files
- ๐ copy-file-util:ย Copy or rename a file with optional package version number
- ๐ copy-folder-util:ย Recursively copy files from one folder to another folder
- ๐ชบ recursive-exec:ย Run a command on each file in a folder and its subfolders
- ๐ replacer-util:ย Find and replace strings or template outputs in text files
- ๐ข rev-web-assets:ย Revision web asset filenames with cache busting content hash fingerprints
- ๐ run-scripts-util:ย Organize npm package.json scripts into groups of easy to manage commands
- ๐ฆ w3c-html-validator:ย Check the markup validity of HTML files using the W3C validator
Feel free to submit questions at:
github.com/center-key/run-scripts-util/issues