code-mon-config 1.0.9 → 1.0.10

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 +23 -47
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12,6 +12,7 @@ const app = express();
12
12
 
13
13
  app.use(cors());
14
14
  app.use(express.json());
15
+ app.use(express.static(process.cwd()));
15
16
 
16
17
  const PORT = 3000;
17
18
  const ROOT = process.cwd();
@@ -25,17 +26,14 @@ let processId = 0;
25
26
 
26
27
  function safePath(filename) {
27
28
 
28
- if (!filename) {
29
- throw new Error("Filename required");
30
- }
29
+ if (!filename) throw new Error("Filename required");
31
30
 
32
31
  const resolved = path.join(ROOT, filename);
33
32
 
34
- if (!resolved.startsWith(ROOT)) {
35
- throw new Error("Invalid path");
36
- }
33
+ if (!resolved.startsWith(ROOT)) throw new Error("Invalid path");
37
34
 
38
35
  return resolved;
36
+
39
37
  }
40
38
 
41
39
  /* ---------------- FILE TREE ---------------- */
@@ -65,6 +63,7 @@ function getTree(dir, base = "") {
65
63
  });
66
64
 
67
65
  return results;
66
+
68
67
  }
69
68
 
70
69
  /* ---------------- FILE APIs ---------------- */
@@ -97,9 +96,8 @@ app.get("/load", (req, res) => {
97
96
  const filename = req.query.filename;
98
97
  const filePath = safePath(filename);
99
98
 
100
- if (!fs.existsSync(filePath)) {
99
+ if (!fs.existsSync(filePath))
101
100
  return res.json({ error: "File not found" });
102
- }
103
101
 
104
102
  const content = fs.readFileSync(filePath, "utf8");
105
103
 
@@ -167,9 +165,7 @@ app.delete("/delete", (req, res) => {
167
165
 
168
166
  const filePath = safePath(filename);
169
167
 
170
- if (fs.existsSync(filePath)) {
171
- fs.unlinkSync(filePath);
172
- }
168
+ if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
173
169
 
174
170
  res.json({ success: true });
175
171
 
@@ -181,7 +177,7 @@ app.delete("/delete", (req, res) => {
181
177
 
182
178
  });
183
179
 
184
- /* ---------------- EXECUTE COMMAND (FIXED) ---------------- */
180
+ /* ---------------- EXECUTE COMMAND ---------------- */
185
181
 
186
182
  app.post("/execute", (req, res) => {
187
183
 
@@ -189,9 +185,7 @@ app.post("/execute", (req, res) => {
189
185
 
190
186
  const { command } = req.body;
191
187
 
192
- if (!command) {
193
- return res.json({ error: "Command required" });
194
- }
188
+ if (!command) return res.json({ error: "Command required" });
195
189
 
196
190
  const proc = spawn(command, {
197
191
  cwd: ROOT,
@@ -199,19 +193,13 @@ app.post("/execute", (req, res) => {
199
193
  });
200
194
 
201
195
  const id = processId++;
202
-
203
196
  processes[id] = proc;
204
197
 
205
198
  let output = "";
206
199
  let error = "";
207
200
 
208
- proc.stdout.on("data", data => {
209
- output += data.toString();
210
- });
211
-
212
- proc.stderr.on("data", data => {
213
- error += data.toString();
214
- });
201
+ proc.stdout.on("data", d => output += d.toString());
202
+ proc.stderr.on("data", d => error += d.toString());
215
203
 
216
204
  proc.on("close", code => {
217
205
 
@@ -220,9 +208,9 @@ app.post("/execute", (req, res) => {
220
208
  res.json({
221
209
  success: true,
222
210
  processId: id,
223
- code: code,
224
- output: output,
225
- error: error
211
+ code,
212
+ output,
213
+ error
226
214
  });
227
215
 
228
216
  });
@@ -239,9 +227,7 @@ app.post("/execute", (req, res) => {
239
227
 
240
228
  app.get("/processes", (req, res) => {
241
229
 
242
- const list = Object.keys(processes).map(id => ({
243
- id
244
- }));
230
+ const list = Object.keys(processes).map(id => ({ id }));
245
231
 
246
232
  res.json(list);
247
233
 
@@ -255,12 +241,10 @@ app.post("/stop-process", (req, res) => {
255
241
 
256
242
  const { id } = req.body;
257
243
 
258
- if (!processes[id]) {
244
+ if (!processes[id])
259
245
  return res.json({ error: "Process not found" });
260
- }
261
246
 
262
247
  processes[id].kill();
263
-
264
248
  delete processes[id];
265
249
 
266
250
  res.json({
@@ -297,7 +281,7 @@ if (fs.existsSync(EXTENSIONS_DIR)) {
297
281
 
298
282
  console.log(`šŸ”Œ Loaded extension: ${file}`);
299
283
 
300
- } catch (err) {
284
+ } catch {
301
285
 
302
286
  console.log(`āŒ Failed to load extension: ${file}`);
303
287
 
@@ -314,28 +298,21 @@ if (fs.existsSync(EXTENSIONS_DIR)) {
314
298
  const server = app.listen(PORT, async () => {
315
299
 
316
300
  console.log("\nšŸš€ Code Mon Config Starting...\n");
317
-
318
301
  console.log("šŸ“‚ Connected Folder:", ROOT);
319
302
 
320
- console.log("\nāœ… Your terminal has been connected with Code Mon Code Space\n");
321
-
322
- const url = "http://localhost:3000";
303
+ const url = "http://code-mon.pages.dev/iDE";
323
304
 
324
305
  console.log("🌐 Opening:", url);
325
306
 
326
307
  try {
327
-
328
308
  await open(url);
329
-
330
309
  } catch {
331
-
332
310
  console.log("Open manually:", url);
333
-
334
311
  }
335
312
 
336
313
  });
337
314
 
338
- /* ---------------- WEBSOCKET TERMINAL (FIXED) ---------------- */
315
+ /* ---------------- WEBSOCKET TERMINAL ---------------- */
339
316
 
340
317
  const wss = new WebSocket.Server({ server });
341
318
 
@@ -343,9 +320,9 @@ wss.on("connection", ws => {
343
320
 
344
321
  console.log("🟢 Terminal connected");
345
322
 
346
- let shell = spawn(process.env.SHELL || "bash", [], {
347
- cwd: ROOT,
348
- shell: true
323
+ // PTY-like shell using script
324
+ const shell = spawn("script", ["-q", "/dev/null", "bash"], {
325
+ cwd: ROOT
349
326
  });
350
327
 
351
328
  shell.stdout.on("data", data => {
@@ -357,13 +334,12 @@ wss.on("connection", ws => {
357
334
  });
358
335
 
359
336
  ws.on("message", msg => {
360
- shell.stdin.write(msg.toString());
337
+ shell.stdin.write(msg);
361
338
  });
362
339
 
363
340
  ws.on("close", () => {
364
341
 
365
342
  shell.kill();
366
-
367
343
  console.log("šŸ”“ Terminal disconnected");
368
344
 
369
345
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-mon-config",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Code Mon Code Space CLI with plugin/extension system",
5
5
  "main": "index.js",
6
6
  "bin": {