jsenv-brunch
jsenv-brunch copied to clipboard
Allow casting and type definitions
If you want to load an integer or a boolean from an environment variable you will quickly find that you have a lot of values that look like "3"
or "true"
. It would currently be possible to write some helper functions in your jsenv file and then call those on each variable but it seems like this may be a common task (it is for my team at least) and could possibly be made easier.
A backwards compatible solution could be something like this: config.jsenv
{
"API_HOST": "http://my.host",
"__ints__": {
"API_VERSION": 3
},
"__bools__": {
"API_ENABLED": true
}
}
when run with API_ENABLED=no brunch build
would compile to:
exports.module = {
"API_HOST": "https://dev.apihost.com",
"API_VERSION": 3,
"API_ENABLED": false
}
I'm in no way married to this approach if someone has a better suggestion. If this is something you think others may be interested in I'm happy to throw a pull request up.