zobro-cli 1.0.9 → 1.1.1
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/index.js +25 -65
- package/package.json +1 -1
package/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GEMINI_API_KEY=AIzaSyBY0LrIq4HTmCfgN-1XuuiKpYUpTAeSiKU
|
package/index.js
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
5
|
const yargs = require('yargs/yargs');
|
|
6
6
|
const { hideBin } = require('yargs/helpers');
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
const API_KEY =
|
|
8
|
+
// 🛡️ SECURE: No hardcoded key. It pulls from your computer's system settings.
|
|
9
|
+
const API_KEY = process.env.GEMINI_API_KEY;
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Generates a full project structure based on a prompt.
|
|
13
|
-
* @param {string} prompt - The user's project request.
|
|
14
|
-
* @param {string} directoryName - The name of the folder to create the project in.
|
|
15
|
-
*/
|
|
16
11
|
async function generateProject(prompt, directoryName) {
|
|
12
|
+
// Check if the key exists before running
|
|
13
|
+
if (!API_KEY) {
|
|
14
|
+
console.error('❌ ERROR: API Key not found on this system.');
|
|
15
|
+
console.log('👉 To fix this, run: setx GEMINI_API_KEY "your_real_key_here"');
|
|
16
|
+
console.log('Then restart your terminal.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
17
20
|
const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
|
|
18
21
|
|
|
19
|
-
// --- This is the new, "smarter" prompt ---
|
|
20
|
-
// We are asking the AI to act as a file structure generator
|
|
21
|
-
// and return a specific JSON format.
|
|
22
22
|
const newPrompt = `
|
|
23
23
|
You are an expert software developer and project scaffolder.
|
|
24
24
|
Based on the user's prompt, generate a complete file structure as a JSON array.
|
|
25
25
|
Each object in the array must have two keys:
|
|
26
|
-
1. "filename": (string) The full relative path for the file
|
|
26
|
+
1. "filename": (string) The full relative path for the file.
|
|
27
27
|
2. "code": (string) The complete code for that file.
|
|
28
28
|
|
|
29
|
-
Only return the raw JSON array, with no other text
|
|
29
|
+
Only return the raw JSON array, with no other text or markdown fences.
|
|
30
|
+
User Prompt: "${prompt}"`;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
const body = {
|
|
35
|
-
contents: [{ parts: [{ text: newPrompt }] }]
|
|
36
|
-
};
|
|
32
|
+
const body = { contents: [{ parts: [{ text: newPrompt }] }] };
|
|
37
33
|
|
|
38
34
|
try {
|
|
39
|
-
console.log(`🤖
|
|
35
|
+
console.log(`🤖 Building project in "${directoryName}"...`);
|
|
40
36
|
|
|
41
37
|
const response = await fetch(url, {
|
|
42
38
|
method: 'POST',
|
|
@@ -53,75 +49,39 @@ User Prompt: "${prompt}"
|
|
|
53
49
|
const data = await response.json();
|
|
54
50
|
let responseText = data.candidates[0].content.parts[0].text;
|
|
55
51
|
|
|
56
|
-
// --- NEW JSON PARSING & FILE CREATION LOGIC ---
|
|
57
|
-
console.log("🤖 AI response received. Building project...");
|
|
58
|
-
|
|
59
|
-
// Clean up potential markdown fences from the AI's response
|
|
60
52
|
if (responseText.startsWith("```json")) {
|
|
61
53
|
responseText = responseText.substring(7, responseText.length - 3).trim();
|
|
62
54
|
}
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
files = JSON.parse(responseText);
|
|
67
|
-
if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
|
|
68
|
-
} catch (parseError) {
|
|
69
|
-
console.error("❌ ERROR: Failed to parse the AI's response. The response was not valid JSON.");
|
|
70
|
-
console.error("Raw AI Response:", responseText);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Create the main project directory
|
|
56
|
+
const files = JSON.parse(responseText);
|
|
75
57
|
fs.mkdirSync(directoryName, { recursive: true });
|
|
76
|
-
console.log(`📁 Created base directory: ${directoryName}`);
|
|
77
58
|
|
|
78
|
-
// Loop through the files array and create each file
|
|
79
59
|
for (const file of files) {
|
|
80
60
|
const filePath = path.join(directoryName, file.filename);
|
|
81
61
|
const fileDir = path.dirname(filePath);
|
|
82
|
-
|
|
83
|
-
// Create subdirectories if they don't exist
|
|
84
|
-
if (!fs.existsSync(fileDir)) {
|
|
85
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Write the code to the file
|
|
62
|
+
if (!fs.existsSync(fileDir)) fs.mkdirSync(fileDir, { recursive: true });
|
|
89
63
|
fs.writeFileSync(filePath, file.code);
|
|
90
|
-
console.log(`✅ Created
|
|
64
|
+
console.log(`✅ Created: ${file.filename}`);
|
|
91
65
|
}
|
|
92
66
|
|
|
93
|
-
console.log(`\n🎉 Project
|
|
67
|
+
console.log(`\n🎉 Done! Project is ready.`);
|
|
94
68
|
|
|
95
69
|
} catch (error) {
|
|
96
70
|
console.error('❌ An error occurred:', error.message);
|
|
97
71
|
}
|
|
98
72
|
}
|
|
99
73
|
|
|
100
|
-
// --- NEW YARGS SETUP ---
|
|
101
74
|
yargs(hideBin(process.argv))
|
|
102
75
|
.command(
|
|
103
|
-
'$0 <prompt>',
|
|
104
|
-
'Generates a full project structure
|
|
76
|
+
'$0 <prompt>',
|
|
77
|
+
'Generates a full project structure.',
|
|
105
78
|
(yargs) => {
|
|
106
79
|
return yargs
|
|
107
|
-
.positional('prompt', {
|
|
108
|
-
|
|
109
|
-
type: 'string',
|
|
110
|
-
})
|
|
111
|
-
.option('directory', { // Replaces the old 'output' flag
|
|
112
|
-
alias: 'd',
|
|
113
|
-
describe: 'The name of the new directory to create the project in',
|
|
114
|
-
type: 'string',
|
|
115
|
-
demandOption: true, // This flag is now required
|
|
116
|
-
});
|
|
80
|
+
.positional('prompt', { type: 'string' })
|
|
81
|
+
.option('directory', { alias: 'd', type: 'string', demandOption: true });
|
|
117
82
|
},
|
|
118
83
|
(argv) => {
|
|
119
|
-
if (!API_KEY || API_KEY === "YOUR_GEMINI_API_KEY_HERE") {
|
|
120
|
-
console.error('❌ ERROR: Please add your API key to the index.js file.');
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
84
|
generateProject(argv.prompt, argv.directory);
|
|
124
85
|
}
|
|
125
86
|
)
|
|
126
|
-
.demandCommand(1, 'Please provide a prompt.')
|
|
127
87
|
.parse();
|