2017-10-02 09:33:29 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
import * as url from 'url';
|
2018-05-01 04:50:23 +02:00
|
|
|
|
import * as net from 'net';
|
|
|
|
|
|
let fs = require('fs'),
|
2017-11-28 03:37:31 +01:00
|
|
|
|
os = require('os'),
|
2017-10-02 09:33:29 +02:00
|
|
|
|
stdin = process.stdin,
|
|
|
|
|
|
stdout = process.stdout;
|
|
|
|
|
|
|
2018-05-01 04:50:23 +02:00
|
|
|
|
let socket = new net.Socket();
|
2017-10-02 09:33:29 +02:00
|
|
|
|
socket.on('data', (chunk: any) => {
|
|
|
|
|
|
// send it back to stdout
|
|
|
|
|
|
stdout.write(chunk);
|
|
|
|
|
|
}).on('end', () => {
|
|
|
|
|
|
stdin.pause();
|
|
|
|
|
|
});
|
2018-05-01 04:50:23 +02:00
|
|
|
|
connectSocket(socket);
|
2017-10-02 09:33:29 +02:00
|
|
|
|
|
|
|
|
|
|
stdin.resume();
|
|
|
|
|
|
stdin.on('data', (chunk: any) => {
|
|
|
|
|
|
socket.write(chunk);
|
|
|
|
|
|
}).on('end', () => {
|
|
|
|
|
|
socket.end();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2018-05-01 04:50:23 +02:00
|
|
|
|
function connectSocket(socket: net.Socket): net.Socket {
|
|
|
|
|
|
let u = discoverUrl();
|
|
|
|
|
|
// let socket = net.Socket();
|
|
|
|
|
|
if (u.protocol == 'tcp:') {
|
|
|
|
|
|
socket.connect(+u.port, '127.0.0.1');
|
|
|
|
|
|
} else if (u.protocol == 'local:' && os.platform() == 'win32') {
|
|
|
|
|
|
let pipePath = '\\\\.\\pipe\\' + u.hostname;
|
|
|
|
|
|
socket.connect(pipePath);
|
|
|
|
|
|
} else if (u.protocol == 'local:') {
|
|
|
|
|
|
socket.connect(u.path);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw 'Unknown protocol ' + u.protocol;
|
|
|
|
|
|
}
|
|
|
|
|
|
return socket;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-02 09:33:29 +02:00
|
|
|
|
// the port file is hardcoded to a particular location relative to the build.
|
|
|
|
|
|
function discoverUrl(): url.Url {
|
|
|
|
|
|
let pf = path.join(process.cwd(), 'project', 'target', 'active.json');
|
|
|
|
|
|
let portfile = JSON.parse(fs.readFileSync(pf));
|
|
|
|
|
|
return url.parse(portfile.uri);
|
|
|
|
|
|
}
|