cli/new: add default- prefix to built-in template pointers

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-02-10 10:33:25 +01:00
parent 2c675620e1
commit b3ff1819d9
2 changed files with 11 additions and 6 deletions
@@ -90,9 +90,9 @@ describe('loadPortableTemplateConfig', () => {
backstage: {
new: {
templates: [
'backend-plugin',
'default-backend-plugin',
{ id: 'template1', target: 'path/to/template1' },
'frontend-plugin',
'default-frontend-plugin',
],
globals: {
license: 'MIT',
@@ -30,6 +30,11 @@ const defaults = {
packageNamePluginInfix: 'plugin-',
};
const builtInTemplateIds = defaultTemplates.map(t => `default-${t.id}`) as [
string,
...string[],
];
const pkgJsonWithNewConfigSchema = z.object({
backstage: z
.object({
@@ -38,9 +43,7 @@ const pkgJsonWithNewConfigSchema = z.object({
templates: z
.array(
z.union([
z.enum(
defaultTemplates.map(t => t.id) as [string, ...string[]],
),
z.enum(builtInTemplateIds),
z
.object({
id: z.string(),
@@ -93,7 +96,9 @@ export async function loadPortableTemplateConfig(
const templatePointers =
config?.templates?.map(t => {
if (typeof t === 'string') {
const defaultTemplate = defaultTemplates.find(d => d.id === t);
const defaultTemplate = defaultTemplates.find(
d => t === `default-${d.id}`,
);
if (!defaultTemplate) {
throw new Error(`Built-in template '${t}' does not exist`);
}