zobro-cli 1.0.7 → 1.1.0

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/index.js +87 -1
  3. package/package.json +1 -1
package/.env ADDED
@@ -0,0 +1 @@
1
+ GEMINI_API_KEY=AIzaSyBY0LrIq4HTmCfgN-1XuuiKpYUpTAeSiKU
package/index.js CHANGED
@@ -1 +1,87 @@
1
- //bduiivjr
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const yargs = require('yargs/yargs');
6
+ const { hideBin } = require('yargs/helpers');
7
+
8
+ // šŸ›”ļø SECURE: No hardcoded key. It pulls from your computer's system settings.
9
+ const API_KEY = process.env.GEMINI_API_KEY;
10
+
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
+
20
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
21
+
22
+ const newPrompt = `
23
+ You are an expert software developer and project scaffolder.
24
+ Based on the user's prompt, generate a complete file structure as a JSON array.
25
+ Each object in the array must have two keys:
26
+ 1. "filename": (string) The full relative path for the file.
27
+ 2. "code": (string) The complete code for that file.
28
+
29
+ Only return the raw JSON array, with no other text or markdown fences.
30
+ User Prompt: "${prompt}"`;
31
+
32
+ const body = { contents: [{ parts: [{ text: newPrompt }] }] };
33
+
34
+ try {
35
+ console.log(`šŸ¤– Building project in "${directoryName}"...`);
36
+
37
+ const response = await fetch(url, {
38
+ method: 'POST',
39
+ headers: { 'Content-Type': 'application/json' },
40
+ body: JSON.stringify(body),
41
+ });
42
+
43
+ if (!response.ok) {
44
+ const errorData = await response.json();
45
+ console.error('āŒ API Error Details:', JSON.stringify(errorData.error, null, 2));
46
+ throw new Error(`API request failed with status ${response.status}`);
47
+ }
48
+
49
+ const data = await response.json();
50
+ let responseText = data.candidates[0].content.parts[0].text;
51
+
52
+ if (responseText.startsWith("```json")) {
53
+ responseText = responseText.substring(7, responseText.length - 3).trim();
54
+ }
55
+
56
+ const files = JSON.parse(responseText);
57
+ fs.mkdirSync(directoryName, { recursive: true });
58
+
59
+ for (const file of files) {
60
+ const filePath = path.join(directoryName, file.filename);
61
+ const fileDir = path.dirname(filePath);
62
+ if (!fs.existsSync(fileDir)) fs.mkdirSync(fileDir, { recursive: true });
63
+ fs.writeFileSync(filePath, file.code);
64
+ console.log(`āœ… Created: ${file.filename}`);
65
+ }
66
+
67
+ console.log(`\nšŸŽ‰ Done! Project is ready.`);
68
+
69
+ } catch (error) {
70
+ console.error('āŒ An error occurred:', error.message);
71
+ }
72
+ }
73
+
74
+ yargs(hideBin(process.argv))
75
+ .command(
76
+ '$0 <prompt>',
77
+ 'Generates a full project structure.',
78
+ (yargs) => {
79
+ return yargs
80
+ .positional('prompt', { type: 'string' })
81
+ .option('directory', { alias: 'd', type: 'string', demandOption: true });
82
+ },
83
+ (argv) => {
84
+ generateProject(argv.prompt, argv.directory);
85
+ }
86
+ )
87
+ .parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zobro-cli",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "zobro-cli": "./index.js"