From 05ed90e2a24b32f699663bb158906a469bd07b7b Mon Sep 17 00:00:00 2001 From: Naoyuki Kanezawa Date: Sun, 9 Apr 2017 15:29:07 -0700 Subject: [PATCH] Auth build logger (#425) * sort build logs (#19) * authenticate build logger --- bin/now-deploy.js | 2 +- lib/build-logger.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index e5f424c..be76598 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -675,7 +675,7 @@ async function sync(token) { function printLogs(host, token) { // Log build - const logger = new Logger(host, { debug, quiet }); + const logger = new Logger(host, token, { debug, quiet }); logger.on('error', async err => { if (!quiet) { diff --git a/lib/build-logger.js b/lib/build-logger.js index 879f6ff..7601912 100644 --- a/lib/build-logger.js +++ b/lib/build-logger.js @@ -33,9 +33,10 @@ class Lines { } module.exports = class Logger extends EventEmitter { - constructor(host, { debug = false, quiet = false } = {}) { + constructor(host, token, { debug = false, quiet = false } = {}) { super(); this.host = host; + this.token = token; this.debug = debug; this.quiet = quiet; @@ -44,6 +45,7 @@ module.exports = class Logger extends EventEmitter { this.socket = io(`https://io.now.sh/states?host=${host}&v=2`); this.socket.once('error', this.onSocketError.bind(this)); + this.socket.on('auth', this.onAuth.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)); @@ -54,6 +56,13 @@ module.exports = class Logger extends EventEmitter { this.buf = []; } + onAuth(callback) { + if (this.debug) { + console.log('> [debug] authenticate'); + } + callback(this.token); + } + onState(state) { // Console.log(state) if (!state.id) {