Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🧩 修复生成组件或生成Hooks失败时仍然显示正在生成中的提示 #15

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading