npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

run-scripts-util

v1.2.5

Published

Organize npm package.json scripts into named groups of easy to manage commands (CLI tool designed for use in npm package.json scripts)

Downloads

521

Readme

run-scripts-util

Organize npm package.json scripts into named groups of easy to manage commands (CLI tool designed for use in npm package.json scripts)

License:MIT npm Build

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",
   "graphics": "copy-folder src/graphics build/my-app/graphics",
   "compile-html": "replacer src/web-app --ext=.html build/my-app",
   "pretest": "npm run clean && npm run compile-ts && npm run compile-less && npm run graphics && npm run compile-html",
   "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",
      "copy-folder src/graphics build/my-app/graphics",
      "replacer src/web-app --ext=.html build/my-app"
   ]
},
"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).

screenshot

A) Setup

Install package for node:

$ npm install --save-dev run-scripts-util

B) Usage

1. npm package.json scripts

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",
   },

2. CLI flags

Command-line flags: | Flag | Description | Value | | ------------ | ------------------------------------------------------ | ---------- | | --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 |

3. Example CLI usage

Examples:

  • run-scripts clean compile Executes the clean group of commands and then execute the compile 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 the compile group.

  • run-scripts lint watch --parallel Executes all the lint commands in parallel and then after all the commands are finished executes the watch commands in parallel.

Note: Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows.

4. Skip a command

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"
  ]
}

5. Debug a command

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

C) Application Code

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-headerPrepend a one-line banner comment (with license notice) to distribution files
  • 📄 copy-file-utilCopy or rename a file with optional package version number
  • 📂 copy-folder-utilRecursively copy files from one folder to another folder
  • 🪺 recursive-execRun a command on each file in a folder and its subfolders
  • 🔍 replacer-utilFind and replace strings or template outputs in text files
  • 🔢 rev-web-assetsRevision web asset filenames with cache busting content hash fingerprints
  • 🚆 run-scripts-utilOrganize npm package.json scripts into named groups of easy to manage commands
  • 🚦 w3c-html-validatorCheck the markup validity of HTML files using the W3C validator

Feel free to submit questions at: github.com/center-key/run-scripts-util/issues

MIT License