(uri: vscode.Uri, command: string, socket: WebSocket, terminalId: number, wss: WebSocketServer)
| 5 | import * as vscode from 'vscode'; |
| 6 | /** Make this work properly with the remix dev tools so it executes, closes and runs processes */ |
| 7 | const executeCommand = async (uri: vscode.Uri, command: string, socket: WebSocket, terminalId: number, wss: WebSocketServer) => { |
| 8 | const workspacePath = await getRemixRootFromFileUri(uri); |
| 9 | const process = exec(command, { cwd: workspacePath?.fsPath, env: { FORCE_COLOR: "true" } }); |
| 10 | |
| 11 | process.on("spawn", () => { |
| 12 | socket.send( |
| 13 | JSON.stringify({ |
| 14 | type: "terminal_command", |
| 15 | terminalId, |
| 16 | processId: process.pid, |
| 17 | }), |
| 18 | ); |
| 19 | }); |
| 20 | process.on("error", (error) => { |
| 21 | socket.send(JSON.stringify({ type: "terminal_command", subtype: "ERROR", terminalId, data: error.message })); |
| 22 | }); |
| 23 | process?.stdout?.on("data", (data) => { |
| 24 | socket.send( |
| 25 | JSON.stringify({ |
| 26 | type: "terminal_command", |
| 27 | subtype: "DATA", |
| 28 | terminalId, |
| 29 | data: data.toString(), |
| 30 | }), |
| 31 | ); |
| 32 | }); |
| 33 | |
| 34 | process?.stderr?.on("data", (data) => { |
| 35 | socket.send(JSON.stringify({ type: "terminal_command", subtype: "ERROR", terminalId, data: data.toString() })); |
| 36 | }); |
| 37 | process?.stdout?.on("error", (error) => { |
| 38 | socket.send(JSON.stringify({ type: "terminal_command", subtype: "ERROR", terminalId, data: error.message })); |
| 39 | }); |
| 40 | process.on("close", (code) => { |
| 41 | socket.send(JSON.stringify({ type: "terminal_command", subtype: "CLOSE", terminalId, data: code?.toString() })); |
| 42 | }); |
| 43 | process.on("exit", (code) => { |
| 44 | socket.send(JSON.stringify({ type: "terminal_command", subtype: "EXIT", terminalId, data: code?.toString() })); |
| 45 | }); |
| 46 | |
| 47 | wss.on("close", async () => { |
| 48 | try { |
| 49 | if (process.pid) { |
| 50 | await killtree(process.pid); |
| 51 | } |
| 52 | } catch (err) { |
| 53 | /* console.log(err); */ |
| 54 | } |
| 55 | }); |
| 56 | }; |
| 57 | export const runTerminalCommands = async ( |
| 58 | uri: vscode.Uri, |
| 59 | socket: WebSocket, |
no test coverage detected