Merge pull request #5328 from backstage/rugvip/config-schema-cli

cli: added config:docs command
This commit is contained in:
Patrik Oldsberg
2021-04-16 12:56:24 +02:00
committed by GitHub
4 changed files with 74 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Add `config:docs` command that opens up reference documentation for the local configuration schema in a browser.
+20
View File
@@ -44,6 +44,7 @@ clean Delete cache directories
create-plugin Creates a new plugin in the current repository
remove-plugin Removes plugin in the current repository
config:docs Browse the configuration reference documentation
config:print Print the app configuration for the current package
config:check Validate that the given configuration loads and matches schema
config:schema Dump the app configuration schema
@@ -447,6 +448,25 @@ Options:
--backstage-cli-help display help for command
```
## config:docs
Scope: `root`
This commands opens up the reference documentation of your apps local
configuration schema in the browser. This is useful to get an overview of what
configuration values are available to use, a description of what they do and
their format, and where they get sent.
```text
Usage: backstage-cli config:docs [options]
Browse the configuration reference documentation
Options:
--package <name> Only include the schema that applies to the given package
-h, --help display help for command
```
## config:print
Scope: `root`
+40
View File
@@ -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)}`);
};
+9
View File
@@ -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(