From bc3ffada188066250bfc5237ab7f2508b129b534 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Fri, 8 Oct 2021 12:21:01 +0200 Subject: [PATCH] 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();