diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index e7fad4f1..47173ab4 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -74,7 +74,6 @@ class Pipeline { logger: self.logger, normalizeInput: self.normalizeInput }); - console.log('Starting process'); webpackProcess.send({action: constants.pipeline.init, options: {}}); webpackProcess.send({action: constants.pipeline.build, file, importsList}); diff --git a/lib/process/processLauncher.js b/lib/process/processLauncher.js index 0e0550ee..c631fc13 100644 --- a/lib/process/processLauncher.js +++ b/lib/process/processLauncher.js @@ -14,60 +14,68 @@ class ProcessLauncher { _subscribeToMessages() { const self = this; this.process.on('message', (msg) => { - console.log('Received message', msg); if (msg.result === constants.process.log) { - if (self.logger[msg.type]) { - return self.logger[msg.type](self.normalizeInput(msg.message)); - } - self.logger.debug(self.normalizeInput(msg.message)); - return; + return self._handleLog(msg); } - - const messageKeys = Object.keys(msg); - const subscriptionsKeys = Object.keys(self.subscriptions); - let subscriptions; - let messageKey; - // Find if the message contains a key that we are subscribed to - messageKeys.some(_messageKey => { - return subscriptionsKeys.some(subscriptionKey => { - if (_messageKey === subscriptionKey) { - subscriptions = self.subscriptions[subscriptionKey]; - messageKey = _messageKey; - return true; - } - return false; - }); - }); - - if (subscriptions) { - console.log('Found the subscriptions'); - let subscription; - // Find if we are subscribed to one of the values - subscriptions.some(sub => { - if (msg[messageKey] === sub.value) { - subscription = sub; - return true; - } - return false; - }); - - if (subscription) { - console.log('Found the sub and calling'); - // We are subscribed to that message, call the callback - subscription.callback(msg); - } + if (msg.event) { + return this._handleEvent(msg); } + this._checkSubscriptions(msg); }); } + _handleLog(msg) { + if (this.logger[msg.type]) { + return this.logger[msg.type](this.normalizeInput(msg.message)); + } + this.logger.debug(this.normalizeInput(msg.message)); + } + + _handleEvent(msg) { + console.log(msg); + } + + _checkSubscriptions(msg) { + const messageKeys = Object.keys(msg); + const subscriptionsKeys = Object.keys(this.subscriptions); + let subscriptions; + let messageKey; + // Find if the message contains a key that we are subscribed to + messageKeys.some(_messageKey => { + return subscriptionsKeys.some(subscriptionKey => { + if (_messageKey === subscriptionKey) { + subscriptions = this.subscriptions[subscriptionKey]; + messageKey = _messageKey; + return true; + } + return false; + }); + }); + + if (subscriptions) { + let subscription; + // Find if we are subscribed to one of the values + subscriptions.some(sub => { + if (msg[messageKey] === sub.value) { + subscription = sub; + return true; + } + return false; + }); + + if (subscription) { + // We are subscribed to that message, call the callback + subscription.callback(msg); + } + } + } + subscribeTo(key, value, callback) { - console.log('Subscribe to ', key, value); if (this.subscriptions[key]) { this.subscriptions[key].push(value); return; } this.subscriptions[key] = [{value, callback}]; - console.log('Subs', this.subscriptions); } unsubscribeTo(key, value) {