jsenv-brunch icon indicating copy to clipboard operation
jsenv-brunch copied to clipboard

Allow casting and type definitions

Open mattdodge opened this issue 8 years ago • 0 comments

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.

mattdodge avatar Oct 11 '16 18:10 mattdodge