From f1f170ed2bf3f0ba64c9fcaad373ba5d243ab208 Mon Sep 17 00:00:00 2001 From: v-ouzex Date: Fri, 28 Jun 2024 17:48:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=A7=A9=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=BB=84=E4=BB=B6=E6=88=96=E7=94=9F=E6=88=90?= =?UTF-8?q?Hooks=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=BB=8D=E7=84=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=AD=A3=E5=9C=A8=E7=94=9F=E6=88=90=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/components/index.ts | 5 +++-- src/core/hooks/index.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/components/index.ts b/src/core/components/index.ts index 0a74d80..ea42772 100644 --- a/src/core/components/index.ts +++ b/src/core/components/index.ts @@ -21,6 +21,7 @@ export default async function createComponents({ componentName: string; componentPath: string | undefined; }) { + const s = spinner(); try { await validateFileName(componentName); @@ -35,7 +36,6 @@ export default async function createComponents({ const openAiClient = await getOpenAiClient(); - const s = spinner(); s.start('AI is generating components for you'); const response = await openAiClient.post(OPENAI_CHAT_COMPLETIONS_ENDPOINT, { @@ -91,10 +91,11 @@ export default async function createComponents({ } } - s.stop(); outro('Component creation complete 🎉🎉🎉'); } catch (error) { console.error('Error creating component:', error); // Handle specific errors or log them appropriately + } finally { + s.stop(); } } diff --git a/src/core/hooks/index.ts b/src/core/hooks/index.ts index 12c9ee8..8f245be 100644 --- a/src/core/hooks/index.ts +++ b/src/core/hooks/index.ts @@ -70,13 +70,13 @@ async function writeCodeBlocksToFile( } export default async function generatorHooks(fileName: string) { + const s = spinner(); try { await validateFileName(fileName); const input = (await getUserInput()) as CustomHooksSelection; const prompts = generatorComponentPrompt(input); - const s = spinner(); s.start('AI is generating hooks for you'); const completion = await getOpenAIResponse(prompts); @@ -94,9 +94,10 @@ export default async function generatorHooks(fileName: string) { await writeCodeBlocksToFile(result, outputDir, fileName, prefix); - s.stop(); outro('Hooks creation complete 🎉🎉🎉'); } catch (error) { console.error(error); + } finally { + s.stop(); } }