Skip to content

Commit

Permalink
fix: 🧩 修复生成组件或生成Hooks失败时仍然显示正在生成中的提示
Browse files Browse the repository at this point in the history
  • Loading branch information
v-ouzex committed Jun 28, 2024
1 parent f72bb81 commit f1f170e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/core/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default async function createComponents({
componentName: string;
componentPath: string | undefined;
}) {
const s = spinner();
try {
await validateFileName(componentName);

Expand All @@ -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, {
Expand Down Expand Up @@ -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();
}
}
5 changes: 3 additions & 2 deletions src/core/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}

0 comments on commit f1f170e

Please sign in to comment.