Fix behaviour regression in create-astro (#8634)

This commit is contained in:
Reuben Tier 2023-09-22 14:18:46 +01:00 committed by GitHub
parent bd00ad776d
commit b64dd45c0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
Fix `--yes` behaviour to prevent it overriding `--template`

View file

@ -9,10 +9,11 @@ import { error, info, spinner, title } from '../messages.js';
export async function template(
ctx: Pick<Context, 'template' | 'prompt' | 'yes' | 'dryRun' | 'exit'>
) {
if (ctx.yes) {
ctx.template = 'basics';
if (!ctx.template && ctx.yes) ctx.template = 'basics';
if (ctx.template) {
await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`);
} else if (!ctx.template) {
} else {
const { template: tmpl } = await ctx.prompt({
name: 'template',
type: 'select',
@ -26,8 +27,6 @@ export async function template(
],
});
ctx.template = tmpl;
} else {
await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`);
}
if (ctx.dryRun) {

View file

@ -33,4 +33,11 @@ describe('template', () => {
expect(fixture.hasMessage('Using blog as project template')).to.be.true;
});
it('minimal (--yes)', async () => {
const context = { template: 'minimal', cwd: '', dryRun: true, yes: true, prompt: () => {} };
await template(context);
expect(fixture.hasMessage('Using minimal as project template')).to.be.true;
})
});