diff --git a/src/index.ts b/src/index.ts index e4c7da1..c240ee2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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. @@ -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: diff --git a/test/custom-templates.test.ts b/test/custom-templates.test.ts index 614a11d..8c658c9 100644 --- a/test/custom-templates.test.ts +++ b/test/custom-templates.test.ts @@ -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(); + }, +);