cross-env-test
v0.1.1
Published
Test environment variables across operating system environments
Downloads
653
Maintainers
Readme
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
orlh!=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