local-cmd-runner 1.0.1 → 1.0.2
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/package.json +1 -1
- package/server.js +8 -8
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -9,36 +9,36 @@ const app = express();
|
|
|
9
9
|
const httpServer = createServer(app);
|
|
10
10
|
const io = new Server(httpServer);
|
|
11
11
|
|
|
12
|
-
const PORT = process.env.PORT ||
|
|
12
|
+
const PORT = process.env.PORT || 3500;
|
|
13
13
|
|
|
14
14
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
15
15
|
|
|
16
16
|
io.on('connection', (socket) => {
|
|
17
17
|
console.log('Client connected');
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
socket.on('run_command', (payload) => {
|
|
20
20
|
// If the old app.js sends a string, handle it. Otherwise handle the new object format.
|
|
21
21
|
const cmd = typeof payload === 'string' ? payload : payload.cmd;
|
|
22
22
|
const runId = typeof payload === 'string' ? cmd : payload.runId;
|
|
23
23
|
console.log(`Running command: ${cmd}`);
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
// execute the command inside the native OS shell
|
|
26
26
|
const child = spawn(cmd, [], { shell: true });
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
socket.emit('cmd_start', { id: cmd, runId: runId });
|
|
29
29
|
|
|
30
30
|
child.stdout.on('data', (data) => {
|
|
31
31
|
socket.emit('cmd_output', { type: 'stdout', data: data.toString(), id: cmd, runId: runId });
|
|
32
32
|
});
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
child.stderr.on('data', (data) => {
|
|
35
35
|
socket.emit('cmd_output', { type: 'stderr', data: data.toString(), id: cmd, runId: runId });
|
|
36
36
|
});
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
child.on('close', (code) => {
|
|
39
39
|
socket.emit('cmd_close', { code, id: cmd, runId: runId });
|
|
40
40
|
});
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
child.on('error', (err) => {
|
|
43
43
|
socket.emit('cmd_error', { error: err.toString(), id: cmd, runId: runId });
|
|
44
44
|
});
|
|
@@ -48,7 +48,7 @@ io.on('connection', (socket) => {
|
|
|
48
48
|
httpServer.listen(PORT, () => {
|
|
49
49
|
const url = `http://localhost:${PORT}`;
|
|
50
50
|
console.log(`Server is running at ${url}`);
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
// Use platform-specific command to open the browser
|
|
53
53
|
const startCmd = os.platform() === 'win32' ? 'start' : (os.platform() === 'darwin' ? 'open' : 'xdg-open');
|
|
54
54
|
spawn(startCmd, [url], { shell: true });
|