refactor.. --verbose and --debug functional

This commit is contained in:
Lloyd Brookes
2016-07-14 20:34:22 +01:00
parent 7a958a68ec
commit ad4efaa6d7
3 changed files with 81 additions and 64 deletions

View File

@ -1,36 +1,5 @@
#!/usr/bin/env node
'use strict'
const path = require('path')
function onServerUp (port, directory, isHttps) {
const ansi = require('ansi-escape-sequences')
const ipList = getIPList()
.map(iface => `[underline]{${isHttps ? 'https' : 'http'}://${iface.address}:${port}}`)
.join(', ')
console.error(ansi.format(
path.resolve(directory || '') === process.cwd()
? `serving at ${ipList}`
: `serving [underline]{${directory}} at ${ipList}`
))
}
function getIPList () {
const flatten = require('reduce-flatten')
const os = require('os')
let ipList = Object.keys(os.networkInterfaces())
.map(key => os.networkInterfaces()[key])
.reduce(flatten, [])
.filter(iface => iface.family === 'IPv4')
ipList.unshift({ address: os.hostname() })
return ipList
}
const LocalWebServer = require('../')
const ws = new LocalWebServer()
const server = ws.getServer()
server.on('listening', function () {
onServerUp(ws.options.port, ws.options['static.root'], server.isHttps)
})