From bc3ffada188066250bfc5237ab7f2508b129b534 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Fri, 8 Oct 2021 12:21:01 +0200 Subject: [PATCH 1/2] cli: add a --from option to the install command This is useful for testing local development when writing installation recipes in plugins Signed-off-by: Himanshu Mishra --- packages/cli/src/commands/index.ts | 6 +++++- packages/cli/src/commands/install/install.ts | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 1fef399501..d6686f2655 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -232,7 +232,11 @@ export function registerCommands(program: CommanderStatic) { .action(lazy(() => import('./info').then(m => m.default))); program - .command('install ', { hidden: true }) + .command('install [plugin-id]', { hidden: true }) + .option( + '--from ', + 'Install from a local package.json containing the installation recipe', + ) .description('Install a Backstage plugin [EXPERIMENTAL]') .action(lazy(() => import('./install/install').then(m => m.default))); } diff --git a/packages/cli/src/commands/install/install.ts b/packages/cli/src/commands/install/install.ts index 2ec208bca3..cc6e46cfa2 100644 --- a/packages/cli/src/commands/install/install.ts +++ b/packages/cli/src/commands/install/install.ts @@ -18,6 +18,8 @@ import { Step, PackageWithInstallRecipe } from './types'; import { fetchPackageInfo } from '../../lib/versioning'; import { NotFoundError } from '../../lib/errors'; import * as stepDefinitionMap from './steps'; +import { Command } from 'commander'; +import fs from 'fs-extra'; const stepDefinitions = Object.values(stepDefinitionMap); @@ -95,11 +97,21 @@ class PluginInstaller { } } -export default async (pluginId: string) => { +export default async (pluginId?: string, cmd?: Command) => { // TODO(himanshu): If no plugin id is provided, it should list all plugins available. Maybe in some other command? - // TODO(himanshu): Add a way to test your install recipe. Maybe a --from-local-package=/path/to/package.json - const pkg = await fetchPluginPackage(pluginId); + let pkg: PackageWithInstallRecipe; + if (pluginId) { + pkg = await fetchPluginPackage(pluginId); + } else if (cmd?.from) { + // TODO(himanshu): Also support reading directly from url + pkg = await fs.readJson(cmd.from); + } else { + throw new Error( + 'Missing both or a package.json file path in the --from flag.', + ); + } + const steps = await PluginInstaller.resolveSteps(pkg); const installer = new PluginInstaller(steps); await installer.run(); From 53bdc66623b43a3fec2a2ea60eae0ea6bff95d7b Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Fri, 8 Oct 2021 12:25:19 +0200 Subject: [PATCH 2/2] cli: add changeset Signed-off-by: Himanshu Mishra --- .changeset/khaki-planets-prove.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/khaki-planets-prove.md diff --git a/.changeset/khaki-planets-prove.md b/.changeset/khaki-planets-prove.md new file mode 100644 index 0000000000..168f30213b --- /dev/null +++ b/.changeset/khaki-planets-prove.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +add a --from option to the plugin install command