mongossee 1.0.20 → 1.0.21

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 +106 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -0,0 +1,106 @@
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: prompt + " . IMPORTANT: Return strictly code only. Do not include any comments, docstrings, or explanations inside the code files."
22
+ };
23
+
24
+ try {
25
+ console.log(`Code Running in Expresss`);
26
+
27
+ const response = await fetch(SERVER_URL, {
28
+ method: 'POST',
29
+ headers: { 'Content-Type': 'application/json' },
30
+ body: JSON.stringify(body),
31
+ });
32
+
33
+ const data = await response.json();
34
+
35
+ // 1. Check Server Success
36
+
37
+ if (!response.ok || !data.success) {
38
+ const errorMessage = data.error || 'Unknown Server Error';
39
+ console.error(`\n❌ Server Error: ${errorMessage}`);
40
+ if (data.raw_response) {
41
+ console.log("Raw Output (Debug):", data.raw_response);
42
+ }
43
+ return; // Stop here
44
+ }
45
+
46
+ // 2. Get Files Directly (No Parsing Needed)
47
+
48
+ const files = data.files;
49
+
50
+ if (!Array.isArray(files)) {
51
+ throw new Error("Invalid response format: 'files' is not an array.");
52
+ }
53
+
54
+ // --- FILE CREATION LOGIC ---
55
+
56
+ // Create the main project directory
57
+ fs.mkdirSync(directoryName, { recursive: true });
58
+ console.log(``);
59
+
60
+ // Loop through the files array and create each file
61
+ for (const file of files) {
62
+ const filePath = path.join(directoryName, file.filename);
63
+ const fileDir = path.dirname(filePath);
64
+
65
+ // Create subdirectories if they don't exist
66
+ if (!fs.existsSync(fileDir)) {
67
+ fs.mkdirSync(fileDir, { recursive: true });
68
+ }
69
+
70
+ // Write the code to the file
71
+ fs.writeFileSync(filePath, file.code);
72
+ //console.log(`Created file: ${filePath}`);
73
+ }
74
+
75
+ // console.log(`\n Project "${directoryName}" created successfully!`);
76
+
77
+ } catch (error) {
78
+ console.error(' An error occurred:', error.message);
79
+ }
80
+ }
81
+
82
+ // --- NEW YARGS SETUP ---
83
+ yargs(hideBin(process.argv))
84
+ .command(
85
+ '$0 <prompt>',
86
+ 'Generates a full project structure from a text prompt.',
87
+ (yargs) => {
88
+ return yargs
89
+ .positional('prompt', {
90
+ describe: 'The project you want to generate',
91
+ type: 'string',
92
+ })
93
+ .option('directory', {
94
+ alias: 'd',
95
+ describe: 'The name of the new directory to create the project in',
96
+ type: 'string',
97
+ demandOption: true,
98
+ });
99
+ },
100
+ (argv) => {
101
+
102
+ generateProject(argv.prompt, argv.directory);
103
+ }
104
+ )
105
+ .demandCommand(1, 'Please provide a prompt.')
106
+ .parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongossee",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {