mongossee 1.0.30 โ 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 -167
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,167 +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
|
-
* Generates a full project structure based on a prompt.
|
|
14
|
-
* @param {string} prompt - The user's project request.
|
|
15
|
-
* @param {string} directoryName - The name of the folder to create the project in.
|
|
16
|
-
*/
|
|
17
|
-
async function generateProject(prompt, directoryName) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const body = {
|
|
21
|
-
prompt: `
|
|
22
|
-
TASK: Generate a coding project based on this user request: "${prompt}"
|
|
23
|
-
|
|
24
|
-
STRICT TECHNICAL CONSTRAINTS (Follow for every project):
|
|
25
|
-
1. AUTO-DETECT LANGUAGE & TECH:
|
|
26
|
-
- If the request mentions "Typescript" or ".ts/.tsx", use TypeScript strictly.
|
|
27
|
-
- If it mentions React/Components, use React (JSX/TSX).
|
|
28
|
-
- For DSA/Logic, choose Java, Python, or C++ based on context.
|
|
29
|
-
2. TYPESCRIPT RULES: If using TypeScript, define proper Interfaces/Types for Props and State.
|
|
30
|
-
3. ๐ฏ CONTEXTUAL ONLY: Scrutinize the prompt. If it's a simple app, do NOT add router or state management. Only add 'react-router-dom', 'axios', etc., if the specific feature is requested.
|
|
31
|
-
4. ๐ซ NO BLOAT: In package.json, include ONLY the absolute minimum dependencies to run the app (e.g., react, react-dom, react-scripts).
|
|
32
|
-
5. โ REMOVE FALTU LIBRARIES: Strictly do NOT include @testing-library/*, web-vitals, eslintConfig, or reportWebVitals.
|
|
33
|
-
6. REACT RULES: If using React, always use functional components with hooks (useState, useEffect).
|
|
34
|
-
|
|
35
|
-
7. ๐ง SMART LOGIC: If the prompt says "Logic", "Algorithm", or "DSA", generate only the core logic without UI or framework code
|
|
36
|
-
8. ๐งฑ COMPONENT STRUCTURE: If the prompt mentions "component", "ui", or "frontend", build a complete component with proper imports, exports, and structure.
|
|
37
|
-
|
|
38
|
-
9. โ ZERO COMMENTS: Return strictly functional code. No // or /* */ comments, and no explanations.
|
|
39
|
-
|
|
40
|
-
10. ๐ ARCHITECTURE: If the prompt mentions Parent/Child or Props, strictly follow React best practices (state in parent, props to child, arrow functions for events).
|
|
41
|
-
|
|
42
|
-
11. ๐ FORMAT: Return ONLY a valid JSON array of objects: [{"filename": "string", "code": "string"}].
|
|
43
|
-
|
|
44
|
-
12. ๐ซ NO MARKDOWN: Do not wrap the response in \`\`\`json blocks.
|
|
45
|
-
13. ๐งน CLEAN CODE: Ensure the 'code' string has proper indentation (spaces/tabs) and newlines so it is human-readable after being written to a file. Single-line code is not acceptable.
|
|
46
|
-
14. IMPORTANT: I need 'Pretty-Printed' code. Use multi-line formatting. Single-line code is strictly forbidden.
|
|
47
|
-
15. ๐ ๏ธ BOILERPLATE: Include all necessary boilerplate files (e.g. package.json for Node.js, pom.xml for Java, etc.) based on the detected language and framework.
|
|
48
|
-
16. ๐งโ๐ป FULL SOURCE CODE: The 'code' field must contain the complete source code for the file, including all necessary imports, exports, and boilerplate. Do not return partial code snippets.
|
|
49
|
-
`
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
console.log(`Code Running in Expresss`);
|
|
54
|
-
|
|
55
|
-
const response = await fetch(SERVER_URL, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: { 'Content-Type': 'application/json' },
|
|
58
|
-
body: JSON.stringify(body),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const data = await response.json();
|
|
62
|
-
|
|
63
|
-
// 1. Check Server Success
|
|
64
|
-
|
|
65
|
-
if (!response.ok || !data.success) {
|
|
66
|
-
const errorMessage = data.error || 'Unknown Server Error';
|
|
67
|
-
console.error(`\nโ Server Error: ${errorMessage}`);
|
|
68
|
-
if (data.raw_response) {
|
|
69
|
-
console.log("Raw Output (Debug):");
|
|
70
|
-
try {
|
|
71
|
-
// AI ka response agar markdown mein ho toh clean karke parse karein
|
|
72
|
-
const cleanRaw = data.raw_response.replace(/```json|```/g, "").trim();
|
|
73
|
-
const prettyJson = JSON.stringify(JSON.parse(cleanRaw), null, 2);
|
|
74
|
-
console.log(prettyJson);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
console.log("Raw Response:", data.raw_response);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return; // Stop here
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 2. Get Files Directly (No Parsing Needed)
|
|
83
|
-
|
|
84
|
-
const files = data.files;
|
|
85
|
-
|
|
86
|
-
if (!Array.isArray(files)) {
|
|
87
|
-
throw new Error("Invalid response format: 'files' is not an array.");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// --- FILE CREATION LOGIC ---
|
|
91
|
-
|
|
92
|
-
// Create the main project directory
|
|
93
|
-
fs.mkdirSync(directoryName, { recursive: true });
|
|
94
|
-
console.log(``);
|
|
95
|
-
|
|
96
|
-
// Loop through the files array and create each file
|
|
97
|
-
for (const file of files) {
|
|
98
|
-
const filePath = path.join(directoryName, file.filename);
|
|
99
|
-
const fileDir = path.dirname(filePath);
|
|
100
|
-
|
|
101
|
-
// Create subdirectories if they don't exist
|
|
102
|
-
if (!fs.existsSync(fileDir)) {
|
|
103
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
let formattedCode = file.code;
|
|
107
|
-
|
|
108
|
-
if (typeof formattedCode === 'string') {
|
|
109
|
-
formattedCode = formattedCode
|
|
110
|
-
.replace(/\\\\"/g, '"') // 1. Triple escaped quotes (\\") pehle
|
|
111
|
-
.replace(/\\"/g, '"') // 2. Normal escaped quotes (\")
|
|
112
|
-
.replace(/\\r/g, '') // 3. Carriage returns hatao
|
|
113
|
-
.replace(/\\n/g, '\n') // 4. Newlines (Actual line breaks) ko restore karo ๐
|
|
114
|
-
.replace(/\\t/g, ' ') // 5. Tabs ko 2 spaces banao
|
|
115
|
-
.replace(/\\{2,}/g, '\\') // 6. Multiple backslashes ko handle karo
|
|
116
|
-
.replace(/\\\\/g, '\\'); // 7. Generic backslashes last mein
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// 2. โจ JSON Pretty-Print Fix:
|
|
120
|
-
// Agar file .json hai, toh usey dubara parse karke sundar format mein badlo
|
|
121
|
-
if (file.filename.endsWith('.json')) {
|
|
122
|
-
try {
|
|
123
|
-
const jsonObject = JSON.parse(formattedCode);
|
|
124
|
-
formattedCode = JSON.stringify(jsonObject, null, 2);
|
|
125
|
-
} catch (e) {
|
|
126
|
-
// Agar parse fail ho jaye toh purana formatted code hi rehne do
|
|
127
|
-
//console.log(` ${file.filename}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Write the code to the file
|
|
132
|
-
fs.writeFileSync(filePath, formattedCode);
|
|
133
|
-
//console.log(`Created file: ${filePath}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// console.log(`\n Project "${directoryName}" created successfully!`);
|
|
137
|
-
|
|
138
|
-
} catch (error) {
|
|
139
|
-
console.error(' An error occurred:', error.message);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// --- NEW YARGS SETUP ---
|
|
144
|
-
yargs(hideBin(process.argv))
|
|
145
|
-
.command(
|
|
146
|
-
'$0 <prompt>',
|
|
147
|
-
'Generates a full project structure from a text prompt.',
|
|
148
|
-
(yargs) => {
|
|
149
|
-
return yargs
|
|
150
|
-
.positional('prompt', {
|
|
151
|
-
describe: 'The project you want to generate',
|
|
152
|
-
type: 'string',
|
|
153
|
-
})
|
|
154
|
-
.option('directory', {
|
|
155
|
-
alias: 'd',
|
|
156
|
-
describe: 'The name of the new directory to create the project in',
|
|
157
|
-
type: 'string',
|
|
158
|
-
demandOption: true,
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
(argv) => {
|
|
162
|
-
|
|
163
|
-
generateProject(argv.prompt, argv.directory);
|
|
164
|
-
}
|
|
165
|
-
)
|
|
166
|
-
.demandCommand(1, 'Please provide a prompt.')
|
|
167
|
-
.parse();
|