@thebros/create-benjamin 1.0.12 → 1.0.14

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 (2) hide show
  1. package/bin/index.js +58 -78
  2. package/package.json +3 -1
package/bin/index.js CHANGED
@@ -1,116 +1,96 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import "dotenv/config";
4
3
  import fs from "fs-extra";
5
4
  import path from "path";
6
5
  import chalk from "chalk";
7
6
  import inquirer from "inquirer";
8
7
  import ora from "ora";
9
- import OpenAI from "openai";
8
+ import degit from "degit";
10
9
 
11
- async function main() {
12
- console.log(chalk.cyan("\nšŸ¤– Create Benjamin AI Generator\n"));
13
-
14
- // ===== GET API KEY =====
15
- let apiKey = process.env.OPENAI_API_KEY;
16
-
17
- if (!apiKey) {
18
- const answer = await inquirer.prompt([
19
- {
20
- type: "password",
21
- name: "key",
22
- message: "Enter OpenAI API Key:",
23
- },
24
- ]);
25
-
26
- apiKey = answer.key;
27
-
28
- if (!apiKey) {
29
- console.log("āŒ No API key provided");
30
- process.exit(1);
31
- }
32
- }
10
+ async function cloneRepo(repo, target) {
11
+ const emitter = degit(repo, {
12
+ cache: false,
13
+ force: true,
14
+ });
15
+
16
+ await emitter.clone(target);
17
+ }
33
18
 
34
- const openai = new OpenAI({ apiKey });
19
+ async function main() {
20
+ console.log(chalk.cyan("\nšŸš€ Benjamin Template Generator\n"));
35
21
 
36
- // ===== USER INPUT =====
37
22
  const answers = await inquirer.prompt([
38
23
  {
39
24
  type: "input",
40
25
  name: "projectName",
41
26
  message: "Project name:",
42
- default: "ai-app",
27
+ default: "my-app",
43
28
  },
44
29
  {
45
- type: "input",
46
- name: "description",
47
- message: "Describe your project:",
30
+ type: "list",
31
+ name: "type",
32
+ message: "Project type:",
33
+ choices: [
34
+ "Full Stack (React + Node)",
35
+ "Frontend (React)",
36
+ "Backend (Express)",
37
+ ],
48
38
  },
49
39
  ]);
50
40
 
51
- const projectName = answers.projectName.trim();
52
- const root = path.join(process.cwd(), projectName);
41
+ const root = path.join(process.cwd(), answers.projectName);
53
42
 
54
43
  if (fs.existsSync(root)) {
55
- console.log(chalk.red("Project already exists"));
44
+ console.log(chalk.red("āŒ Project already exists"));
56
45
  process.exit(1);
57
46
  }
58
47
 
59
48
  await fs.mkdir(root);
60
49
 
61
- const spinner = ora("Generating project with AI...").start();
62
-
63
- // ===== PROMPT =====
64
- const prompt = `
65
- You are a senior full-stack developer.
66
-
67
- Generate a full project for:
68
-
69
- ${answers.description}
50
+ const spinner = ora("Fetching templates from internet...").start();
70
51
 
71
- Return ONLY valid JSON:
72
-
73
- {
74
- "files": {
75
- "path/to/file": "file content"
76
- }
77
- }
78
- `;
79
-
80
- // ===== AI CALL =====
81
- const response = await openai.chat.completions.create({
82
- model: "gpt-4o-mini",
83
- messages: [{ role: "user", content: prompt }],
84
- temperature: 0.3,
85
- });
86
-
87
- let text = response.choices[0].message.content;
88
-
89
- text = text.replace(/```json/g, "").replace(/```/g, "");
90
-
91
- let project;
92
-
93
- try {
94
- project = JSON.parse(text);
95
- } catch (err) {
96
- spinner.fail("AI returned invalid JSON");
97
- console.log(text);
98
- process.exit(1);
52
+ // =========================
53
+ // FRONTEND
54
+ // =========================
55
+ if (
56
+ answers.type.includes("Frontend") ||
57
+ answers.type.includes("Full")
58
+ ) {
59
+ await cloneRepo("vitejs/vite", path.join(root, "frontend"));
99
60
  }
100
61
 
101
- // ===== CREATE FILES =====
102
- for (const filePath in project.files) {
103
- const fullPath = path.join(root, filePath);
104
- await fs.ensureDir(path.dirname(fullPath));
105
- await fs.writeFile(fullPath, project.files[filePath]);
62
+ // =========================
63
+ // BACKEND
64
+ // =========================
65
+ if (
66
+ answers.type.includes("Backend") ||
67
+ answers.type.includes("Full")
68
+ ) {
69
+ await cloneRepo("expressjs/express", path.join(root, "backend"));
70
+
71
+ await fs.writeFile(
72
+ path.join(root, "backend", "server.js"),
73
+ `
74
+ const express = require("express");
75
+ const app = express();
76
+
77
+ app.get("/", (req, res) => {
78
+ res.json({ message: "API Running" });
79
+ });
80
+
81
+ app.listen(5000, () => {
82
+ console.log("Server running on 5000");
83
+ });
84
+ `
85
+ );
106
86
  }
107
87
 
108
- spinner.succeed("Project generated successfully");
88
+ spinner.succeed("Project created successfully");
109
89
 
110
- console.log(chalk.green("\nāœ… AI project created!"));
90
+ console.log(chalk.green("\nāœ… Done!\n"));
111
91
 
112
92
  console.log(`
113
- cd ${projectName}
93
+ cd ${answers.projectName}
114
94
  npm install
115
95
  npm run dev
116
96
  `);
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@thebros/create-benjamin",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "create-benjamin": "./bin/index.js"
7
7
  },
8
8
  "dependencies": {
9
9
  "chalk": "^5.6.2",
10
+ "degit": "^3.0.0",
10
11
  "dotenv": "^17.4.2",
11
12
  "execa": "^8.0.1",
12
13
  "figlet": "^1.7.0",
13
14
  "fs-extra": "^11.3.5",
14
15
  "inquirer": "^9.3.8",
16
+ "node-fetch": "^3.3.2",
15
17
  "openai": "^6.39.0",
16
18
  "ora": "^8.2.0"
17
19
  },