config-loader: resolve config files suffixed with local and NODE_ENV
This commit is contained in:
@@ -125,3 +125,6 @@ dist
|
||||
|
||||
# MkDocs build output
|
||||
site
|
||||
|
||||
# Local configuration files
|
||||
*.local.yaml
|
||||
|
||||
@@ -24,18 +24,34 @@ type ResolveOptions = {
|
||||
|
||||
/**
|
||||
* Resolves all configuration files that should be loaded in the given environment.
|
||||
*
|
||||
* For each root directory, search for the default app-config.yaml, along with suffixed
|
||||
* NODE_ENV and local variants, e.g. app-config.production.yaml or app-config.development.local.yaml
|
||||
*
|
||||
* The priority order of config loaded through suffixes is `env > local > none`, meaning that
|
||||
* for example app-config.development.yaml has higher priority than `app-config.local.yaml`.
|
||||
*
|
||||
*/
|
||||
export async function resolveStaticConfig(
|
||||
options: ResolveOptions,
|
||||
): Promise<string[]> {
|
||||
// TODO: We'll want this to be a bit more elaborate, probably adding configs for
|
||||
// specific env, and maybe local config for plugins.
|
||||
const env = process.env.NODE_ENV ?? 'development';
|
||||
|
||||
const filePaths = [
|
||||
`app-config.${env}.local.yaml`,
|
||||
`app-config.${env}.yaml`,
|
||||
`app-config.local.yaml`,
|
||||
`app-config.yaml`,
|
||||
];
|
||||
|
||||
const resolvedPaths = [];
|
||||
|
||||
for (const rootPath of options.rootPaths) {
|
||||
const path = resolvePath(rootPath, 'app-config.yaml');
|
||||
if (await pathExists(path)) {
|
||||
resolvedPaths.push(path);
|
||||
for (const filePath of filePaths) {
|
||||
const path = resolvePath(rootPath, filePath);
|
||||
if (await pathExists(path)) {
|
||||
resolvedPaths.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user