cross-env-test

0.1.1 • Public • Published

cross-env-test

This command line tool works on *NIX (including OS X) and Windows. This tool checks to see if an environment variable is set to a given value:

cross-env-test NODE_ENV=testing

if NODE_ENV is set to testing the program will exit with 0 otherwise it will exit with a non-zero value

The logic is very close to:

if (process.env.NODE_ENV === 'testing') {
  process.exit(0);
} else {
  process.exit(1);
}
 

Usage I use this in my npm scripts:

{
  "scripts": {
    "postinstall": "cross-env-test NODE_ENV=testing || npm run build"
  }
}

Why?

Sometimes it's advantages to only run certain npm scripts sometimes. For example when running an install in an automated test environment.

Limitations

  • only supports '=' and '!=' operators
  • environment variable must be on the left hand side of the operator
  • arguments not in the form of lh=rh or lh!=rh will cause the program to exit with an error code
  • chained arguments are implicitly &&ed together
  • if there is interest we can add a --or modifier

License

MIT

Package Sidebar

Install

npm i cross-env-test

Weekly Downloads

250

Version

0.1.1

License

MIT

Last publish

Collaborators

  • bennett000