https://github.com/megahertz/if-prod
Conditional running of npm scripts depending on environment
https://github.com/megahertz/if-prod
Last synced: 12 months ago
JSON representation
Conditional running of npm scripts depending on environment
- Host: GitHub
- URL: https://github.com/megahertz/if-prod
- Owner: megahertz
- Created: 2018-08-30T09:03:35.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-30T12:34:07.000Z (almost 8 years ago)
- Last Synced: 2025-06-29T17:01:58.262Z (12 months ago)
- Language: Shell
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# if-prod
[](https://travis-ci.org/megahertz/if-prod)
[](https://badge.fury.io/js/if-prod)
[](https://david-dm.org/megahertz/if-prod)
## Description
This tiny script allows to simplify conditional statements which check
for the current environment from $NODE_ENV. Consider the following
package.json:
```json
"scripts": {
"start": "if [[ \"${NODE_ENV}\" == \"production\" ]]; then node dist/server.js; else webpack --watch; fi",
}
```
The following code is hard for reading and doesn't work on Windows. It
can be simplified using this package:
```json
"scripts": {
"start": "if-prod && node dist/server.js || webpack --watch",
}
```
## Installation
Install with [npm](https://npmjs.org/package/if-prod):
npm install if-prod
## Usage
There are the following commands in this package:
- if-prod
- if-dev
- if-env-is ENVIRONMENT NAME
- if-not-prod
- if-not-dev
- if-not-env-is ENVIRONMENT NAME
### Examples
- **if/then/else**
`if-prod && node dist/server.js || webpack --watch`
- **single if**
`if-prod && node dist/server.js || true` - without `|| true` this
command returns status code 1 if the current environment is
not "production"
- **if not**
`if-not-prod && rm -rf dist || true` - run in all environment except
"production"
- **custom environment**
`if-env-is test && rm -rf coverage || true`
## Related projects
[ericclemmons/if-env](https://github.com/ericclemmons/if-env) - almost
the same approach but can check for any environment variables, not only
$NODE_ENV
[ericclemmons/per-env](https://github.com/ericclemmons/per-env) -
environment-driven npm scripting
## License
Licensed under MIT.