Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heapwolf/test-env
Conditional output based on an environment variable
https://github.com/heapwolf/test-env
Last synced: 25 days ago
JSON representation
Conditional output based on an environment variable
- Host: GitHub
- URL: https://github.com/heapwolf/test-env
- Owner: heapwolf
- Created: 2013-12-20T19:56:37.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2013-12-26T15:29:30.000Z (almost 11 years ago)
- Last Synced: 2024-10-18T17:05:28.030Z (26 days ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![build-status](https://www.codeship.io/projects/50ca8900-4c7b-0131-1043-328a0651e296/status)](https://www.codeship.io/projects/11256)
# SYNOPSIS
Bash programming does not read clearly inside a `package.json` script field.
This program helps test environment variables and create conditional output.# EXAMPLE
`package.json` scripts likely want some context about their environment. In
this example we want to add the `--debug` flag to the `browserify` program
before we run it, but only if the `NODE_ENV` environment variable has not
been set.```json
"scripts": {
"build-js": "browserify $(test-env !NODE_ENV '--debug') browser/*.js > static/bundle.js"
}
```# USAGE
## TESTING
If the variable exists, the second argument will be written to `stdout`. If the test is false,
and a third variable is supplied it will be printed.```bash
$test-env VARIABLE_NAME Yes
``````bash
$test-env VARIABLE_NAME Yep Nope
```If the variable does not exist, the second argument will be written to `stdout`. If the test
is false, and a third variable is supplied it will be printed.```bash
$test-env !USER "Yeah ok, sure"
``````bash
$test-env !USER 1 2
```## COMPARING
The comparison operators are supported- `==` (or `eq`) Equal
- `!=` (or `not`) Not Equal
- `gt` Greater Than
- `lt` Less Than
- `gte` Greater Than or Equal To
- `lte` Less Than or Equal To```bash
$test-env SHLVL == 2 Yep Nope
Yep
``````bash
$test-env SHLVL gte 1 OK "NOT OK"
OK
```