Skip to content

Commit

Permalink
Revert "Revert accidental create-astro fix"
Browse files Browse the repository at this point in the history
This reverts commit c13d428.
  • Loading branch information
bholmesdev committed Mar 27, 2023
1 parent c13d428 commit 6be8bb3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ export async function template(ctx: Pick<Context, 'template' | 'prompt' | 'dryRu
while: () =>
copyTemplate(ctx.template!, ctx as Context).catch((e) => {
// eslint-disable-next-line no-console
error('error', e);
process.exit(1);
if (e instanceof Error) {
error('error', e.message);
process.exit(1);
} else {
error('error', 'Unable to clone template.');
process.exit(1);
}
}),
});
} else {
Expand Down Expand Up @@ -81,11 +86,18 @@ export default async function copyTemplate(tmpl: string, ctx: Context) {
} catch (err: any) {
fs.rmdirSync(ctx.cwd);
if (err.message.includes('404')) {
await error('Error', `Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
} else {
console.error(err.message);
throw new Error(err.message);
}
ctx.exit(1);
}

// It's possible the repo exists (ex. `withastro/astro`),
// But the template route is invalid (ex. `withastro/astro/examples/DNE`).
// `giget` doesn't throw for this case,
// so check if the directory is still empty as a heuristic.
if (fs.readdirSync(ctx.cwd).length === 0) {
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('is empty!')}`);
}

// Post-process in parallel
Expand Down

0 comments on commit 6be8bb3

Please sign in to comment.