UNPKG

@jvhaile/loopback4-helper

Version:
44 lines (39 loc) 1.2 kB
function flattenObject(object: any) { const keys = Object.keys(object); let flat: any = {}; keys.map(key => { const value = object[key]; if (typeof value == 'object') { const flatten = flattenObject(value); Object.keys(flatten).forEach(subKey => { flat[`${key}.${subKey}`] = flatten[subKey]; }) } flat[key] = value; }); return flat; } export default function configure(env: string, configurationPath: string, onEach: (key: string, value: any) => void) { let configFile = { config: {} } let envConfigFile = { config: {} } try { configFile = require(`../../../../${configurationPath}/config.default`); } catch (e) { console.log(e); } try { envConfigFile = require(`../../../../${configurationPath}/config.${env}`); } catch (e) { console.log(e); } const config = { ...configFile.config, ...envConfigFile.config, }; const flatConfig = flattenObject(config); Object.keys(flatConfig).forEach(key => onEach(key, flatConfig[key])); }