Browse Source

build-logger: log only errors in quiet mode

master
Guillermo Rauch 9 years ago
parent
commit
7eab45a017
  1. 18
      lib/build-logger.js

18
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');
}

Loading…
Cancel
Save