config-loader: use multiple config roots
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user