config-loader: use multiple config roots

This commit is contained in:
Patrik Oldsberg
2020-08-07 10:37:22 +02:00
parent 032ba401af
commit 811328ed1f
8 changed files with 30 additions and 12 deletions
+12 -4
View File
@@ -15,10 +15,11 @@
*/
import { resolve as resolvePath } from 'path';
import { pathExists } from 'fs-extra';
type ResolveOptions = {
// Root path for search for app-config.yaml
rootPath: string;
// Root paths to search for config files. Config from earlier paths has higher priority.
rootPaths: string[];
};
/**
@@ -29,7 +30,14 @@ export async function resolveStaticConfig(
): 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 configPath = resolvePath(options.rootPath, 'app-config.yaml');
const resolvedPaths = [];
return [configPath];
for (const rootPath of options.rootPaths) {
const path = resolvePath(rootPath, 'app-config.yaml');
if (await pathExists(path)) {
resolvedPaths.push(path);
}
}
return resolvedPaths;
}
+2 -2
View File
@@ -25,8 +25,8 @@ import {
} from './lib';
export type LoadConfigOptions = {
// Root path for search for app-config.yaml
rootPath: string;
// Root paths to search for config files. Config from earlier paths has higher priority.
rootPaths: string[];
// Whether to read secrets or omit them, defaults to false.
shouldReadSecrets?: boolean;