From 7eab45a017741ef75eaab4ae86d5447d74ea3088 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Tue, 5 Jul 2016 16:16:24 -0700 Subject: [PATCH] build-logger: log only errors in quiet mode --- lib/build-logger.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/build-logger.js b/lib/build-logger.js index a40f976..1baa7e9 100644 --- a/lib/build-logger.js +++ b/lib/build-logger.js @@ -5,15 +5,16 @@ import EventEmitter from 'events'; export default class Logger extends EventEmitter { - constructor (host) { + constructor (host, { debug = false, quiet = false } = {}) { super(); this.host = host; + this.quiet = quiet; // readyState this.building = false; this.socket = io(`https://io.now.sh?host=${host}`); - this.socket.once('error', this.onError.bind(this)); + this.socket.once('error', this.onSocketError.bind(this)); this.socket.on('state', this.onState.bind(this)); this.socket.on('logs', this.onLog.bind(this)); this.socket.on('backend', this.onComplete.bind(this)); @@ -25,6 +26,13 @@ export default class Logger extends EventEmitter { if (!state.id) { console.error('> Deployment not found'); this.emit('error'); + return; + } + + if (state.error) { + console.error('> Deployment error'); + this.emit('error'); + return; } if (state.backend) { @@ -43,6 +51,8 @@ export default class Logger extends EventEmitter { this.building = true; } + if (this.quiet) return; + if ('command' === log.type) { console.log(`${chalk.gray('>')} ▲ ${log.data}`); this.lines.reset(); @@ -72,7 +82,9 @@ export default class Logger extends EventEmitter { this.emit('close'); } - onError () { + onSocketError () { + this.removeAllListeners(); + console.error('> Connection error'); this.emit('error'); }