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

npm-run-batch

v0.0.9

Published

npm run-script helper that allows running a bunch of run-scripts - in series or parallel!

Downloads

818

Readme

npm-run-batch

npm license travis status Build status David David NPM

npm run-script helper that allows running multiple run-scripts in series & parallel

npm-run-batch allows npm to be used as a build tool with a minimum of fuss.

It's not uncommon to see npm run-scripts that look like this:

"prebuild": "npm run build:clean && npm run test",
"build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p",
"build:clean": "npm run test:clean && rimraf ./build",
"build:dll": "node ./internals/scripts/dependencies.js",

As project complexity grows, these become harder to comprehend and debug.

To tackle this (and other things, but I never claim impartiality!), multiple build/automation tools have been craated gulp, grunt, brunch and that is not even the whole list.

However, this is not without debate.

A persistent source of complexity with using npm as a build tool are the pesky && to chain commands together. Further, one cannot run multiple commands in parallel. Here's a good example why that can be necessary.

npm-run-batch attempts to solve the problem of composing complex automation flows for npm-as-a-build-tool. It provides simple semantics, aids clarity and requires almost no extra installed weight.

Prove it!

"scripts": {
  "rimraf": "rimraf ./build",
  "webpack": "webpack --config internals/webpack/webpack.prod.bable.js --color -p",
  "build:dll": "node ./internals/scripts/dependencies.js",
  "test": "mocha",

  "build:clean": "npm-run-batch",
  "build": "cross-env NODE_ENV=production npm-run-batch"
},
"run-batch": {
  "build:clean": [
    "test:clean",
    "rimraf"
  ],
  "build": [
    "build:clean",
    "test",
    "webpack"
  ]
}

Installation

npm install npm-run-batch

Usage

The module exposes two binary aliases -

npm-run-batch
run-batch

These are meant to be invoked from npm-run scripts and used for the grouping of batch sequences as we shall see next.

In your package.json, define tasks as usual, but they do only one thing. The batch operations are the ones that are the meat of your run-script.

"scripts": {
  "task:1": "a simple task",
  "task:2": "a simple task",
  "task:3": "a simple task",
  "task:4": "a simple task",
  "batch:1": "run-batch",
  "batch:2": "run-batch"
}

Once the batch tasks have been tagged (either of the aliases will work),

  1. Add a "run-batch" segment to your package.json

  2. For each batch run-script, add a key to the "run-batch" section.

  3. Each "run-batch" segment is a list of run-scripts that you want to run.

  4. At each stage, run-scripts can be run in parallel if you add an array as shown for "batch:2" below.

    "run-batch": { "batch:1": [ "task:1", "task:2" ], "batch:2": [ "task:1", [ "task:2", "task:3" ], // Parallel tasks "task:4" ] }

Importantly, we allow for both aliases to be used interchangeably. If both aliases are present in package.json for batching, "run-batch" takes precedence over "npm-run-batch".

That's all there is to it!

Working Example

Please see package.json for a few working examples. Because we can't install the package within itself, instead of the alias run-batch, we use node ./index.js. With that caveat, this should work as described.

  • notice the use of cross-env to pass the environment forward.
  • for true cross-platform independence, we highly recommend using shelljs

Feedback of all kinds is welcome.

License

Apache-2.0