config-loader: pass in env as an option

This commit is contained in:
Patrik Oldsberg
2020-08-07 10:52:50 +02:00
parent 74edab290a
commit a37aa1d994
8 changed files with 13 additions and 4 deletions
+1
View File
@@ -23,6 +23,7 @@ import { loadConfig } from '@backstage/config-loader';
export async function loadBackendConfig() {
const paths = findPaths(__dirname);
const configs = await loadConfig({
env: process.env.NODE_ENV,
rootPaths: [paths.targetDir, paths.targetRoot],
shouldReadSecrets: true,
});
+1
View File
@@ -22,6 +22,7 @@ import { buildBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({
env: 'production',
rootPaths: [paths.targetDir, paths.targetRoot],
});
await buildBundle({
+1
View File
@@ -22,6 +22,7 @@ import { serveBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({
env: 'development',
rootPaths: [paths.targetDir, paths.targetRoot],
});
const waitForExit = await serveBundle({
+1
View File
@@ -22,6 +22,7 @@ import { serveBackend } from '../../lib/bundler/backend';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({
env: 'development',
rootPaths: [paths.targetDir, paths.targetRoot],
});
const waitForExit = await serveBackend({
@@ -22,6 +22,7 @@ import { buildBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({
env: 'production',
rootPaths: [paths.targetDir, paths.targetRoot],
});
await buildBundle({
@@ -22,6 +22,7 @@ import { serveBundle } from '../../lib/bundler';
export default async (cmd: Command) => {
const appConfigs = await loadConfig({
env: 'development',
rootPaths: [paths.targetDir, paths.targetRoot],
});
const waitForExit = await serveBundle({
+4 -4
View File
@@ -20,6 +20,8 @@ import { pathExists } from 'fs-extra';
type ResolveOptions = {
// Root paths to search for config files. Config from earlier paths has higher priority.
rootPaths: string[];
// The environment that we're loading config for, e.g. 'development', 'production'.
env: string;
};
/**
@@ -35,11 +37,9 @@ type ResolveOptions = {
export async function resolveStaticConfig(
options: ResolveOptions,
): Promise<string[]> {
const env = process.env.NODE_ENV ?? 'development';
const filePaths = [
`app-config.${env}.local.yaml`,
`app-config.${env}.yaml`,
`app-config.${options.env}.local.yaml`,
`app-config.${options.env}.yaml`,
`app-config.local.yaml`,
`app-config.yaml`,
];
+3
View File
@@ -28,6 +28,9 @@ export type LoadConfigOptions = {
// Root paths to search for config files. Config from earlier paths has higher priority.
rootPaths: string[];
// The environment that we're loading config for, e.g. 'development', 'production'.
env: string;
// Whether to read secrets or omit them, defaults to false.
shouldReadSecrets?: boolean;
};