cli/new: move description to template pointer
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -17,52 +17,64 @@
|
||||
export const defaultTemplates = [
|
||||
{
|
||||
id: 'backend-module',
|
||||
description: 'A new backend module that extends an existing backend plugin',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/default-backend-module.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'backend-plugin',
|
||||
description: 'A new backend plugin',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/default-backend-plugin.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'plugin-common',
|
||||
description: 'A new isomorphic common plugin package',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/default-common-plugin-package.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'plugin-node',
|
||||
description: 'A new Node.js library plugin package',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/default-node-plugin-package.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'frontend-plugin',
|
||||
description: 'A new frontend plugin',
|
||||
target: require.resolve('@backstage/cli/templates/default-plugin.yaml'),
|
||||
},
|
||||
{
|
||||
id: 'plugin-react',
|
||||
description: 'A new web library plugin package',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/default-react-plugin-package.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'node-library',
|
||||
description:
|
||||
'A library package, exporting shared functionality for Node.js environments',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/node-library-package.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'scaffolder-module',
|
||||
target: require.resolve('@backstage/cli/templates/scaffolder-module.yaml'),
|
||||
},
|
||||
{
|
||||
id: 'web-library',
|
||||
description:
|
||||
'A library package, exporting shared functionality for web environments',
|
||||
target: require.resolve(
|
||||
'@backstage/cli/templates/web-library-package.yaml',
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'scaffolder-module',
|
||||
description:
|
||||
'A module exporting custom actions for @backstage/plugin-scaffolder-backend',
|
||||
target: require.resolve('@backstage/cli/templates/scaffolder-module.yaml'),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -32,25 +32,23 @@ import { fromZodError } from 'zod-validation-error';
|
||||
|
||||
const templateDefinitionSchema = z
|
||||
.object({
|
||||
description: z.string().optional(),
|
||||
template: z.string(),
|
||||
role: z.enum(TEMPLATE_ROLES),
|
||||
template: z.string(),
|
||||
templateValues: z.record(z.string()).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export async function loadPortableTemplate({
|
||||
id,
|
||||
target,
|
||||
}: PortableTemplatePointer): Promise<PortableTemplate> {
|
||||
if (target.match(/https?:\/\//)) {
|
||||
export async function loadPortableTemplate(
|
||||
pointer: PortableTemplatePointer,
|
||||
): Promise<PortableTemplate> {
|
||||
if (pointer.target.match(/https?:\/\//)) {
|
||||
throw new Error('Remote templates are not supported yet');
|
||||
}
|
||||
const templateContent = await fs
|
||||
.readFile(paths.resolveTargetRoot(target), 'utf-8')
|
||||
.readFile(paths.resolveTargetRoot(pointer.target), 'utf-8')
|
||||
.catch(error => {
|
||||
throw new ForwardedError(
|
||||
`Failed to load template definition from '${target}'`,
|
||||
`Failed to load template definition from '${pointer.target}'`,
|
||||
error,
|
||||
);
|
||||
});
|
||||
@@ -59,14 +57,14 @@ export async function loadPortableTemplate({
|
||||
const parsed = templateDefinitionSchema.safeParse(rawTemplate);
|
||||
if (!parsed.success) {
|
||||
throw new ForwardedError(
|
||||
`Invalid template definition at '${target}'`,
|
||||
`Invalid template definition at '${pointer.target}'`,
|
||||
fromZodError(parsed.error),
|
||||
);
|
||||
}
|
||||
|
||||
const { template, templateValues = {}, ...templateData } = parsed.data;
|
||||
const { role, template, templateValues = {} } = parsed.data;
|
||||
|
||||
const templatePath = resolvePath(dirname(target), template);
|
||||
const templatePath = resolvePath(dirname(pointer.target), template);
|
||||
const filePaths = await recursiveReaddir(templatePath).catch(error => {
|
||||
throw new ForwardedError(
|
||||
`Failed to load template contents from '${templatePath}'`,
|
||||
@@ -93,5 +91,5 @@ export async function loadPortableTemplate({
|
||||
}
|
||||
}
|
||||
|
||||
return { id, templateValues, ...templateData, files };
|
||||
return { id: pointer.id, role, files, templateValues };
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ const pkgJsonWithNewConfigSchema = z.object({
|
||||
z
|
||||
.object({
|
||||
id: z.string(),
|
||||
description: z.string().optional(),
|
||||
target: z.string(),
|
||||
})
|
||||
.strict(),
|
||||
|
||||
@@ -36,7 +36,9 @@ export async function selectTemplateInteractively(
|
||||
type: 'list',
|
||||
name: 'id',
|
||||
message: 'What do you want to create?',
|
||||
choices: config.templatePointers.map(t => t.id),
|
||||
choices: config.templatePointers.map(t =>
|
||||
t.description ? `${t.id} - ${t.description}` : t.id,
|
||||
),
|
||||
},
|
||||
]);
|
||||
selectedId = answers.id;
|
||||
|
||||
@@ -38,6 +38,7 @@ export type PortableTemplateConfig = {
|
||||
|
||||
export type PortableTemplatePointer = {
|
||||
id: string;
|
||||
description?: string;
|
||||
target: string;
|
||||
};
|
||||
|
||||
@@ -71,7 +72,6 @@ export type PortableTemplateFile = {
|
||||
|
||||
export type PortableTemplate = {
|
||||
id: string;
|
||||
description?: string;
|
||||
role: PortableTemplateRole;
|
||||
files: PortableTemplateFile[];
|
||||
templateValues: Record<string, string>;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
description: A new backend module that extends an existing backend plugin with additional features
|
||||
template: ./default-backend-module
|
||||
role: backend-plugin-module
|
||||
template: ./default-backend-module
|
||||
templateValues:
|
||||
moduleVar: '{{ camelCase pluginId }}Module{{ upperFirst ( camelCase moduleId ) }}'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
description: A new backend plugin
|
||||
template: ./default-backend-plugin
|
||||
role: backend-plugin
|
||||
template: ./default-backend-plugin
|
||||
templateValues:
|
||||
pluginVar: '{{ camelCase pluginId }}Plugin'
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
description: A new isomorphic common plugin package
|
||||
template: ./default-common-plugin-package
|
||||
role: plugin-common-library
|
||||
template: ./default-common-plugin-package
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
description: A new Node.js library plugin package
|
||||
template: ./default-node-plugin-package
|
||||
role: plugin-node-library
|
||||
template: ./default-node-plugin-package
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
description: A new frontend plugin
|
||||
template: ./default-plugin
|
||||
role: frontend-plugin
|
||||
template: ./default-plugin
|
||||
templateValues:
|
||||
pluginVar: '{{ camelCase pluginId }}Plugin'
|
||||
extensionName: '{{ upperFirst ( camelCase pluginId ) }}Page'
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
description: A new web library plugin package
|
||||
template: ./default-react-plugin-package
|
||||
role: plugin-web-library
|
||||
template: ./default-react-plugin-package
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
description: A new node-library package, exporting shared functionality for backend plugins and modules
|
||||
template: ./node-library-package
|
||||
role: node-library
|
||||
template: ./node-library-package
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
description: A module exporting custom actions for @backstage/plugin-scaffolder-backend
|
||||
template: ./scaffolder-module
|
||||
role: backend-plugin-module
|
||||
template: ./scaffolder-module
|
||||
params:
|
||||
pluginId: scaffolder
|
||||
templateValues:
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
description: A new web-library package, exporting shared functionality for frontend plugins
|
||||
template: ./web-library-package
|
||||
role: web-library
|
||||
template: ./web-library-package
|
||||
|
||||
Reference in New Issue
Block a user