cli/new: add support for predefined template parameters
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -47,11 +47,13 @@ export async function collectPortableTemplateInput(
|
||||
prompts.push(ownerPrompt());
|
||||
}
|
||||
|
||||
const parameters = { ...template.parameters, ...prefilledParams };
|
||||
|
||||
const needsAnswer = [];
|
||||
const prefilledAnswers = {} as PortableTemplateParams;
|
||||
for (const prompt of prompts) {
|
||||
if (prompt.name && prefilledParams[prompt.name] !== undefined) {
|
||||
prefilledAnswers[prompt.name] = prefilledParams[prompt.name];
|
||||
if (prompt.name && parameters[prompt.name] !== undefined) {
|
||||
prefilledAnswers[prompt.name] = parameters[prompt.name];
|
||||
} else {
|
||||
needsAnswer.push(prompt);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ describe('loadTemplate', () => {
|
||||
'path/to/template1.yaml': `
|
||||
template: template1
|
||||
role: frontend-plugin
|
||||
parameters:
|
||||
foo: bar
|
||||
`,
|
||||
'path/to/template1/hello.txt': 'hello world',
|
||||
},
|
||||
@@ -38,6 +40,7 @@ describe('loadTemplate', () => {
|
||||
id: 'template1',
|
||||
role: 'frontend-plugin',
|
||||
files: [{ path: 'hello.txt', content: 'hello world' }],
|
||||
parameters: { foo: 'bar' },
|
||||
templateValues: {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,6 +34,7 @@ const templateDefinitionSchema = z
|
||||
.object({
|
||||
role: z.enum(TEMPLATE_ROLES),
|
||||
template: z.string(),
|
||||
parameters: z.record(z.string()).optional(),
|
||||
templateValues: z.record(z.string()).optional(),
|
||||
})
|
||||
.strict();
|
||||
@@ -62,7 +63,7 @@ export async function loadPortableTemplate(
|
||||
);
|
||||
}
|
||||
|
||||
const { role, template, templateValues = {} } = parsed.data;
|
||||
const { role, template, parameters = {}, templateValues = {} } = parsed.data;
|
||||
|
||||
const templatePath = resolvePath(dirname(pointer.target), template);
|
||||
const filePaths = await recursiveReaddir(templatePath).catch(error => {
|
||||
@@ -91,5 +92,5 @@ export async function loadPortableTemplate(
|
||||
}
|
||||
}
|
||||
|
||||
return { id: pointer.id, role, files, templateValues };
|
||||
return { id: pointer.id, role, files, parameters, templateValues };
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ export type PortableTemplate = {
|
||||
id: string;
|
||||
role: PortableTemplateRole;
|
||||
files: PortableTemplateFile[];
|
||||
parameters: Record<string, string>;
|
||||
templateValues: Record<string, string>;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
role: backend-plugin-module
|
||||
template: ./scaffolder-module
|
||||
params:
|
||||
parameters:
|
||||
pluginId: scaffolder
|
||||
templateValues:
|
||||
moduleVar: '{{ camelCase pluginId }}Module{{ upperFirst ( camelCase moduleId ) }}'
|
||||
|
||||
Reference in New Issue
Block a user