cli/commands/new: restore ability to preselect template

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-02-06 23:07:52 +01:00
parent 4309e13c78
commit e6535e0f26
3 changed files with 17 additions and 2 deletions
+4
View File
@@ -247,6 +247,10 @@ export function registerCommands(program: Command) {
.description(
'Open up an interactive guide to creating new things in your app',
)
.option(
'--select <name>',
'Select the thing you want to be creating upfront',
)
.action(lazy(() => import('./new/new'), 'default'));
registerConfigCommands(program);
+5 -2
View File
@@ -41,13 +41,16 @@ import {
import { runAdditionalActions } from '../../lib/new/additionalActions';
import { executePluginPackageTemplate } from '../../lib/new/executeTemplate';
import { TemporaryDirectoryManager } from './TemporaryDirectoryManager';
import { OptionValues } from 'commander';
export default async () => {
export default async (opts: OptionValues) => {
const pkgJson = await fs.readJson(paths.resolveTargetRoot('package.json'));
const cliConfig = pkgJson.backstage?.cli;
const { templates, globals } = readCliConfig(cliConfig);
const template = verifyTemplate(await templateSelector(templates));
const template = verifyTemplate(
await templateSelector(templates, opts.select),
);
const codeOwnersFilePath = await getCodeownersFilePath(paths.targetRoot);
@@ -47,7 +47,15 @@ export function readCliConfig(cliConfig: CliConfig) {
export async function templateSelector(
templates: TemplateLocation[],
selected?: string,
): Promise<TemplateLocation> {
if (selected) {
const template = templates.find(t => t.id === selected);
if (!template) {
throw new Error(`Template '${selected}' not found`);
}
return template;
}
const answer = await inquirer.prompt<{ name: TemplateLocation }>([
{
type: 'list',