Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behaviour regression in create-astro #8634

Merged
merged 4 commits into from
Sep 22, 2023
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
5 changes: 5 additions & 0 deletions .changeset/neat-islands-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Fix `--yes` behaviour to prevent it overriding `--template`
11 changes: 5 additions & 6 deletions packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`);
} else if (!ctx.template) {
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 {
const { template: tmpl } = await ctx.prompt({
name: 'template',
type: 'select',
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions packages/create-astro/test/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
});