cli/new: move config into backstage.cli.new

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-02-10 10:40:13 +01:00
parent b3ff1819d9
commit 24b2bacc58
3 changed files with 80 additions and 63 deletions
+10 -8
View File
@@ -1,19 +1,21 @@
{
"name": "root",
"version": "1.36.0-next.2",
"backstage": {
"cli": {
"new": {
"globals": {
"scope": "backstage",
"private": false
}
}
}
},
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage"
},
"backstage": {
"new": {
"globals": {
"scope": "backstage",
"private": false
}
}
},
"workspaces": {
"packages": [
"packages/*",
@@ -29,16 +29,18 @@ describe('loadPortableTemplateConfig', () => {
mockDir.setContent({
'package.json': JSON.stringify({
backstage: {
new: {
templates: [
{ id: 'template1', target: 'path/to/template1' },
{ id: 'template2', target: 'path/to/template2' },
],
globals: {
license: 'MIT',
private: true,
namePrefix: '@acme/',
namePluginInfix: 'backstage-plugin-',
cli: {
new: {
templates: [
{ id: 'template1', target: 'path/to/template1' },
{ id: 'template2', target: 'path/to/template2' },
],
globals: {
license: 'MIT',
private: true,
namePrefix: '@acme/',
namePluginInfix: 'backstage-plugin-',
},
},
},
},
@@ -88,17 +90,19 @@ describe('loadPortableTemplateConfig', () => {
mockDir.setContent({
'package.json': JSON.stringify({
backstage: {
new: {
templates: [
'default-backend-plugin',
{ id: 'template1', target: 'path/to/template1' },
'default-frontend-plugin',
],
globals: {
license: 'MIT',
private: true,
namePrefix: '@acme/',
namePluginInfix: 'backstage-plugin-',
cli: {
new: {
templates: [
'default-backend-plugin',
{ id: 'template1', target: 'path/to/template1' },
'default-frontend-plugin',
],
globals: {
license: 'MIT',
private: true,
namePrefix: '@acme/',
namePluginInfix: 'backstage-plugin-',
},
},
},
},
@@ -136,10 +140,12 @@ describe('loadPortableTemplateConfig', () => {
mockDir.setContent({
'package.json': JSON.stringify({
backstage: {
new: {
globals: {
license: 'MIT',
private: true,
cli: {
new: {
globals: {
license: 'MIT',
private: true,
},
},
},
},
@@ -165,8 +171,10 @@ describe('loadPortableTemplateConfig', () => {
mockDir.setContent({
'package.json': JSON.stringify({
backstage: {
new: {
templates: 'invalid',
cli: {
new: {
templates: 'invalid',
},
},
},
}),
@@ -185,8 +193,10 @@ describe('loadPortableTemplateConfig', () => {
mockDir.setContent({
'package.json': JSON.stringify({
backstage: {
new: {
templates: ['invalid'],
cli: {
new: {
templates: ['invalid'],
},
},
},
}),
@@ -35,36 +35,41 @@ const builtInTemplateIds = defaultTemplates.map(t => `default-${t.id}`) as [
...string[],
];
const newConfigSchema = z
.object({
templates: z
.array(
z.union([
z.enum(builtInTemplateIds),
z
.object({
id: z.string(),
description: z.string().optional(),
target: z.string(),
})
.strict(),
]),
)
.optional(),
globals: z
.object({
license: z.string().optional(),
version: z.string().optional(),
private: z.boolean().optional(),
namePrefix: z.string().optional(),
namePluginInfix: z.string().optional(),
})
.optional(),
})
.strict();
const pkgJsonWithNewConfigSchema = z.object({
backstage: z
.object({
new: z
cli: z
.object({
templates: z
.array(
z.union([
z.enum(builtInTemplateIds),
z
.object({
id: z.string(),
description: z.string().optional(),
target: z.string(),
})
.strict(),
]),
)
.optional(),
globals: z
.object({
license: z.string().optional(),
version: z.string().optional(),
private: z.boolean().optional(),
namePrefix: z.string().optional(),
namePluginInfix: z.string().optional(),
})
.optional(),
new: newConfigSchema.optional(),
})
.strict()
.optional(),
})
.optional(),
@@ -91,7 +96,7 @@ export async function loadPortableTemplateConfig(
);
}
const config = parsed.data.backstage?.new;
const config = parsed.data.backstage?.cli?.new;
const templatePointers =
config?.templates?.map(t => {