Browse Source

refactor bin run

master
Lloyd Brookes 8 years ago
parent
commit
b7289201e1
  1. 14
      bin/cli.js
  2. 41
      lib/local-web-server.js

14
bin/cli.js

@ -1,14 +1,2 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict'
const LocalWebServer = require('../')
const localWebServer = new LocalWebServer()
try {
localWebServer.start()
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
console.error(err.message)
console.error(require('util').inspect(err.attempted, { depth: 6, colors: true }))
} else {
console.error(err.stack)
}
}
require('../').run()

41
lib/local-web-server.js

@ -1,6 +1,7 @@
'use strict' 'use strict'
const Lws = require('lws') const Lws = require('lws')
const Serve = require('lws/lib/command/serve/serve')
const Serve = require('lws/lib/command/serve')
const path = require('path')
/** /**
* @module local-web-server * @module local-web-server
@ -8,26 +9,23 @@ const Serve = require('lws/lib/command/serve/serve')
class WsServe extends Serve { class WsServe extends Serve {
execute (options, argv) { execute (options, argv) {
const path = require('path')
let stack = [
'lws-log',
'lws-cors',
'lws-json',
'lws-rewrite',
'lws-body-parser',
'lws-blacklist',
'lws-conditional-get',
'lws-mime',
'lws-compress',
'lws-mock-response',
'lws-spa',
'lws-static',
'lws-index'
]
const moduleDir = path.resolve(__dirname, `../node_modules`)
options = { options = {
stack,
moduleDir,
stack: [
'lws-log',
'lws-cors',
'lws-json',
'lws-rewrite',
'lws-body-parser',
'lws-blacklist',
'lws-conditional-get',
'lws-mime',
'lws-compress',
'lws-mock-response',
'lws-spa',
'lws-static',
'lws-index'
],
moduleDir: path.resolve(__dirname, `../node_modules`),
modulePrefix: 'lws-' modulePrefix: 'lws-'
} }
super.execute(options, argv) super.execute(options, argv)
@ -64,12 +62,13 @@ class WsServe extends Serve {
class LocalWebServer extends Lws { class LocalWebServer extends Lws {
constructor (options) { constructor (options) {
super (options) super (options)
/* override default serve command */
this.commands.add(null, WsServe) this.commands.add(null, WsServe)
/* add feature-list command */
this.commands.add('feature-list', require('./feature-list')) this.commands.add('feature-list', require('./feature-list'))
} }
getVersion () { getVersion () {
const path = require('path')
const pkg = require(path.resolve(__dirname, '..', 'package.json')) const pkg = require(path.resolve(__dirname, '..', 'package.json'))
return pkg.version return pkg.version
} }

Loading…
Cancel
Save