mongossee 1.0.31 → 1.0.32
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/index.js +0 -140
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
|
|
9
|
-
const SERVER_URL = "https://mongossee.vercel.app/api/server";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Generates a full project structure based on a prompt.
|
|
15
|
-
* @param {string} prompt - The user's project request.
|
|
16
|
-
* @param {string} directoryName - The name of the folder to create the project in.
|
|
17
|
-
*/
|
|
18
|
-
async function generateProject(prompt, directoryName) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const body = {
|
|
22
|
-
prompt: prompt // Ye wahi prompt hai jo user terminal mein likhega
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
console.log(`Code Running in Expresss`);
|
|
27
|
-
|
|
28
|
-
const response = await fetch(SERVER_URL, {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
headers: { 'Content-Type': 'application/json' },
|
|
31
|
-
body: JSON.stringify(body),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const data = await response.json();
|
|
35
|
-
|
|
36
|
-
// 1. Check Server Success
|
|
37
|
-
|
|
38
|
-
if (!response.ok || !data.success) {
|
|
39
|
-
const errorMessage = data.error || 'Unknown Server Error';
|
|
40
|
-
console.error(`\n Server Error: ${errorMessage}`);
|
|
41
|
-
if (data.raw_response) {
|
|
42
|
-
// console.log("Raw Output (Debug):");
|
|
43
|
-
try {
|
|
44
|
-
// AI ka response agar markdown mein ho toh clean karke parse karein
|
|
45
|
-
const cleanRaw = data.raw_response.replace(/```json|```/g, "").trim();
|
|
46
|
-
const prettyJson = JSON.stringify(JSON.parse(cleanRaw), null, 2);
|
|
47
|
-
console.log(prettyJson);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
//console.log("Raw Response:", data.raw_response);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return; // Stop here
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 2. Get Files Directly (No Parsing Needed)
|
|
56
|
-
|
|
57
|
-
const files = data.files;
|
|
58
|
-
|
|
59
|
-
if (!Array.isArray(files)) {
|
|
60
|
-
throw new Error("Invalid response format: 'files' is not an array.");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// --- FILE CREATION LOGIC ---
|
|
64
|
-
|
|
65
|
-
// Create the main project directory
|
|
66
|
-
fs.mkdirSync(directoryName, { recursive: true });
|
|
67
|
-
console.log(``);
|
|
68
|
-
|
|
69
|
-
// Loop through the files array and create each file
|
|
70
|
-
for (const file of files) {
|
|
71
|
-
const filePath = path.join(directoryName, file.filename);
|
|
72
|
-
const fileDir = path.dirname(filePath);
|
|
73
|
-
|
|
74
|
-
// Create subdirectories if they don't exist
|
|
75
|
-
if (!fs.existsSync(fileDir)) {
|
|
76
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let formattedCode = file.code;
|
|
80
|
-
|
|
81
|
-
if (typeof formattedCode === 'string') {
|
|
82
|
-
formattedCode = formattedCode
|
|
83
|
-
.replace(/\\\\"/g, '"') // 1. Triple escaped quotes (\\") pehle
|
|
84
|
-
.replace(/\\"/g, '"') // 2. Normal escaped quotes (\")
|
|
85
|
-
.replace(/\\r/g, '') // 3. Carriage returns hatao
|
|
86
|
-
.replace(/\\n/g, '\n') // 4. Newlines (Actual line breaks) ko restore karo 🚀
|
|
87
|
-
.replace(/\\t/g, ' ') // 5. Tabs ko 2 spaces banao
|
|
88
|
-
.replace(/\\{2,}/g, '\\') // 6. Multiple backslashes ko handle karo
|
|
89
|
-
.replace(/\\\\/g, '\\'); // 7. Generic backslashes last mein
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 2. ✨ JSON Pretty-Print Fix:
|
|
93
|
-
// Agar file .json hai, toh usey dubara parse karke sundar format mein badlo
|
|
94
|
-
if (file.filename.endsWith('.json')) {
|
|
95
|
-
try {
|
|
96
|
-
const jsonObject = JSON.parse(formattedCode);
|
|
97
|
-
formattedCode = JSON.stringify(jsonObject, null, 2);
|
|
98
|
-
} catch (e) {
|
|
99
|
-
// Agar parse fail ho jaye toh purana formatted code hi rehne do
|
|
100
|
-
//console.log(` ${file.filename}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Write the code to the file
|
|
105
|
-
fs.writeFileSync(filePath, formattedCode);
|
|
106
|
-
//console.log(`Created file: ${filePath}`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// console.log(`\n Project "${directoryName}" created successfully!`);
|
|
110
|
-
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error(' An error occurred:', error.message);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// --- NEW YARGS SETUP ---
|
|
117
|
-
yargs(hideBin(process.argv))
|
|
118
|
-
.command(
|
|
119
|
-
'$0 <prompt>',
|
|
120
|
-
'Generates a full project structure from a text prompt.',
|
|
121
|
-
(yargs) => {
|
|
122
|
-
return yargs
|
|
123
|
-
.positional('prompt', {
|
|
124
|
-
describe: 'The project you want to generate',
|
|
125
|
-
type: 'string',
|
|
126
|
-
})
|
|
127
|
-
.option('directory', {
|
|
128
|
-
alias: 'd',
|
|
129
|
-
describe: 'The name of the new directory to create the project in',
|
|
130
|
-
type: 'string',
|
|
131
|
-
demandOption: true,
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
(argv) => {
|
|
135
|
-
|
|
136
|
-
generateProject(argv.prompt, argv.directory);
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
.demandCommand(1, 'Please provide a prompt.')
|
|
140
|
-
.parse();
|