Chore: Add capability for overriding local development behaviour using env vars (#85603)

This commit is contained in:
Tom Ratcliffe
2024-08-13 13:07:42 +01:00
committed by GitHub
parent 735954386f
commit 8136fbef1f
8 changed files with 218 additions and 34 deletions

View File

@ -0,0 +1,29 @@
const { parse } = require('ini');
const { readFileSync, existsSync } = require('node:fs');
const getEnvConfig = () => {
const defaultSettings = readFileSync(`./conf/defaults.ini`, {
encoding: 'utf-8',
});
const customSettings = existsSync(`./conf/custom.ini`)
? readFileSync(`./conf/custom.ini`, {
encoding: 'utf-8',
})
: '';
const defaults = parse(defaultSettings);
const custom = parse(customSettings);
const merged = { ...defaults.frontend_dev, ...custom.frontend_dev };
// Take all frontend keys from the ini file and prefix with `frontend_dev_`,
// so they can be added to `process.env` elsewhere
return Object.entries(merged).reduce((acc, [key, value]) => {
return {
...acc,
[`frontend_dev_${key}`]: value,
};
}, {});
};
module.exports = getEnvConfig;