log.format, error reporting
This commit is contained in:
@ -77,11 +77,16 @@ class LocalWebServer {
|
||||
const usage = commandLineUsage(cli.usage(middlewareOptionDefinitions))
|
||||
|
||||
let options = {}
|
||||
const allOptionDefinitions = cli.optionDefinitions.concat(middlewareOptionDefinitions)
|
||||
try {
|
||||
options = commandLineArgs(cli.optionDefinitions.concat(middlewareOptionDefinitions))
|
||||
options = commandLineArgs(allOptionDefinitions)
|
||||
} catch (err) {
|
||||
tool.printError(err)
|
||||
tool.printError(allOptionDefinitions.map(def => {
|
||||
return `name: ${def.name}${def.alias ? ', alias: ' + def.alias : ''}`
|
||||
}).join('\n'))
|
||||
console.error(usage)
|
||||
tool.halt(err)
|
||||
tool.halt()
|
||||
}
|
||||
|
||||
/* combine in stored config */
|
||||
@ -125,7 +130,7 @@ class LocalWebServer {
|
||||
const app = new Koa()
|
||||
app.use(this.stack)
|
||||
app.on('error', err => {
|
||||
if (this.options['log-format']) {
|
||||
if (this.options['log.format']) {
|
||||
console.error(ansi.format(err.stack, 'red'))
|
||||
}
|
||||
})
|
||||
@ -189,7 +194,6 @@ function onServerUp (port, directory, isHttps) {
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
function getIPList () {
|
||||
const flatten = require('reduce-flatten')
|
||||
const os = require('os')
|
||||
@ -227,25 +231,36 @@ function collectUserOptions (mwOptionDefinitions) {
|
||||
*/
|
||||
function loadStack (modulePath) {
|
||||
let module
|
||||
const tried = []
|
||||
if (modulePath) {
|
||||
const fs = require('fs')
|
||||
try {
|
||||
tried.push(path.resolve(modulePath))
|
||||
module = require(path.resolve(modulePath))
|
||||
} catch (err) {
|
||||
const walkBack = require('walk-back')
|
||||
const foundPath = walkBack(process.cwd(), path.join('node_modules', 'local-web-server-' + modulePath))
|
||||
tried.push('local-web-server-' + modulePath)
|
||||
if (foundPath) {
|
||||
module = require(foundPath)
|
||||
} else {
|
||||
const foundPath2 = walkBack(process.cwd(), path.join('node_modules', modulePath))
|
||||
tried.push(modulePath)
|
||||
if (foundPath2) {
|
||||
module = require(foundPath2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(module && (module.prototype.middleware || module.prototype.stack))) {
|
||||
tool.halt(new Error('Not valid Middleware: ' + modulePath))
|
||||
if (module) {
|
||||
if (!(module.prototype.middleware || module.prototype.stack)) {
|
||||
const insp = require('util').inspect(module, { depth: 3, colors: true })
|
||||
const msg = `Not valid Middleware at: ${insp}`
|
||||
tool.halt(new Error(msg))
|
||||
}
|
||||
} else {
|
||||
const msg = `No module found at: \n${tried.join('\n')}`
|
||||
tool.halt(new Error(msg))
|
||||
}
|
||||
return module
|
||||
}
|
||||
|
Reference in New Issue
Block a user