From 4e5c942491dd1f52d8e0deff5f1877ff8192b87f Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 14 Apr 2021 17:42:11 +0200 Subject: [PATCH 1/2] cli: added config:docs command Signed-off-by: Patrik Oldsberg --- .changeset/fair-carrots-tell.md | 5 +++ packages/cli/src/commands/config/docs.ts | 40 ++++++++++++++++++++++++ packages/cli/src/commands/index.ts | 9 ++++++ 3 files changed, 54 insertions(+) create mode 100644 .changeset/fair-carrots-tell.md create mode 100644 packages/cli/src/commands/config/docs.ts diff --git a/.changeset/fair-carrots-tell.md b/.changeset/fair-carrots-tell.md new file mode 100644 index 0000000000..62dce5c3ce --- /dev/null +++ b/.changeset/fair-carrots-tell.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Add `config:docs` command that opens up reference documentation for the local configuration schema in a browser. diff --git a/packages/cli/src/commands/config/docs.ts b/packages/cli/src/commands/config/docs.ts new file mode 100644 index 0000000000..e06bc42c27 --- /dev/null +++ b/packages/cli/src/commands/config/docs.ts @@ -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)}`); +}; diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 46b6deeb21..c770239464 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -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 ', + '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( From ff42512d3a31f2a51814bcf35a2ca7ef53b36590 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 14 Apr 2021 17:47:27 +0200 Subject: [PATCH 2/2] docs/cli: add config:docs command Signed-off-by: Patrik Oldsberg --- docs/cli/commands.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/cli/commands.md b/docs/cli/commands.md index 33693b010f..324d17463c 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -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 Only include the schema that applies to the given package + -h, --help display help for command +``` + ## config:print Scope: `root`