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 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();