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(); } }