-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·54 lines (45 loc) · 1.53 KB
/
cli.js
File metadata and controls
executable file
·54 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bun
import { showLogo } from "./lib/logo.js";
import { ensureApiKey, changeApiKey } from "./lib/config.js";
import { askMainQuestions, askClarifications } from "./lib/questions.js";
import { generateComponent } from "./lib/generator.js";
import { writeComponent } from "./lib/writer.js";
import prompts from "prompts";
async function main() {
await showLogo();
await ensureApiKey();
const { action } = await prompts({
type: "select",
name: "action",
message: "What would you like to do?",
choices: [
{ title: "Create new component", value: "create" },
{ title: "Change API key", value: "changeKey" },
{ title: "Exit", value: "exit" },
],
});
if (action === "changeKey") {
await changeApiKey();
process.exit(0);
}
if (action === "exit") process.exit(0);
const mainAnswers = await askMainQuestions();
const clarifications = await askClarifications(mainAnswers.componentName);
const promptText = `
Create a React ${mainAnswers.fileType.toUpperCase()} component named "${mainAnswers.componentName}".
The component structure should resemble the following example:
${mainAnswers.exampleCode}
Target folder: ${mainAnswers.targetFolder}
Use hooks: ${mainAnswers.useHooks ? "Yes" : "No"}
Additional details: ${clarifications.details}
`;
const code = await generateComponent(promptText);
await writeComponent(
mainAnswers.targetFolder,
mainAnswers.componentName,
mainAnswers.fileType,
code
);
console.log("\n✅ Component has been created and saved.");
}
main();