mirror of https://github.com/embarklabs/embark.git
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const constants = require('../constants');
|
|
const Events = require('./eventsWrapper');
|
|
|
|
// Override process.chdir so that we have a partial-implementation PWD for Windows
|
|
const realChdir = process.chdir;
|
|
process.chdir = (...args) => {
|
|
if (!process.env.PWD) {
|
|
process.env.PWD = process.cwd();
|
|
}
|
|
realChdir(...args);
|
|
};
|
|
|
|
class ProcessWrapper {
|
|
constructor(_options) {
|
|
this.interceptLogs();
|
|
this.events = new Events();
|
|
}
|
|
|
|
interceptLogs() {
|
|
const context = {};
|
|
context.console = console;
|
|
|
|
context.console.log = this.log.bind(this, 'log');
|
|
context.console.warn = this.log.bind(this, 'warn');
|
|
context.console.info = this.log.bind(this, 'info');
|
|
context.console.debug = this.log.bind(this, 'debug');
|
|
context.console.trace = this.log.bind(this, 'trace');
|
|
context.console.dir = this.log.bind(this, 'dir');
|
|
}
|
|
|
|
log(type, ...messages) {
|
|
if (messages[0].indexOf('hard-source')) {
|
|
return;
|
|
}
|
|
process.send({result: constants.process.log, message: messages, type});
|
|
}
|
|
}
|
|
|
|
process.on('exit', () => {
|
|
process.exit(0);
|
|
});
|
|
|
|
module.exports = ProcessWrapper;
|