From 246777ef93c557916eb67864d0a6ad42c705dc73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hegyi=20=C3=81ron=20Ferenc?= Date: Thu, 25 Jan 2024 22:13:26 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20bug=20with=20init=20not?= =?UTF-8?q?=20prompting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/init.ts | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/commands/init.ts b/src/commands/init.ts index 3811acf..6332de0 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -22,9 +22,9 @@ export default defineCommand({ }, async run(ctx) { await checkGitHook(!ctx.args.config) // if config is not specified, perform a clean init - const configType = (ctx.args.config ? ctx.args.config : 'none') as ConfigType + let configType = ctx.args.config as ConfigType | undefined - if (configType !== 'none') { + if (!configType && configType !== 'none') { const options = { label: { ts: 'TypeScript', @@ -38,29 +38,27 @@ export default defineCommand({ }, } - const selectedConfigType = configTypes.includes(configType) - ? configType - : await consola.prompt('Which config would you like to use?', { - type: 'select', - options: configTypes.map(type => ({ - value: type, - label: options.label[type], - hint: options.hint[type], - })), - }) + configType = await consola.prompt('Which config would you like to use?', { + type: 'select', + options: configTypes.map(type => ({ + value: type, + label: options.label[type], + hint: options.hint[type], + })), + }) as unknown as ConfigType // consola.prompt types are wrong + } - if (selectedConfigType === 'json') { - if (await consola.prompt('Add JSON schema for types? (VSCode only)', { - type: 'confirm', - initial: true, - })) - checkJsonSchema() + if (configType === 'json') { + if (await consola.prompt('Add JSON schema for types? (VSCode only)', { + type: 'confirm', + initial: true, + })) + checkJsonSchema() - createConfigFile(C.jsonFiles[0], JSON.stringify(C.defaultConfig, null, 2)) - } - else if (selectedConfigType === 'ts') { - createConfigFile(C.jsFiles[0], C.defaultTsConfig) - } + createConfigFile(C.jsonFiles[0], JSON.stringify(C.defaultConfig, null, 2)) + } + else if (configType === 'ts') { + createConfigFile(C.jsFiles[0], C.defaultTsConfig) } consola.success('Initialized eemoji!')