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-on

v0.2.4

Published

Better NPM scripts runner with special addon for platform specific runs

Downloads

11

Readme

NPM

Linux Build Status

PRs Welcome

Intro

Better NPM scripts runner

  • Avoid hard-coded commands in package.json
  • Cross-platform compatibility, originally needed by:
    • https://github.com/formly-js/angular-formly/issues/305
      • https://github.com/npm/npm/issues/2800

Inspired by

  • https://www.npmjs.com/package/with-package

Alternatives

Usage in package.json

From this:

{
  "scripts": {
    "build:dist": "NODE_ENV=development webpack --config $npm_package_webpack --progress --colors",
    "test": "NODE_ENV=production karma start"
  }
}

To this:

{
  "devDependencies": {
    "run-on": "~0.0.1"
  },
  "scripts": {
    "build:dist": "run-on build:dist",
    "build:prod": "run-on build:prod",
    "test": "run-on test",
    "test:special": "run-on --on mac,linux build:dist",
    "raw:test": "run-on --on windows --raw echo 'test'"
  },
  "betterScripts": {
    "build:dist": "webpack --config $npm_package_webpack --progress --colors",
    "build:prod": {
      "command": "webpack --config $npm_package_webpack --progress --colors",
      "env": {
        "NODE_ENV": "production"
      }
    },
    "test": {
      "command": "karma start",
      "env": {
        "NODE_ENV": "test"
      }
    }
  }
}

The betterScripts script definition can either be a string or sub-object with command and env attributes. Values defined in the env block will override previously set environment variables.

Note that depending on the OS and terminal you're using, dots, spaces or other special characters in the command path may be treated as separators and the command will be parsed wrong.

{
  "serve:dist": "./node_modules/.bin/webpack-dev-server --hot --inline --config webpack/development.js"
}

To prevent this you need to explicitly wrap the command path with double quotes:

{
  "serve:dist": "\"./node_modules/.bin/webpack-dev-server\" --hot --inline --config webpack/development.js"
}

.env File

If you have an .env file in your project root it will be loaded on every command.

NODE_PATH=./:./lib
NODE_ENV=development
PORT=5000

Environment variables defined in the betterScripts script definition will take precedence over .env values.

Shell scripts

Currently, using bash variables (PWD, USER, etc.) is not possible:

  "command": "forever start -l ${PWD}/logs/forever.log -o ${PWD}/logs/out.log -e ${PWD}/logs/errors.log -a index.js",

In order to use them, you can create an script file (.sh) instead:

forever.sh:

forever start -l ${PWD}/logs/forever.log -o ${PWD}/logs/out.log -e ${PWD}/logs/errors.log -a index.js

package.json:

  "command": "./forever.sh"

cli commands

This module expose 2 cli commands:

  • run-on and,
  • a shorter one: bnr which is an alias to the former.

The shorter one is useful for cases where you have a script that calls several run-on scripts. e.g:

using the normal cli name

"scripts": {
  "dev": "shell-exec 'run-on install-hooks' 'run-on watch-client' 'run-on start-dev' 'run-on start-dev-api' 'run-on start-dev-worker' 'run-on start-dev-socket'",
}

using the shorter alias

"scripts": {
  "dev": "shell-exec 'bnr install-hooks' 'bnr watch-client' 'bnr start-dev' 'bnr start-dev-api' 'bnr start-dev-worker' 'bnr start-dev-socket'",
}

And for silence output, you can use -s or verbose --silence flags

bnr -s watch-client

And you can use -p or verbose --path to specify a custom path of dotenv file

bnr --path=/custom/path/to/your/env/vars start-dev

Also use -e or verbose --encoding to specify the encoding of dotenv file

bnr --encoding=base64 start-dev

Also use -o or verbose --on to specify platform that script should run on

run-on --on linux,mac start-dev
run-on --on windows start-dev-win

Also use -r or verbose --raw to run a command in current env, like dir on windows or rm -rf ./lib on linux

run-on --raw echo 'test'
run-on --raw cross-env TEST=123 my-special-run

by using --on and --raw you can archive platform specific commands that doesn't require to write shell scripts.

run-on --on linux,windows --raw cross-env TEST=123 my-special-run && run-on --on windows --raw cross-env TEST=123 my-special-run-win

See envdot docs for more infomation

Original author: benoror

License

Copyright © 2017, Dmitry Poddubniy. Released under the MIT License.