@thebros/create-benjamin 1.0.3 ā 1.0.5
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.
- package/.env +1 -0
- package/bin/index.js +77 -17
- package/package.json +4 -5
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
|
|
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("
|
|
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: "
|
|
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
|
|
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("
|
|
42
|
+
const spinner = ora("Generating project with AI...").start();
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
98
|
+
console.log(chalk.green("\nā
AI project created!"));
|
|
43
99
|
|
|
44
|
-
console.log(
|
|
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,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thebros/create-benjamin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
|
-
|
|
6
5
|
"bin": {
|
|
7
6
|
"create-benjamin": "./bin/index.js"
|
|
8
7
|
},
|
|
9
|
-
|
|
10
8
|
"dependencies": {
|
|
11
9
|
"chalk": "^5.3.0",
|
|
10
|
+
"dotenv": "^17.4.2",
|
|
12
11
|
"execa": "^8.0.1",
|
|
13
12
|
"figlet": "^1.7.0",
|
|
14
13
|
"fs-extra": "^11.2.0",
|
|
15
14
|
"inquirer": "^9.2.15",
|
|
15
|
+
"openai": "^6.39.0",
|
|
16
16
|
"ora": "^8.0.1"
|
|
17
17
|
},
|
|
18
|
-
|
|
19
18
|
"publishConfig": {
|
|
20
19
|
"access": "public"
|
|
21
20
|
}
|
|
22
|
-
}
|
|
21
|
+
}
|