@smpx/cfg
Advanced tools
Comparing version 1.3.0 to 1.4.0
11
index.js
@@ -70,3 +70,12 @@ const path = require('path'); | ||
const key = val.slice(5).split('__').map(el => _.camelCase(el)).join('.'); | ||
cfg.set(key, process.env[val]); | ||
let envVal = process.env[val]; | ||
if (envVal && envVal.startsWith('@JSON:')) { | ||
try { | ||
envVal = JSON.parse(envVal.substring(6)); | ||
} | ||
catch (e) { | ||
console.error(`Error while parsing JSON value of env variable ${val}`); | ||
} | ||
} | ||
cfg.set(key, envVal); | ||
}); | ||
@@ -73,0 +82,0 @@ } |
{ | ||
"name": "@smpx/cfg", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Configuration management for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,3 +54,5 @@ # cfg | ||
# Adding host to posiition 1 (hosts.1): | ||
CFG__HOSTS_1='new-host.region.rds.amazonaws.com' yarn start | ||
CFG__HOSTS__1='new-host.region.rds.amazonaws.com' yarn start | ||
# Override all hosts | ||
CFG__HOSTS='@JSON:["a.b", "c.d"]' yarn start | ||
``` | ||
@@ -60,3 +62,3 @@ | ||
It basically uses lodash.set internally. The path is generated by removing the `CFG__` prefix and replacing `__` with `.` and converting each word in between to camelCase (also through lodash). | ||
It basically uses lodash.set internally. The path is generated by removing the `CFG__` prefix and replacing `__` with `.` and converting each word in between to camelCase (also through lodash). If the value starts with `@JSON:`, it will be parsed as JSON (after removing `@JSON:`), so you can use it to set arrays, objects and numbers. | ||
@@ -63,0 +65,0 @@ ### NODE_ENV & CI overrides |
19406
602
90