feat: move config to its own "module"
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
@@ -18,7 +18,7 @@ import fs from 'fs-extra';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { buildBundle, getModuleFederationOptions } from '../../lib/bundler';
|
||||
import { getEnvironmentParallelism } from '../../lib/parallel';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { loadCliConfig } from '../../modules/config/lib/config';
|
||||
|
||||
interface BuildAppOptions {
|
||||
targetDir: string;
|
||||
|
||||
@@ -15,15 +15,11 @@
|
||||
*/
|
||||
|
||||
import { Command, Option } from 'commander';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { exitWithError } from '../lib/errors';
|
||||
|
||||
const configOption = [
|
||||
'--config <path>',
|
||||
'Config files to load instead of app-config.yaml',
|
||||
(opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]),
|
||||
Array<string>(),
|
||||
] as const;
|
||||
import { lazy } from '../lib/lazy';
|
||||
import {
|
||||
configOption,
|
||||
registerCommands as registerConfigCommands,
|
||||
} from '../modules/config';
|
||||
|
||||
export function registerRepoCommand(program: Command) {
|
||||
const command = program
|
||||
@@ -279,66 +275,7 @@ export function registerCommands(program: Command) {
|
||||
.option('--no-private', 'Do not mark new packages as private')
|
||||
.action(lazy(() => import('./new/new').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:docs')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only include the schema that applies to the given package',
|
||||
)
|
||||
.description('Browse the configuration reference documentation')
|
||||
.action(lazy(() => import('./config/docs').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:print')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only load config schema that applies to the given package',
|
||||
)
|
||||
.option('--lax', 'Do not require environment variables to be set')
|
||||
.option('--frontend', 'Print only the frontend configuration')
|
||||
.option('--with-secrets', 'Include secrets in the printed configuration')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Format to print the configuration in, either json or yaml [yaml]',
|
||||
)
|
||||
.option(...configOption)
|
||||
.description('Print the app configuration for the current package')
|
||||
.action(lazy(() => import('./config/print').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:check')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only load config schema that applies to the given package',
|
||||
)
|
||||
.option('--lax', 'Do not require environment variables to be set')
|
||||
.option('--frontend', 'Only validate the frontend configuration')
|
||||
.option('--deprecated', 'Output deprecated configuration settings')
|
||||
.option(
|
||||
'--strict',
|
||||
'Enable strict config validation, forbidding errors and unknown keys',
|
||||
)
|
||||
.option(...configOption)
|
||||
.description(
|
||||
'Validate that the given configuration loads and matches schema',
|
||||
)
|
||||
.action(lazy(() => import('./config/validate').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:schema')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only output config schema that applies to the given package',
|
||||
)
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Format to print the schema in, either json or yaml [yaml]',
|
||||
)
|
||||
.option('--merge', 'Print the config schemas merged', true)
|
||||
.option('--no-merge', 'Print the config schemas not merged')
|
||||
.description('Print configuration schema')
|
||||
.action(lazy(() => import('./config/schema').then(m => m.default)));
|
||||
|
||||
registerConfigCommands(program);
|
||||
registerRepoCommand(program);
|
||||
registerScriptCommand(program);
|
||||
registerMigrateCommand(program);
|
||||
@@ -444,20 +381,3 @@ function removed(message?: string) {
|
||||
process.exit(1);
|
||||
};
|
||||
}
|
||||
|
||||
// Wraps an action function so that it always exits and handles errors
|
||||
function lazy(
|
||||
getActionFunc: () => Promise<(...args: any[]) => Promise<void>>,
|
||||
): (...args: any[]) => Promise<never> {
|
||||
return async (...args: any[]) => {
|
||||
try {
|
||||
const actionFunc = await getActionFunc();
|
||||
await actionFunc(...args);
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
exitWithError(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import webpack from 'webpack';
|
||||
import WebpackDevServer from 'webpack-dev-server';
|
||||
|
||||
import { paths as libPaths } from '../../lib/paths';
|
||||
import { loadCliConfig } from '../config';
|
||||
import { loadCliConfig } from '../../modules/config/lib/config';
|
||||
import { createConfig, resolveBaseUrl, resolveEndpoint } from './config';
|
||||
import { createDetectedModulesEntryPoint } from './packageDetection';
|
||||
import { resolveBundlingPaths, resolveOptionalBundlingPaths } from './paths';
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { exitWithError } from '../lib/errors';
|
||||
|
||||
// Wraps an action function so that it always exits and handles errors
|
||||
export function lazy(
|
||||
getActionFunc: () => Promise<(...args: any[]) => Promise<void>>,
|
||||
): (...args: any[]) => Promise<never> {
|
||||
return async (...args: any[]) => {
|
||||
try {
|
||||
const actionFunc = await getActionFunc();
|
||||
await actionFunc(...args);
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
exitWithError(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ import { mergeConfigSchemas } from '@backstage/config-loader';
|
||||
import { OptionValues } from 'commander';
|
||||
import { JSONSchema7 as JSONSchema } from 'json-schema';
|
||||
import openBrowser from 'react-dev-utils/openBrowser';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { loadCliConfig } from '../lib/config';
|
||||
|
||||
const DOCS_URL = 'https://config.backstage.io';
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
import { OptionValues } from 'commander';
|
||||
import { stringify as stringifyYaml } from 'yaml';
|
||||
import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { loadCliConfig } from '../lib/config';
|
||||
import { ConfigSchema, ConfigVisibility } from '@backstage/config-loader';
|
||||
|
||||
export default async (opts: OptionValues) => {
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
import { OptionValues } from 'commander';
|
||||
import { JSONSchema7 as JSONSchema } from 'json-schema';
|
||||
import { stringify as stringifyYaml } from 'yaml';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { loadCliConfig } from '../lib/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { mergeConfigSchemas } from '@backstage/config-loader';
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { OptionValues } from 'commander';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { loadCliConfig } from '../lib/config';
|
||||
|
||||
export default async (opts: OptionValues) => {
|
||||
await loadCliConfig({
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { lazy } from '../../lib/lazy';
|
||||
|
||||
export const configOption = [
|
||||
'--config <path>',
|
||||
'Config files to load instead of app-config.yaml',
|
||||
(opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]),
|
||||
Array<string>(),
|
||||
] as const;
|
||||
|
||||
export function registerCommands(program: Command) {
|
||||
program
|
||||
.command('config:docs')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only include the schema that applies to the given package',
|
||||
)
|
||||
.description('Browse the configuration reference documentation')
|
||||
.action(lazy(() => import('./commands/docs').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:print')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only load config schema that applies to the given package',
|
||||
)
|
||||
.option('--lax', 'Do not require environment variables to be set')
|
||||
.option('--frontend', 'Print only the frontend configuration')
|
||||
.option('--with-secrets', 'Include secrets in the printed configuration')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Format to print the configuration in, either json or yaml [yaml]',
|
||||
)
|
||||
.option(...configOption)
|
||||
.description('Print the app configuration for the current package')
|
||||
.action(lazy(() => import('./commands/print').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:check')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only load config schema that applies to the given package',
|
||||
)
|
||||
.option('--lax', 'Do not require environment variables to be set')
|
||||
.option('--frontend', 'Only validate the frontend configuration')
|
||||
.option('--deprecated', 'Output deprecated configuration settings')
|
||||
.option(
|
||||
'--strict',
|
||||
'Enable strict config validation, forbidding errors and unknown keys',
|
||||
)
|
||||
.option(...configOption)
|
||||
.description(
|
||||
'Validate that the given configuration loads and matches schema',
|
||||
)
|
||||
.action(lazy(() => import('./commands/validate').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:schema')
|
||||
.option(
|
||||
'--package <name>',
|
||||
'Only output config schema that applies to the given package',
|
||||
)
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Format to print the schema in, either json or yaml [yaml]',
|
||||
)
|
||||
.option('--merge', 'Print the config schemas merged', true)
|
||||
.option('--no-merge', 'Print the config schemas not merged')
|
||||
.description('Print configuration schema')
|
||||
.action(lazy(() => import('./commands/schema').then(m => m.default)));
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { ConfigSources, loadConfigSchema } from '@backstage/config-loader';
|
||||
import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
import { paths } from './paths';
|
||||
import { paths } from '../../../lib/paths';
|
||||
import { getPackages } from '@manypkg/get-packages';
|
||||
import { PackageGraph } from '@backstage/cli-node';
|
||||
|
||||
Reference in New Issue
Block a user