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
+1 -1
View File
@@ -23,7 +23,7 @@ import { loadConfig } from '@backstage/config-loader';
export async function loadBackendConfig() {
const paths = findPaths(__dirname);
const configs = await loadConfig({
rootPath: paths.targetRoot,
rootPaths: [paths.targetDir, paths.targetRoot],
shouldReadSecrets: true,
});
return configs;
+3 -1
View File
@@ -21,7 +21,9 @@ import { paths } from '../../lib/paths';
import { buildBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({ rootPath: paths.targetRoot });
const appConfigs = await loadConfig({
rootPaths: [paths.targetDir, paths.targetRoot],
});
await buildBundle({
entry: 'src/index',
statsJsonEnabled: cmd.stats,
+3 -1
View File
@@ -21,7 +21,9 @@ import { paths } from '../../lib/paths';
import { serveBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({ rootPath: paths.targetRoot });
const appConfigs = await loadConfig({
rootPaths: [paths.targetDir, paths.targetRoot],
});
const waitForExit = await serveBundle({
entry: 'src/index',
checksEnabled: cmd.check,
+3 -1
View File
@@ -21,7 +21,9 @@ import { paths } from '../../lib/paths';
import { serveBackend } from '../../lib/bundler/backend';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({ rootPath: paths.targetRoot });
const appConfigs = await loadConfig({
rootPaths: [paths.targetDir, paths.targetRoot],
});
const waitForExit = await serveBackend({
entry: 'src/index',
checksEnabled: cmd.check,
+3 -1
View File
@@ -21,7 +21,9 @@ import { paths } from '../../lib/paths';
import { buildBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({ rootPath: paths.targetRoot });
const appConfigs = await loadConfig({
rootPaths: [paths.targetDir, paths.targetRoot],
});
await buildBundle({
entry: 'dev/index',
statsJsonEnabled: cmd.stats,
+3 -1
View File
@@ -21,7 +21,9 @@ import { paths } from '../../lib/paths';
import { serveBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({ rootPath: paths.targetRoot });
const appConfigs = await loadConfig({
rootPaths: [paths.targetDir, paths.targetRoot],
});
const waitForExit = await serveBundle({
entry: 'dev/index',
checksEnabled: cmd.check,
+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;