Merge pull request #7515 from backstage/orkohunter/cli-install-from
cli: add a --from <location> option to the plugin install command
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
add a --from <location> option to the plugin install command
|
||||
@@ -232,7 +232,11 @@ export function registerCommands(program: CommanderStatic) {
|
||||
.action(lazy(() => import('./info').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('install <plugin-id>', { hidden: true })
|
||||
.command('install [plugin-id]', { hidden: true })
|
||||
.option(
|
||||
'--from <packageJsonFilePath>',
|
||||
'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)));
|
||||
}
|
||||
|
||||
@@ -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 <plugin-id> or a package.json file path in the --from flag.',
|
||||
);
|
||||
}
|
||||
|
||||
const steps = await PluginInstaller.resolveSteps(pkg);
|
||||
const installer = new PluginInstaller(steps);
|
||||
await installer.run();
|
||||
|
||||
Reference in New Issue
Block a user