This lib is about to merge config files in JSON and YAML.
The name of the config file is important to separate the config data ${configName}.${extension}
or ${configName}_${siteId}.${extension}
.
The siteID usually 3-6 letter identifier, for example:
forms_customer.yml
it's just for the default configforms_customer_bkit.yml
will be theforms_customer
for config name to the sitebkit
Before to fetch the configs is necessary to load the config data for this you need to call the function loadAllConfigsInFolder
.
If you do not pass the folder of configs as a parameter to loadAllConfigsInFolder
the files will be found in the path configured in the env READER_CONFIG_FOLDER
, this function returns a promise.
To fetch the configs you want you must call the getConfig
function, this function receives three parameters config name
, siteId
and environment
, the production key is used as default.
The data need to be load just one time.
loadAllConfigsInFolder('./config_files_folder').then(() => {
console.log(getConfig('forms_customer', 'bkit', 'staging'));
});
Every hash will be deep merged and the preference always will be the siteID config.
The production keys is used to fill the empty keys for other environments config, for example:
"config": {
"active": false,
"number": "123",
"baseUri": "https://productionurl.com",
}
"development": {
"config": {
"baseUri": "https://test.com"
}
}
"config": {
"active": false,
"number": "123",
"baseUri": "https://test.com",
}
For configs in an array the objects will be merged with the more similar config found in the array, for example:
`` listConfig: - type: String name: potato label: vegetable fry: true amount: 5
- type: String
name: strawberry
label: fruit
sweet: false
listConfig:
- type: String
name: potato
- type: String
name: strawberry
label: fruit
sweet: true
amount: 100
listConfig:
- type: String
name: potato
label: vegetable
fry: true
amount: 5
- type: String
name: strawberry
label: fruit
sweet: true
amount: 100