@watchmen/configr
v3.0.2
Published
config helper
Downloads
50
Readme
node-configr
config helper
see tests for examples
usage
npm i @watchmen/configrimport {...} from '@watchmen/configr'
configuration sources
CONFIGR_SOURCES={source},{source},...
where a source can be a url or a relative file path
when processing a source, the file will b a template which could result in multiple files being processed
example: ./config/values.yaml
values.yaml becomes the template which will be processed as a sequence of files, if the files exist, and be processed sequentially where each subsequent file has precedence.
the sequence is based on the following:
- environment
- specified in a variable named
ENVIRONMENT- of form
[{modifier}-]{base}- optional
{modifier}could be anything likefoo {base}would be one of discrete set of base environments like [dev,test,prod]
- optional
- of form
- specified in a variable named
- git branch
- specified in variable named
GITHUB_REF_NAME- of form
{trunk}[-{modifier}] {trunk}would be something likemain- optional
{modifier}coudld be anything likefoo
- of form
- specified in variable named
- examples
- (no modifiers): environment=
dev, branch=main- sequence
values.yamlvalues.dev.yaml
- sequence
- (with modifiers): environment=
foo-dev, branch=main-bar- sequence
values.yamlvalues.bar.yamlvalues.foo.yamlvalues.dev.yamlvalues.foo-dev.yaml
- sequence
- (no modifiers): environment=
configuration environment variables
every element can be specified/overridden with an environment variable
let's say that after parsing of sources that the resultant structure looks like the following:
# discrete val
#
root:
key-1: val-1
# list val
#
key-2:
- val-2-1
- val-2-2
# map val
#
key-3:
key-3-1: val-3-1
key-3-2: val-3-2root.key-1can be specified with an environment-variableROOT__KEY_1=val-1-xroot.key-2can be specified with an env-var likeROOT__KEY_2=[val-2-1-x, val-2-2-x]root.key-3.key-3-1can be specified with an env-var likeROOT__KEY_3__KEY_3_1=val-3-2-x
note the use of a double-underscore
__to imply a nested value strategy lifted from the dynaconf python based configuration package
development
git clone {repo name}cd {repo name}npm inpm test
