mirror of https://github.com/embarklabs/embark.git
revert
This commit is contained in:
parent
30c25a7b49
commit
dc2e68f0f2
|
@ -1,126 +1,4 @@
|
|||
const child_process = require('child_process');
|
||||
<<<<<<< HEAD
|
||||
const EventEmitter = require('events');
|
||||
|
||||
class ProcessLauncher extends EventEmitter {
|
||||
constructor(embark, options) {
|
||||
super();
|
||||
|
||||
this.embark = embark;
|
||||
|
||||
this.name = options.name;
|
||||
this.command = options.command;
|
||||
this.args = options.args || [];
|
||||
this.splitLines = !!options.splitLines;
|
||||
}
|
||||
|
||||
start() {
|
||||
if (this.child) {
|
||||
throw new Error('child process already started');
|
||||
}
|
||||
|
||||
const stdioHandler = (chunk, fd) => {
|
||||
const ev = `output:${fd}`; // output:stdout, output:stderr
|
||||
|
||||
if (!this.splitLines) {
|
||||
return this.emit(ev, chunk.toString());
|
||||
}
|
||||
|
||||
const lines = chunk.toString().trim().split("\n");
|
||||
for (const l of lines) {
|
||||
this.emit(ev, l);
|
||||
}
|
||||
};
|
||||
|
||||
const child = child_process.spawn(
|
||||
this.command,
|
||||
this.args,
|
||||
{
|
||||
detached: true,
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
windowsHide: true
|
||||
}
|
||||
);
|
||||
|
||||
child.on('error', (err) => {
|
||||
// Make sure we have listeners for errors. If not, we should throw
|
||||
// an error to make sure the operator handles it next time.
|
||||
const listeners = this.listeners('error');
|
||||
if (listeners.length === 0) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
this.emit('error', err);
|
||||
});
|
||||
|
||||
child.on('exit', (code) => this.emit('exit', code));
|
||||
child.stdout.on('data', chunk => stdioHandler(chunk, 'stdout'));
|
||||
child.stderr.on('data', chunk => stdioHandler(chunk, 'stderr'));
|
||||
|
||||
this.child = child;
|
||||
|
||||
// Ensure we kill child processes when SIGINT is signaled.
|
||||
process.on('SIGINT', () => process.exit(0));
|
||||
process.on('exit', () => child.kill('SIGINT'));
|
||||
}
|
||||
|
||||
send(buf) {
|
||||
if (!this.child) {
|
||||
throw new Error('child process not started or killed');
|
||||
}
|
||||
|
||||
this.child.stdin.write(buf);
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (!this.child) {
|
||||
throw new Error('child process not started or killed');
|
||||
}
|
||||
|
||||
const child = this.child;
|
||||
this.child = null;
|
||||
|
||||
child.kill('SIGINT');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=======
|
||||
>>>>>>> parent of 2beeaa68... process launching code
|
||||
const constants = require('../../constants');
|
||||
const path = require('path');
|
||||
const ProcessLogsApi = require('embark-process-logs-api');
|
||||
|
@ -184,7 +62,7 @@ export class ProcessLauncher {
|
|||
return self.exitCallback(code);
|
||||
}
|
||||
if (code) {
|
||||
self.logger.info(`Child Process ${this.name} exited with code ${code}`);
|
||||
this.logger.info(`Child Process ${this.name} exited with code ${code}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue