cli: added config:docs command
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Add `config:docs` command that opens up reference documentation for the local configuration schema in a browser.
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2021 Spotify AB
|
||||
*
|
||||
* 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 { JsonObject } from '@backstage/config';
|
||||
import { mergeConfigSchemas } from '@backstage/config-loader';
|
||||
import { Command } from 'commander';
|
||||
import { JSONSchema7 as JSONSchema } from 'json-schema';
|
||||
import openBrowser from 'react-dev-utils/openBrowser';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
|
||||
const DOCS_URL = 'https://config.backstage.io';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
const { schema: appSchemas } = await loadCliConfig({
|
||||
args: [],
|
||||
fromPackage: cmd.package,
|
||||
mockEnv: true,
|
||||
});
|
||||
|
||||
const schema = mergeConfigSchemas(
|
||||
(appSchemas.serialize().schemas as JsonObject[]).map(
|
||||
_ => _.value as JSONSchema,
|
||||
),
|
||||
);
|
||||
|
||||
openBrowser(`${DOCS_URL}#schema=${JSON.stringify(schema)}`);
|
||||
};
|
||||
@@ -140,6 +140,15 @@ export function registerCommands(program: CommanderStatic) {
|
||||
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
|
||||
.action(lazy(() => import('./testCommand').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(
|
||||
|
||||
Reference in New Issue
Block a user