Browse Source

version.. paths

master
Lloyd Brookes 8 years ago
parent
commit
d0797a703f
  1. 56
      lib/cli-view.js
  2. 10
      lib/local-web-server.js

56
lib/cli-view.js

@ -1,56 +0,0 @@
'use strict'
class CliView {
constructor (localWebServer) {
this.localWebServer = localWebServer
}
/**
* @example
* { log: 'whatever' }
* { config: { static: { root: 1, hidden: 2 } } }
*/
write (msg) {
const writeToStdout = [ 'log', 'info' ]
Object.keys(msg).forEach(key => {
if (writeToStdout.includes(key)) {
console.log(msg[key])
} else if (key === 'config' && msg.config && this.localWebServer.options.verbose) {
printLine(msg.config)
} else if (key === 'error') {
const ansi = require('ansi-escape-sequences')
console.error(ansi.format(msg.error, 'red'))
}
})
}
}
module.exports = CliView
function printLine (config) {
const output = objectToTable(config)
process.stderr.write(output)
}
/**
* create a nested table for deep object trees
*/
function objectToTable (object) {
const ansi = require('ansi-escape-sequences')
const tableLayout = require('table-layout')
const t = require('typical')
const data = Object.keys(object).map(key => {
if (t.isObject(object[key])) {
return { key: ansi.format(key, 'bold'), value: objectToTable(object[key]) }
} else {
return { key: ansi.format(key, 'bold'), value: object[key] }
}
})
return tableLayout(data, {
padding: { left: '', right: ' ' },
columns: [
// { name: 'key', width: 18 },
// { name: 'value', nowrap: true }
]
})
}

10
lib/local-web-server.js

@ -11,11 +11,17 @@ const Lws = require('lws')
class LocalWebServer extends Lws {
constructor () {
const path = require('path')
const stack = [ 'log', 'cors', 'json', 'rewrite', 'body-parser', 'blacklist', 'conditional-get', 'mime', 'compress', 'mock-response', 'spa', 'static', 'index' ].map(name => {
return path.resolve(__dirname, `../node_modules/local-web-server-${name}`)
const stack = [ 'lws-log', 'local-web-server-cors', 'local-web-server-json', 'local-web-server-rewrite', 'local-web-server-body-parser', 'local-web-server-blacklist', 'local-web-server-conditional-get', 'local-web-server-mime', 'local-web-server-compress', 'local-web-server-mock-response', 'local-web-server-spa', 'local-web-server-static', 'local-web-server-index' ].map(name => {
return path.resolve(__dirname, `../node_modules/${name}`)
})
super({ stack })
}
getVersion () {
const path = require('path')
const pkg = require(path.resolve(__dirname, '..', 'package.json'))
return pkg.version
}
}
module.exports = LocalWebServer
Loading…
Cancel
Save