'use strict'
!(function(require, directRequire) {
  const a = require('events'),
    b = new a()
  b.update = a => {
    ;(global.remoteCLIPort = a), b.emit('update', a)
  }
  module.exports = {
    registerHandlers: a => {
      a.get('/updatePort', (a, c) => {
        const d = a.mQuery.port
        d
          ? (b.update(d), (c.statusCode = 200), c.end())
          : ((c.statusCode = 400), c.end()),
          console.log('updatePort ' + d)
      })
    },
    getRemoteCLIPort: () =>
      new Promise(a => {
        global.remoteCLIPort ? a(global.remoteCLIPort) : b.once('update', a)
      }),
    updateRemoteCLIPort: a => {
      b.update(a)
    }
  }
})(require('lazyload'), require)
