diff --git a/packages/cli/src/commands/package-dynamic-plugins/command.ts b/packages/cli/src/commands/package-dynamic-plugins/command.ts index 7dc4487dcc5..ef67cb70bd7 100644 --- a/packages/cli/src/commands/package-dynamic-plugins/command.ts +++ b/packages/cli/src/commands/package-dynamic-plugins/command.ts @@ -1,7 +1,9 @@ import { PackageRoles } from '@backstage/cli-node'; +import chalk from 'chalk'; import { OptionValues } from 'commander'; import fs from 'fs-extra'; +import YAML from 'yaml'; import os from 'os'; import path from 'path'; @@ -73,6 +75,7 @@ export async function command(opts: OptionValues): Promise { path.join(os.tmpdir(), 'package-dynamic-plugins'), ); const pluginRegistryMetadata = []; + const pluginConfigs: Record = {}; try { // copy the dist-dynamic output folder for each plugin to some temp directory and generate the metadata entry for each plugin for (const pluginPkg of packages) { @@ -121,6 +124,27 @@ export async function command(opts: OptionValues): Promise { keywords, }, }); + // some plugins include configuration snippets in an app-config.janus-idp.yaml + const pluginConfigPath = path.join( + packageDirectory, + 'app-config.janus-idp.yaml', + ); + if (fs.existsSync(pluginConfigPath)) { + try { + const pluginConfig = fs.readFileSync(pluginConfigPath); + pluginConfigs[packageName] = YAML.parse( + pluginConfig.toLocaleString(), + ); + } catch (err) { + Task.log( + `Encountered an error parsing configuration at ${pluginConfigPath}, no example configuration will be displayed`, + ); + } + } else { + Task.log( + `No plugin configuration found at ${pluginConfigPath} create this file as needed if this plugin requires configuration`, + ); + } } catch (err) { Task.log( `Encountered an error copying static assets for plugin ${packageFilePath}, the plugin will not be packaged. The error was ${err}`, @@ -143,6 +167,31 @@ COPY . . `, { cwd: tmpDir }, ); + Task.log(`Successfully built image ${tag} with following plugins:`); + for (const plugin of pluginRegistryMetadata) { + Task.log(` ${chalk.white(Object.keys(plugin)[0])}`); + } + // print out a configuration example based on available plugin data + try { + const configurationExample = YAML.stringify({ + plugins: pluginRegistryMetadata.map(plugin => { + const pluginName = Object.keys(plugin)[0]; + const pluginConfig = pluginConfigs[pluginName]; + return { + package: `oci://${tag}!${pluginName}`, + disabled: false, + ...(pluginConfig ? { pluginConfig } : {}), + }; + }), + }); + Task.log( + `\nHere is an example dynamic-plugins.yaml for these plugins: \n\n${chalk.white(configurationExample)}\n\n`, + ); + } catch (err) { + Task.error( + `An error occurred while creating configuration example: ${err}`, + ); + } } catch (e) { Task.error(`Error encountered while packaging dynamic plugins: ${e}`); } finally { @@ -153,22 +202,6 @@ COPY . . if (preserveTempDir) { Task.log(`Keeping temporary directory ${tmpDir}`); } - - Task.log(`Successfully built image ${tag} with following plugins:`); - for (const plugin of pluginRegistryMetadata) { - Task.log(` ${Object.keys(plugin)[0]}`); - } - Task.log(` -Configuration example for the dynamic-plugins.yaml: - -packages:`); - for (const plugin of pluginRegistryMetadata) { - Task.log(`- package: oci://${tag}!${Object.keys(plugin)[0]} - disabled: false - pluginConfig: - # add required plugin configuration here -`); - } } catch (err) { Task.error( `An error occurred while removing the temporary staging directory: ${err}`,