Revert accidental create-astro fix

This commit is contained in:
bholmesdev 2023-03-27 17:46:00 -04:00
parent c853ffc606
commit c13d428a78

View file

@ -35,13 +35,8 @@ export async function template(ctx: Pick<Context, 'template' | 'prompt' | 'dryRu
while: () => while: () =>
copyTemplate(ctx.template!, ctx as Context).catch((e) => { copyTemplate(ctx.template!, ctx as Context).catch((e) => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
if (e instanceof Error) { error('error', e);
error('error', e.message);
process.exit(1); process.exit(1);
} else {
error('error', 'Unable to clone template.');
process.exit(1);
}
}), }),
}); });
} else { } else {
@ -86,18 +81,11 @@ export default async function copyTemplate(tmpl: string, ctx: Context) {
} catch (err: any) { } catch (err: any) {
fs.rmdirSync(ctx.cwd); fs.rmdirSync(ctx.cwd);
if (err.message.includes('404')) { if (err.message.includes('404')) {
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`); await error('Error', `Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
} else { } else {
throw new Error(err.message); console.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 // Post-process in parallel