fix(create-astro): typescript prompt handling (#5958)

* fix(create-astro): typescript prompt handling

* fallback

* fix(create-astro): additional case

Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
Nate Moore 2023-01-24 11:01:26 -06:00 committed by Matthew Phillips
parent ab7e1b9a5a
commit c69c364c9f
2 changed files with 9 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
Fix typescript prompt handling

View file

@ -312,7 +312,7 @@ export async function main() {
args.typescript = 'strict'; args.typescript = 'strict';
} }
const tsResponse = let tsResponse =
args.typescript || args.typescript ||
( (
await prompts( await prompts(
@ -342,7 +342,7 @@ export async function main() {
if (tsResponse === 'unsure') { if (tsResponse === 'unsure') {
await typescriptByDefault(); await typescriptByDefault();
tsResponse.typescript = 'base'; tsResponse = 'base';
} }
if (args.dryRun) { if (args.dryRun) {
ora().info(dim(`--dry-run enabled, skipping.`)); ora().info(dim(`--dry-run enabled, skipping.`));
@ -353,7 +353,7 @@ export async function main() {
// If the template doesn't have a tsconfig.json, let's add one instead // If the template doesn't have a tsconfig.json, let's add one instead
fs.writeFileSync( fs.writeFileSync(
templateTSConfigPath, templateTSConfigPath,
stringify({ extends: `astro/tsconfigs/${tsResponse}` }, null, 2) stringify({ extends: `astro/tsconfigs/${tsResponse ?? 'base'}` }, null, 2)
); );
return; return;
@ -363,7 +363,7 @@ export async function main() {
if (templateTSConfig && typeof templateTSConfig === 'object') { if (templateTSConfig && typeof templateTSConfig === 'object') {
const result = assign(templateTSConfig, { const result = assign(templateTSConfig, {
extends: `astro/tsconfigs/${tsResponse.typescript}`, extends: `astro/tsconfigs/${tsResponse ?? 'base'}`,
}); });
fs.writeFileSync(templateTSConfigPath, stringify(result, null, 2)); fs.writeFileSync(templateTSConfigPath, stringify(result, null, 2));