cli/new: remove ability to load template contents from a separate dir

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-02-11 11:13:50 +01:00
parent 97a8632cfa
commit 82107cd9a5
3 changed files with 2 additions and 58 deletions
-2
View File
@@ -106,7 +106,6 @@ Your first step in creating your own CLI template is composing your yaml file:
name: custom-plugin
role: frontend-plugin
description: Description of my CLI template # optional
files: ./template # optional
templateValues: # optional
pluginVar: '{{ camelCase pluginId }}Plugin'
```
@@ -116,7 +115,6 @@ The following properties are supported:
- `name` **(required)** - The name of your template, used by the user to select it.
- `role` **(required)** - The role of the template, similar to package role. See [Template Roles](#template-roles) for more details.
- `description` - A description of the type of package that this template produces.
- `files` - A directory or list of relative file paths pointing to the contents of your template. Defaults to the current directory.
- `parameters` - A map of pre-filled parameters that will be used instead of prompting the user for input.
- `templateValues` - A map of additional values that will be present during templating. The values are themselves templated and can reference other values.
@@ -49,32 +49,6 @@ describe('loadTemplate', () => {
});
});
it('should load a valid template with files in a separate dir', async () => {
mockDir.setContent({
'path/to/template.yaml': `
name: template1
role: frontend-plugin
files: content
parameters:
foo: bar
`,
'path/to/content/hello.txt': 'hello world',
});
await expect(
loadPortableTemplate({
name: 'template1',
target: mockDir.resolve('path/to/template.yaml'),
}),
).resolves.toEqual({
name: 'template1',
role: 'frontend-plugin',
files: [{ path: 'hello.txt', content: 'hello world' }],
parameters: { foo: 'bar' },
templateValues: {},
});
});
it('should throw an error if template file does not exist', async () => {
mockDir.setContent({});
@@ -117,7 +91,6 @@ describe('loadTemplate', () => {
'path/to/template1.yaml': `
name: x
role: invalid-role
files: template1
`,
});
@@ -132,25 +105,4 @@ describe('loadTemplate', () => {
)}'; caused by Validation error: Invalid enum value`,
);
});
it('should throw an error if template directory does not exist', async () => {
mockDir.setContent({
'path/to/template1.yaml': `
name: x
role: frontend-plugin
files: template1
`,
});
await expect(
loadPortableTemplate({
name: 'template1',
target: mockDir.resolve('path/to/template1.yaml'),
}),
).rejects.toThrow(
`Failed to load template contents from '${mockDir.resolve(
'path/to/template1',
)}'`,
);
});
});
@@ -35,7 +35,6 @@ const templateDefinitionSchema = z
name: z.string(),
role: z.enum(TEMPLATE_ROLES),
description: z.string().optional(),
files: z.string().optional(),
parameters: z.record(z.string()).optional(),
templateValues: z.record(z.string()).optional(),
})
@@ -65,14 +64,9 @@ export async function loadPortableTemplate(
);
}
const {
role,
files = '.',
parameters = {},
templateValues = {},
} = parsed.data;
const { role, parameters = {}, templateValues = {} } = parsed.data;
const templatePath = resolvePath(dirname(pointer.target), files);
const templatePath = resolvePath(dirname(pointer.target));
const filePaths = await recursiveReaddir(templatePath).catch(error => {
throw new ForwardedError(
`Failed to load template contents from '${templatePath}'`,