@thebros/create-benjamin 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/.env +1 -0
  2. package/bin/index.js +77 -17
  3. package/package.json +11 -15
package/.env ADDED
@@ -0,0 +1 @@
1
+ OPENAI_API_KEY=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
package/bin/index.js CHANGED
@@ -5,21 +5,32 @@ import path from "path";
5
5
  import chalk from "chalk";
6
6
  import inquirer from "inquirer";
7
7
  import ora from "ora";
8
- import { execa } from "execa";
8
+ import OpenAI from "openai";
9
+ import "dotenv/config";
10
+
11
+ const openai = new OpenAI({
12
+ apiKey: process.env.OPENAI_API_KEY,
13
+ });
9
14
 
10
15
  async function main() {
11
- console.log(chalk.cyan("\\nšŸš€ Create Benjamin Fullstack App\\n"));
16
+ console.log(chalk.cyan("\nšŸ¤– Create Benjamin AI Project Generator\n"));
12
17
 
13
18
  const answers = await inquirer.prompt([
14
19
  {
15
20
  type: "input",
16
21
  name: "projectName",
17
22
  message: "Project name:",
18
- default: "my-app"
19
- }
23
+ default: "ai-app",
24
+ },
25
+ {
26
+ type: "input",
27
+ name: "description",
28
+ message: "Describe your project (be detailed):",
29
+ },
20
30
  ]);
21
31
 
22
- const root = path.join(process.cwd(), answers.projectName);
32
+ const projectName = answers.projectName.trim();
33
+ const root = path.join(process.cwd(), projectName);
23
34
 
24
35
  if (fs.existsSync(root)) {
25
36
  console.log(chalk.red("Project already exists"));
@@ -28,20 +39,69 @@ async function main() {
28
39
 
29
40
  await fs.mkdir(root);
30
41
 
31
- const spinner = ora("Creating frontend...").start();
42
+ const spinner = ora("Generating project with AI...").start();
32
43
 
33
- await execa(
34
- "npm",
35
- ["create", "vite@latest", "frontend", "--", "--template", "react"],
36
- {
37
- cwd: root,
38
- stdio: "inherit"
39
- }
40
- );
44
+ // ===== AI PROMPT =====
45
+ const prompt = `
46
+ You are a senior full-stack developer.
47
+
48
+ Generate a complete project structure and code for this app:
49
+
50
+ Project: ${answers.description}
51
+
52
+ Rules:
53
+ - Must be Node.js backend + React frontend if needed
54
+ - Use Express for backend
55
+ - Use React + Vite for frontend
56
+ - Use MySQL if database needed
57
+ - Include folder structure
58
+ - Include working code files
59
+ - Return ONLY JSON in this format:
60
+
61
+ {
62
+ "files": {
63
+ "path/to/file": "file content"
64
+ }
65
+ }
66
+ `;
67
+
68
+ const response = await openai.chat.completions.create({
69
+ model: "gpt-4o-mini",
70
+ messages: [{ role: "user", content: prompt }],
71
+ temperature: 0.3,
72
+ });
73
+
74
+ let text = response.choices[0].message.content;
75
+
76
+ // Clean AI response
77
+ text = text.replace(/```json/g, "").replace(/```/g, "");
78
+
79
+ let project;
80
+
81
+ try {
82
+ project = JSON.parse(text);
83
+ } catch (err) {
84
+ spinner.fail("AI returned invalid JSON");
85
+ console.log(text);
86
+ process.exit(1);
87
+ }
88
+
89
+ // ===== CREATE FILES =====
90
+ for (const filePath in project.files) {
91
+ const fullPath = path.join(root, filePath);
92
+ await fs.ensureDir(path.dirname(fullPath));
93
+ await fs.writeFile(fullPath, project.files[filePath]);
94
+ }
95
+
96
+ spinner.succeed("Project generated successfully");
41
97
 
42
- spinner.succeed("Frontend created");
98
+ console.log(chalk.green("\nāœ… AI project created!"));
43
99
 
44
- console.log(chalk.green("\\nāœ… Project created successfully"));
100
+ console.log(`
101
+ cd ${projectName}
102
+ npm install
103
+ npm run dev
104
+ `);
45
105
  }
46
106
 
47
- main();
107
+ main();
package/package.json CHANGED
@@ -1,25 +1,21 @@
1
1
  {
2
2
  "name": "@thebros/create-benjamin",
3
- "version": "1.0.2",
4
- "description": "Full-stack scaffolding CLI",
3
+ "version": "1.0.4",
5
4
  "type": "module",
6
- "bin": {
7
- "create-benjamin": "./bin/index.js"
8
- },
9
- "keywords": [
10
- "cli",
11
- "scaffolding",
12
- "react",
13
- "node",
14
- "mysql"
15
- ],
16
- "author": "Benjamin",
17
- "license": "MIT",
5
+ "bin": {
6
+ "create-benjamin": "./bin/index.js"
7
+ },
18
8
  "dependencies": {
19
9
  "chalk": "^5.3.0",
10
+ "dotenv": "^17.4.2",
20
11
  "execa": "^8.0.1",
12
+ "figlet": "^1.7.0",
21
13
  "fs-extra": "^11.2.0",
22
14
  "inquirer": "^9.2.15",
15
+ "openai": "^6.39.0",
23
16
  "ora": "^8.0.1"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
24
20
  }
25
- }
21
+ }