@thebros/create-benjamin 1.0.13 → 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 +65 -89
  2. package/package.json +3 -1
package/bin/index.js CHANGED
@@ -1,62 +1,44 @@
1
1
  #!/usr/bin/env node
2
- import "dotenv/config";
2
+
3
3
  import fs from "fs-extra";
4
4
  import path from "path";
5
5
  import chalk from "chalk";
6
6
  import inquirer from "inquirer";
7
7
  import ora from "ora";
8
- import OpenAI from "openai";
8
+ import degit from "degit";
9
9
 
10
- async function main() {
11
- console.log(chalk.cyan("\nšŸ¤– Create Benjamin AI Generator\n"));
12
-
13
- // ===== DEBUG: Check if .env loaded =====
14
- console.log("Key loaded from env:", !!process.env.OPENAI_API_KEY);
15
-
16
- // ===== GET API KEY =====
17
- let apiKey = process.env.OPENAI_API_KEY;
18
-
19
- if (!apiKey) {
20
- const answer = await inquirer.prompt([
21
- {
22
- type: "password",
23
- name: "key",
24
- message: "Enter OpenAI API Key:",
25
- },
26
- ]);
27
-
28
- apiKey = answer.key.trim(); // āœ… trim whitespace
29
-
30
- if (!apiKey) {
31
- console.log(chalk.red("āŒ No API key provided"));
32
- process.exit(1);
33
- }
34
-
35
- if (!apiKey.startsWith("sk-")) {
36
- console.log(chalk.red("āŒ That doesn't look like a valid OpenAI key (should start with sk-)"));
37
- process.exit(1);
38
- }
39
- }
10
+ async function cloneRepo(repo, target) {
11
+ const emitter = degit(repo, {
12
+ cache: false,
13
+ force: true,
14
+ });
40
15
 
41
- const openai = new OpenAI({ apiKey });
16
+ await emitter.clone(target);
17
+ }
18
+
19
+ async function main() {
20
+ console.log(chalk.cyan("\nšŸš€ Benjamin Template Generator\n"));
42
21
 
43
- // ===== USER INPUT =====
44
22
  const answers = await inquirer.prompt([
45
23
  {
46
24
  type: "input",
47
25
  name: "projectName",
48
26
  message: "Project name:",
49
- default: "ai-app",
27
+ default: "my-app",
50
28
  },
51
29
  {
52
- type: "input",
53
- name: "description",
54
- 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
+ ],
55
38
  },
56
39
  ]);
57
40
 
58
- const projectName = answers.projectName.trim();
59
- const root = path.join(process.cwd(), projectName);
41
+ const root = path.join(process.cwd(), answers.projectName);
60
42
 
61
43
  if (fs.existsSync(root)) {
62
44
  console.log(chalk.red("āŒ Project already exists"));
@@ -65,59 +47,53 @@ async function main() {
65
47
 
66
48
  await fs.mkdir(root);
67
49
 
68
- const spinner = ora("Generating project with AI...").start();
69
-
70
- // ===== PROMPT =====
71
- const prompt = `You are a senior full-stack developer.
72
- Generate a full project for:
73
- ${answers.description}
74
-
75
- Return ONLY valid JSON:
76
- {"files": {"path/to/file": "file content"}}`;
77
-
78
- // ===== AI CALL =====
79
- let response;
80
- try {
81
- response = await openai.chat.completions.create({
82
- model: "gpt-4o-mini",
83
- messages: [{ role: "user", content: prompt }],
84
- temperature: 0.3,
85
- });
86
- } catch (err) {
87
- spinner.fail("OpenAI API call failed");
88
- console.log(chalk.red("Error: " + err.message));
89
- if (err.status === 401) {
90
- console.log(chalk.yellow("→ Your API key is invalid or expired. Check: https://platform.openai.com/api-keys"));
91
- } else if (err.status === 429) {
92
- console.log(chalk.yellow("→ Rate limit or quota exceeded. Check your usage at: https://platform.openai.com/usage"));
93
- } else if (err.status === 404) {
94
- console.log(chalk.yellow("→ Model not available on your account. Try changing model to 'gpt-3.5-turbo'"));
95
- }
96
- process.exit(1);
97
- }
98
-
99
- let text = response.choices[0].message.content;
100
- text = text.replace(/```json/g, "").replace(/```/g, "").trim();
50
+ const spinner = ora("Fetching templates from internet...").start();
101
51
 
102
- let project;
103
- try {
104
- project = JSON.parse(text);
105
- } catch (err) {
106
- spinner.fail("AI returned invalid JSON");
107
- console.log(chalk.red("Raw response:"), text);
108
- 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"));
109
60
  }
110
61
 
111
- // ===== CREATE FILES =====
112
- for (const filePath in project.files) {
113
- const fullPath = path.join(root, filePath);
114
- await fs.ensureDir(path.dirname(fullPath));
115
- 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
+ );
116
86
  }
117
87
 
118
- spinner.succeed("Project generated successfully");
119
- console.log(chalk.green("\nāœ… AI project created!"));
120
- console.log(`cd ${projectName}\nnpm install\nnpm run dev`);
88
+ spinner.succeed("Project created successfully");
89
+
90
+ console.log(chalk.green("\nāœ… Done!\n"));
91
+
92
+ console.log(`
93
+ cd ${answers.projectName}
94
+ npm install
95
+ npm run dev
96
+ `);
121
97
  }
122
98
 
123
- main();
99
+ main();
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@thebros/create-benjamin",
3
- "version": "1.0.13",
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
  },