cli/commands/new: restore ability to preselect template
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user