Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,26 @@ const parseArgv = (processArgv: string[]) => {
return argv;
};

function validateCustomTemplateOptions(argv: Argv, templateName: string) {
const unsupportedOptions: string[] = [];
if (argv.tools !== undefined) {
unsupportedOptions.push('--tools');
}
if (argv.skill !== undefined) {
unsupportedOptions.push('--skill');
}
const templateVersion = argv.templateVersion ?? argv['template-version'];
if (templateVersion !== undefined) {
unsupportedOptions.push('--template-version');
}

if (unsupportedOptions.length) {
throw new Error(
`Template "${templateName}" does not support ${unsupportedOptions.join(', ')}. Remove the unsupported options and use the template's setup flow instead.`,
);
}
}

type ExtraTool = {
/**
* The value of the multiselect option.
Expand Down Expand Up @@ -846,6 +866,8 @@ export async function create({
typeof template !== 'string' && template.name === templateName,
);
if (typeof customTemplate === 'object') {
validateCustomTemplateOptions(argv, templateName);

await customTemplate.create({
distFolder,
packageName:
Expand Down
16 changes: 16 additions & 0 deletions test/custom-templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ test('should propagate errors from a custom template', async () => {

await expect(create(options)).rejects.toBe(error);
});

test.each([
{
args: ['--tools', '', '--skill', 'example-skill', '--template-version', ''],
unsupported: '--tools, --skill, --template-version',
},
{ args: ['--templateVersion', '1.0.0'], unsupported: '--template-version' },
])(
'should reject unsupported options: $args',
async ({ args, unsupported }) => {
await expect(
create({ ...options, argv: [...options.argv, ...args] }),
).rejects.toThrow(`Template "external" does not support ${unsupported}.`);
expect(createTemplate).not.toHaveBeenCalled();
},
);
Loading