MCPcopy
hub / github.com/meteor/meteor / setUpSocketForSingleUse

Method setUpSocketForSingleUse

tools/shell-client.ts:86–116  ·  view source on GitHub ↗
(sock: net.Socket, key: string)

Source from the content-addressed store, hash-verified

84 };
85
86 setUpSocketForSingleUse(sock: net.Socket, key: string) {
87 sock.on("connect", function () {
88 const inputBuffers: Buffer[] = [];
89 process.stdin.on("data", buffer => inputBuffers.push(buffer));
90 process.stdin.on("end", () => {
91 sock.write(JSON.stringify({
92 evaluateAndExit: {
93 // Make sure the entire command is written as a string within a
94 // JSON object, so that the server can easily tell when it has
95 // received the whole command.
96 command: Buffer.concat(inputBuffers).toString("utf8")
97 },
98 terminal: false,
99 key: key
100 }) + "\n");
101 });
102 });
103
104 const outputBuffers: Buffer[] = [];
105 sock.on("data", buffer => outputBuffers.push(buffer));
106 sock.on("close", function () {
107 const output = JSON.parse(Buffer.concat(outputBuffers));
108 if (output.error) {
109 console.error(output.error);
110 process.exit(output.code);
111 } else {
112 process.stdout.write(JSON.stringify(output.result) + "\n");
113 process.exit(0);
114 }
115 });
116 };
117
118 setUpSocket(sock: net.Socket, key: string) {
119 if (!process.stdin.isTTY) {

Callers 1

setUpSocketMethod · 0.95

Calls 5

onMethod · 0.80
parseMethod · 0.65
writeMethod · 0.45
toStringMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected