repair #1795 Default settings in config/config.yml are ignored

This commit is contained in:
Samuel Cambien
2022-09-07 17:46:49 +02:00
parent 916d7fc13d
commit 44489fa4e0

View File

@@ -54,14 +54,28 @@ const getEnvironment = (): Environment => {
return environment; return environment;
}; };
const getLocalConfigPath = (env: Environment) => { /**
// default to config/config.yml * Get the path of the default config file.
let localConfigPath = join(CONFIG_PATH, 'config.yml'); */
const getDefaultConfigPath = () => {
if (!fs.existsSync(localConfigPath)) { // default to config/config.yml
localConfigPath = join(CONFIG_PATH, 'config.yaml'); let defaultConfigPath = join(CONFIG_PATH, 'config.yml');
if (!fs.existsSync(defaultConfigPath)) {
defaultConfigPath = join(CONFIG_PATH, 'config.yaml');
} }
return defaultConfigPath;
};
/**
* Get the path of an environment-specific config file.
*
* @param env the environment to get the config file for
*/
const getEnvConfigFilePath = (env: Environment) => {
// determine app config filename variations // determine app config filename variations
let envVariations; let envVariations;
switch (env) { switch (env) {
@@ -76,22 +90,21 @@ const getLocalConfigPath = (env: Environment) => {
envVariations = ['dev', 'development']; envVariations = ['dev', 'development'];
} }
let envLocalConfigPath;
// check if any environment variations of app config exist // check if any environment variations of app config exist
for (const envVariation of envVariations) { for (const envVariation of envVariations) {
let envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yml`); envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yml`);
if (fs.existsSync(envLocalConfigPath)) {
break;
}
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yaml`);
if (fs.existsSync(envLocalConfigPath)) { if (fs.existsSync(envLocalConfigPath)) {
localConfigPath = envLocalConfigPath;
break; break;
} else {
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yaml`);
if (fs.existsSync(envLocalConfigPath)) {
localConfigPath = envLocalConfigPath;
break;
}
} }
} }
return localConfigPath; return envLocalConfigPath;
}; };
const overrideWithConfig = (config: Config, pathToConfig: string) => { const overrideWithConfig = (config: Config, pathToConfig: string) => {
@@ -174,12 +187,20 @@ export const buildAppConfig = (destConfigPath?: string): AppConfig => {
console.log(`Building ${colors.green.bold(`development`)} app config`); console.log(`Building ${colors.green.bold(`development`)} app config`);
} }
// override with dist config // override with default config
const localConfigPath = getLocalConfigPath(env); const defaultConfigPath = getDefaultConfigPath();
if (fs.existsSync(defaultConfigPath)) {
overrideWithConfig(appConfig, defaultConfigPath);
} else {
console.warn(`Unable to find default config file at ${defaultConfigPath}`);
}
// override with env config
const localConfigPath = getEnvConfigFilePath(env);
if (fs.existsSync(localConfigPath)) { if (fs.existsSync(localConfigPath)) {
overrideWithConfig(appConfig, localConfigPath); overrideWithConfig(appConfig, localConfigPath);
} else { } else {
console.warn(`Unable to find dist config file at ${localConfigPath}`); console.warn(`Unable to find env config file at ${localConfigPath}`);
} }
// override with external config if specified by environment variable `DSPACE_APP_CONFIG_PATH` // override with external config if specified by environment variable `DSPACE_APP_CONFIG_PATH`