From 74edab290a8297ec1700718f0cf44e93716461a8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 7 Aug 2020 10:39:08 +0200 Subject: [PATCH] config-loader: resolve config files suffixed with local and NODE_ENV --- .gitignore | 3 +++ packages/config-loader/src/lib/resolver.ts | 26 +++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index c1bcf5a4b4..069be4aa2d 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,6 @@ dist # MkDocs build output site + +# Local configuration files +*.local.yaml diff --git a/packages/config-loader/src/lib/resolver.ts b/packages/config-loader/src/lib/resolver.ts index 5ee3d2cf09..c1f95cdef7 100644 --- a/packages/config-loader/src/lib/resolver.ts +++ b/packages/config-loader/src/lib/resolver.ts @@ -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 { - // 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); + } } }