|
@ -1,7 +1,6 @@ |
|
|
#!/usr/bin/env node
|
|
|
#!/usr/bin/env node
|
|
|
'use strict' |
|
|
'use strict' |
|
|
const localWebServer = require('../') |
|
|
const localWebServer = require('../') |
|
|
const streamLogStats = require('stream-log-stats') |
|
|
|
|
|
const commandLineArgs = require('command-line-args') |
|
|
const commandLineArgs = require('command-line-args') |
|
|
const ansi = require('ansi-escape-sequences') |
|
|
const ansi = require('ansi-escape-sequences') |
|
|
const cliOptions = require('../lib/cli-options') |
|
|
const cliOptions = require('../lib/cli-options') |
|
@ -34,23 +33,11 @@ options.cli.server = Object.assign(options.builtIn, options.stored, options.cli. |
|
|
if (options.cli.misc.help) return console.log(usage) |
|
|
if (options.cli.misc.help) return console.log(usage) |
|
|
if (options.cli.misc.config) return console.log(JSON.stringify(options.stored, null, ' ')) |
|
|
if (options.cli.misc.config) return console.log(JSON.stringify(options.stored, null, ' ')) |
|
|
|
|
|
|
|
|
let log = { |
|
|
|
|
|
format: options.cli.server['log-format'] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (log.format === 'none'){ |
|
|
|
|
|
log.format = undefined |
|
|
|
|
|
} else if (log.format){ |
|
|
|
|
|
log.stream = process.stdout |
|
|
|
|
|
} else { |
|
|
|
|
|
log.format = 'common' |
|
|
|
|
|
log.stream = streamLogStats({ refreshRate: 100 }) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
localWebServer({ |
|
|
localWebServer({ |
|
|
static: { root: options.cli.server.directory }, |
|
|
static: { root: options.cli.server.directory }, |
|
|
serveIndex: { path: options.cli.server.directory, options: { icons: true } }, |
|
|
serveIndex: { path: options.cli.server.directory, options: { icons: true } }, |
|
|
logger: { format: log.format, options: { stream: log.stream } } |
|
|
|
|
|
|
|
|
logger: { format: options.cli.server['log-format'] }, |
|
|
|
|
|
compress: options.cli.server.compress |
|
|
}).listen(options.cli.server.port, serverUp) |
|
|
}).listen(options.cli.server.port, serverUp) |
|
|
|
|
|
|
|
|
function halt (message) { |
|
|
function halt (message) { |
|
@ -64,6 +51,6 @@ function serverUp () { |
|
|
if (path.resolve(options.cli.server.directory) === process.cwd()) { |
|
|
if (path.resolve(options.cli.server.directory) === process.cwd()) { |
|
|
console.error(ansi.format(`serving at [underline]{http://localhost:${options.cli.server.port}}`)) |
|
|
console.error(ansi.format(`serving at [underline]{http://localhost:${options.cli.server.port}}`)) |
|
|
} else { |
|
|
} else { |
|
|
console.error(ansi.format(`serving [underline]{options.cli.server.directory} at [underline]{http://localhost:${options.cli.server.port}}`)) |
|
|
|
|
|
|
|
|
console.error(ansi.format(`serving [underline]{${options.cli.server.directory}} at [underline]{http://localhost:${options.cli.server.port}}`)) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |