xoxohp 1.0.1 → 1.0.3

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 +180 -67
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,127 +1,240 @@
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
+ // ⚠️ PUT YOUR *NEW* OPENAI API KEY HERE
138
+ const API_KEY = "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";
10
139
 
11
140
  /**
12
141
  * 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
142
  */
16
143
  async function generateProject(prompt, directoryName) {
17
- const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
144
+ const url = "https://api.openai.com/v1/responses";
18
145
 
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
146
  const newPrompt = `
23
147
  You are an expert software developer and project scaffolder.
24
148
  Based on the user's prompt, generate a complete file structure as a JSON array.
25
149
  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.
150
+ 1. "filename": (string) The full relative path for the file
151
+ 2. "code": (string) The complete code for that file
28
152
 
29
- Only return the raw JSON array, with no other text, explanations, or markdown fences.
153
+ Only return the raw JSON array. No markdown. No explanations.
30
154
 
31
155
  User Prompt: "${prompt}"
32
156
  `;
33
157
 
34
158
  const body = {
35
- contents: [{ parts: [{ text: newPrompt }] }]
159
+ model: "gpt-4.1-mini",
160
+ input: newPrompt
36
161
  };
37
162
 
38
163
  try {
39
- console.log(`Code Running in Expresss`);
164
+ console.log("Generating project...");
40
165
 
41
166
  const response = await fetch(url, {
42
- method: 'POST',
43
- headers: { 'Content-Type': 'application/json' },
44
- body: JSON.stringify(body),
167
+ method: "POST",
168
+ headers: {
169
+ "Authorization": `Bearer ${API_KEY}`,
170
+ "Content-Type": "application/json"
171
+ },
172
+ body: JSON.stringify(body)
45
173
  });
46
174
 
47
175
  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}`);
176
+ const error = await response.text();
177
+ throw new Error(error);
51
178
  }
52
179
 
53
180
  const data = await response.json();
54
- let responseText = data.candidates[0].content.parts[0].text;
55
181
 
56
- // --- NEW JSON PARSING & FILE CREATION LOGIC ---
57
- // console.log("Building project...");
182
+ // OpenAI response text
183
+ let responseText = data.output_text;
58
184
 
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
- }
185
+ // Remove accidental code fences
186
+ responseText = responseText
187
+ .replace(/^```json/, "")
188
+ .replace(/```$/, "")
189
+ .trim();
63
190
 
64
191
  let files;
65
192
  try {
66
193
  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);
194
+ if (!Array.isArray(files)) throw new Error();
195
+ } catch {
196
+ console.error("❌ Invalid JSON returned by AI:");
197
+ console.error(responseText);
71
198
  return;
72
199
  }
73
200
 
74
- // Create the main project directory
75
201
  fs.mkdirSync(directoryName, { recursive: true });
76
- console.log(``);
77
202
 
78
- // Loop through the files array and create each file
79
203
  for (const file of files) {
80
204
  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
205
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
89
206
  fs.writeFileSync(filePath, file.code);
90
- //console.log(`Created file: ${filePath}`);
91
207
  }
92
208
 
93
- // console.log(`\n🎉 Project "${directoryName}" created successfully!`);
209
+ console.log(`🎉 Project "${directoryName}" created successfully!`);
94
210
 
95
211
  } catch (error) {
96
- console.error('An error occurred:', error.message);
212
+ console.error("Error:", error.message);
97
213
  }
98
214
  }
99
215
 
100
- // --- NEW YARGS SETUP ---
216
+ // --- CLI ---
101
217
  yargs(hideBin(process.argv))
102
218
  .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',
219
+ "$0 <prompt>",
220
+ "Generates a full project structure from a text prompt.",
221
+ (yargs) =>
222
+ yargs
223
+ .positional("prompt", {
224
+ describe: "Project description",
225
+ type: "string"
110
226
  })
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
- },
227
+ .option("directory", {
228
+ alias: "d",
229
+ type: "string",
230
+ demandOption: true
231
+ }),
118
232
  (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.');
233
+ if (!API_KEY) {
234
+ console.error("Missing OpenAI API key");
121
235
  return;
122
236
  }
123
237
  generateProject(argv.prompt, argv.directory);
124
238
  }
125
239
  )
126
- .demandCommand(1, 'Please provide a prompt.')
127
- .parse();
240
+ .parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xoxohp",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "index.js",
5
5
  "bin":{
6
6
  "xoxohp":"./index.js"