code-mon-config 1.0.8 → 1.0.9

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 +28 -46
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -181,7 +181,7 @@ app.delete("/delete", (req, res) => {
181
181
 
182
182
  });
183
183
 
184
- /* ---------------- EXECUTE COMMAND ---------------- */
184
+ /* ---------------- EXECUTE COMMAND (FIXED) ---------------- */
185
185
 
186
186
  app.post("/execute", (req, res) => {
187
187
 
@@ -193,9 +193,7 @@ app.post("/execute", (req, res) => {
193
193
  return res.json({ error: "Command required" });
194
194
  }
195
195
 
196
- const parts = command.split(" ");
197
-
198
- const proc = spawn(parts[0], parts.slice(1), {
196
+ const proc = spawn(command, {
199
197
  cwd: ROOT,
200
198
  shell: true
201
199
  });
@@ -204,25 +202,29 @@ app.post("/execute", (req, res) => {
204
202
 
205
203
  processes[id] = proc;
206
204
 
205
+ let output = "";
206
+ let error = "";
207
+
207
208
  proc.stdout.on("data", data => {
208
- console.log(`[${id}]`, data.toString());
209
+ output += data.toString();
209
210
  });
210
211
 
211
212
  proc.stderr.on("data", data => {
212
- console.error(`[${id}]`, data.toString());
213
+ error += data.toString();
213
214
  });
214
215
 
215
216
  proc.on("close", code => {
216
217
 
217
218
  delete processes[id];
218
219
 
219
- console.log(`Process ${id} exited`);
220
-
221
- });
220
+ res.json({
221
+ success: true,
222
+ processId: id,
223
+ code: code,
224
+ output: output,
225
+ error: error
226
+ });
222
227
 
223
- res.json({
224
- success: true,
225
- processId: id
226
228
  });
227
229
 
228
230
  } catch (err) {
@@ -333,7 +335,7 @@ const server = app.listen(PORT, async () => {
333
335
 
334
336
  });
335
337
 
336
- /* ---------------- WEBSOCKET TERMINAL ---------------- */
338
+ /* ---------------- WEBSOCKET TERMINAL (FIXED) ---------------- */
337
339
 
338
340
  const wss = new WebSocket.Server({ server });
339
341
 
@@ -341,46 +343,26 @@ wss.on("connection", ws => {
341
343
 
342
344
  console.log("🟢 Terminal connected");
343
345
 
344
- let proc;
345
-
346
- ws.on("message", msg => {
347
-
348
- const command = msg.toString();
349
-
350
- if (!proc) {
351
-
352
- proc = spawn(command, {
353
- cwd: ROOT,
354
- shell: true
355
- });
356
-
357
- proc.stdout.on("data", data => {
358
- ws.send(data.toString());
359
- });
360
-
361
- proc.stderr.on("data", data => {
362
- ws.send(data.toString());
363
- });
364
-
365
- proc.on("close", code => {
366
-
367
- ws.send(`\nProcess exited with code ${code}\n`);
368
-
369
- proc = null;
370
-
371
- });
372
-
373
- } else {
346
+ let shell = spawn(process.env.SHELL || "bash", [], {
347
+ cwd: ROOT,
348
+ shell: true
349
+ });
374
350
 
375
- proc.stdin.write(command + "\n");
351
+ shell.stdout.on("data", data => {
352
+ ws.send(data.toString());
353
+ });
376
354
 
377
- }
355
+ shell.stderr.on("data", data => {
356
+ ws.send(data.toString());
357
+ });
378
358
 
359
+ ws.on("message", msg => {
360
+ shell.stdin.write(msg.toString());
379
361
  });
380
362
 
381
363
  ws.on("close", () => {
382
364
 
383
- if (proc) proc.kill();
365
+ shell.kill();
384
366
 
385
367
  console.log("🔴 Terminal disconnected");
386
368
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-mon-config",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Code Mon Code Space CLI with plugin/extension system",
5
5
  "main": "index.js",
6
6
  "bin": {