diff --git a/lib/local-web-server.js b/lib/local-web-server.js index d9143e1..bbc60da 100644 --- a/lib/local-web-server.js +++ b/lib/local-web-server.js @@ -4,6 +4,7 @@ const ansi = require('ansi-escape-sequences') const path = require('path') const CommandLineTool = require('command-line-tool') const flatten = require('reduce-flatten') +const arrayify = require('array-back') /** * @module local-web-server @@ -26,7 +27,7 @@ class LocalWebServer { const stored = loadConfig('local-web-server') /* manually scan for any --stack passed, as we may need to display stack options */ - const stackPaths = initOptions.stack || stored.stack || [] + const stackPaths = arrayify(initOptions.stack || stored.stack) || [] const stackIndex = process.argv.indexOf('--stack') if (stackIndex > -1) { for (var i = stackIndex + 1; i < process.argv.length; i++) { @@ -39,8 +40,10 @@ class LocalWebServer { } } - /* load the stack */ + /* if the user did not supply a stack, use the default */ if (!stackPaths.length) stackPaths.push(path.resolve(__dirname, '..', 'node_modules', 'local-web-server-default-stack')) + + /* load the stack */ const stackModules = stackPaths .map(stackPath => loadStack(stackPath)) .map(Middleware => new Middleware()) @@ -216,6 +219,7 @@ function getIPList () { */ function loadStack (modulePath) { let module + if (isModule(modulePath)) return modulePath const tried = [] if (modulePath) { try { @@ -237,7 +241,7 @@ function loadStack (modulePath) { } } if (module) { - if (!(module.prototype.middleware || module.prototype.stack)) { + if (!isModule(module)) { const insp = require('util').inspect(module, { depth: 3, colors: true }) const msg = `Not valid Middleware at: ${insp}` tool.halt(new Error(msg)) @@ -249,4 +253,8 @@ function loadStack (modulePath) { return module } +function isModule (module) { + return module.prototype.middleware || module.prototype.stack +} + module.exports = LocalWebServer diff --git a/package.json b/package.json index a25495e..4669e6b 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "engines": { "node": ">=4.0.0" }, + "files": [ + "bin", "lib", "ssl" + ], "scripts": { "test": "tape test/*/*.js", "docs": "jsdoc2md -t jsdoc2md/api.hbs -p list lib/*.js > doc/api.md; echo",