xoxohp 1.0.2 → 1.0.4

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/index.js +182 -76
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,127 +1,233 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs'); // Node.js File System
4
- const path = require('path'); // Node.js Path module
1
+ // #!/usr/bin/env node
2
+
3
+ // const fs = require('fs'); // Node.js File System
4
+ // const path = require('path'); // Node.js Path module
5
+ // const yargs = require('yargs/yargs');
6
+ // const { hideBin } = require('yargs/helpers');
7
+
8
+ // // ⚠️ Paste your official Google Gemini API key here.
9
+ // const API_KEY = "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";
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
+ // async function generateProject(prompt, directoryName) {
17
+ // const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
18
+
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
+ // 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 (e.g., "index.html", "src/styles.css", "js/app.js").
27
+ // 2. "code": (string) The complete code for that file.
28
+
29
+ // Only return the raw JSON array, with no other text, explanations, or markdown fences.
30
+
31
+ // User Prompt: "${prompt}"
32
+ // `;
33
+
34
+ // const body = {
35
+ // contents: [{ parts: [{ text: newPrompt }] }]
36
+ // };
37
+
38
+ // try {
39
+ // console.log(`Code Running in Expresss`);
40
+
41
+ // const response = await fetch(url, {
42
+ // method: 'POST',
43
+ // headers: { 'Content-Type': 'application/json' },
44
+ // body: JSON.stringify(body),
45
+ // });
46
+
47
+ // if (!response.ok) {
48
+ // const errorData = await response.json();
49
+ // console.error('❌ API Error Details:', JSON.stringify(errorData.error, null, 2));
50
+ // throw new Error(`API request failed with status ${response.status}`);
51
+ // }
52
+
53
+ // const data = await response.json();
54
+ // let responseText = data.candidates[0].content.parts[0].text;
55
+
56
+ // // --- NEW JSON PARSING & FILE CREATION LOGIC ---
57
+ // // console.log("Building project...");
58
+
59
+ // // Clean up potential markdown fences from the AI's response
60
+ // if (responseText.startsWith("```json")) {
61
+ // responseText = responseText.substring(7, responseText.length - 3).trim();
62
+ // }
63
+
64
+ // let files;
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
75
+ // fs.mkdirSync(directoryName, { recursive: true });
76
+ // console.log(``);
77
+
78
+ // // Loop through the files array and create each file
79
+ // for (const file of files) {
80
+ // const filePath = path.join(directoryName, file.filename);
81
+ // 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
89
+ // fs.writeFileSync(filePath, file.code);
90
+ // //console.log(`Created file: ${filePath}`);
91
+ // }
92
+
93
+ // // console.log(`\n🎉 Project "${directoryName}" created successfully!`);
94
+
95
+ // } catch (error) {
96
+ // console.error('❌ An error occurred:', error.message);
97
+ // }
98
+ // }
99
+
100
+ // // --- NEW YARGS SETUP ---
101
+ // yargs(hideBin(process.argv))
102
+ // .command(
103
+ // '$0 <prompt>', // The default command
104
+ // 'Generates a full project structure from a text prompt.',
105
+ // (yargs) => {
106
+ // return yargs
107
+ // .positional('prompt', {
108
+ // describe: 'The project you want to generate',
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
+ // });
117
+ // },
118
+ // (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
+ // generateProject(argv.prompt, argv.directory);
124
+ // }
125
+ // )
126
+ // .demandCommand(1, 'Please provide a prompt.')
127
+ // .parse();
128
+
129
+
130
+ // #!/usr/bin/env node
131
+
132
+ const fs = require('fs');
133
+ const path = require('path');
5
134
  const yargs = require('yargs/yargs');
6
135
  const { hideBin } = require('yargs/helpers');
7
136
 
8
- // ⚠️ Paste your official Google Gemini API key here.
9
- const API_KEY = "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";
137
+ // Fetch for Node.js
138
+ const fetch = (...args) =>
139
+ import('node-fetch').then(({ default: fetch }) => fetch(...args));
140
+
141
+ // 🔐 Put your OpenAI API key here or use process.env.OPENAI_API_KEY
142
+ const API_KEY = process.env.OPENAI_API_KEY || "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";
10
143
 
11
144
  /**
12
145
  * 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
146
  */
16
147
  async function generateProject(prompt, directoryName) {
17
- const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
148
+ const url = "https://api.openai.com/v1/responses";
18
149
 
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
150
  const newPrompt = `
23
151
  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 (e.g., "index.html", "src/styles.css", "js/app.js").
27
- 2. "code": (string) The complete code for that file.
152
+ Return a JSON array of files.
153
+ Each item must contain:
154
+ - filename
155
+ - code
28
156
 
29
- Only return the raw JSON array, with no other text, explanations, or markdown fences.
157
+ Return ONLY valid JSON. No markdown.
30
158
 
31
159
  User Prompt: "${prompt}"
32
160
  `;
33
161
 
34
162
  const body = {
35
- contents: [{ parts: [{ text: newPrompt }] }]
163
+ model: "gpt-4.1-mini",
164
+ input: newPrompt,
165
+ max_output_tokens: 3000
36
166
  };
37
167
 
38
168
  try {
39
- console.log(`Code Running in Expresss`);
169
+ console.log("Generating project...");
40
170
 
41
171
  const response = await fetch(url, {
42
- method: 'POST',
43
- headers: { 'Content-Type': 'application/json' },
44
- body: JSON.stringify(body),
172
+ method: "POST",
173
+ headers: {
174
+ "Authorization": `Bearer ${API_KEY}`,
175
+ "Content-Type": "application/json"
176
+ },
177
+ body: JSON.stringify(body)
45
178
  });
46
179
 
47
180
  if (!response.ok) {
48
- const errorData = await response.json();
49
- console.error('❌ API Error Details:', JSON.stringify(errorData.error, null, 2));
50
- throw new Error(`API request failed with status ${response.status}`);
181
+ throw new Error(await response.text());
51
182
  }
52
183
 
53
184
  const data = await response.json();
54
- let responseText = data.candidates[0].content.parts[0].text;
55
185
 
56
- // --- NEW JSON PARSING & FILE CREATION LOGIC ---
57
- // console.log("Building project...");
186
+ let responseText =
187
+ data.output_text ||
188
+ data.output?.[0]?.content?.[0]?.text ||
189
+ "";
58
190
 
59
- // Clean up potential markdown fences from the AI's response
60
- if (responseText.startsWith("```json")) {
61
- responseText = responseText.substring(7, responseText.length - 3).trim();
62
- }
191
+ responseText = responseText
192
+ .replace(/^```json/, "")
193
+ .replace(/```$/, "")
194
+ .trim();
63
195
 
64
- let files;
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
- }
196
+ let files = JSON.parse(responseText);
73
197
 
74
- // Create the main project directory
75
198
  fs.mkdirSync(directoryName, { recursive: true });
76
- console.log(``);
77
199
 
78
- // Loop through the files array and create each file
79
200
  for (const file of files) {
80
201
  const filePath = path.join(directoryName, file.filename);
81
- 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
202
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
89
203
  fs.writeFileSync(filePath, file.code);
90
- //console.log(`Created file: ${filePath}`);
91
204
  }
92
205
 
93
- // console.log(`\n🎉 Project "${directoryName}" created successfully!`);
206
+ console.log(`🎉 Project "${directoryName}" created successfully!`);
94
207
 
95
- } catch (error) {
96
- console.error('An error occurred:', error.message);
208
+ } catch (err) {
209
+ console.error("Error:", err.message);
97
210
  }
98
211
  }
99
212
 
100
- // --- NEW YARGS SETUP ---
213
+ // CLI
101
214
  yargs(hideBin(process.argv))
102
215
  .command(
103
- '$0 <prompt>', // The default command
104
- 'Generates a full project structure from a text prompt.',
105
- (yargs) => {
106
- return yargs
107
- .positional('prompt', {
108
- describe: 'The project you want to generate',
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
- });
117
- },
216
+ "$0 <prompt>",
217
+ "Generate a project from a prompt",
218
+ (y) =>
219
+ y.option("directory", {
220
+ alias: "d",
221
+ type: "string",
222
+ demandOption: true
223
+ }),
118
224
  (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.');
225
+ if (!API_KEY) {
226
+ console.error("Set OPENAI_API_KEY first");
121
227
  return;
122
228
  }
123
229
  generateProject(argv.prompt, argv.directory);
124
230
  }
125
231
  )
126
- .demandCommand(1, 'Please provide a prompt.')
127
- .parse();
232
+ .parse();
233
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xoxohp",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "index.js",
5
5
  "bin":{
6
6
  "xoxohp":"./index.js"