Browse Source

refactor bin run

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

14
bin/cli.js

@ -1,14 +1,2 @@
#!/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()

17
lib/local-web-server.js

@ -1,6 +1,7 @@
'use strict'
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
@ -8,8 +9,8 @@ const Serve = require('lws/lib/command/serve/serve')
class WsServe extends Serve {
execute (options, argv) {
const path = require('path')
let stack = [
options = {
stack: [
'lws-log',
'lws-cors',
'lws-json',
@ -23,11 +24,8 @@ class WsServe extends Serve {
'lws-spa',
'lws-static',
'lws-index'
]
const moduleDir = path.resolve(__dirname, `../node_modules`)
options = {
stack,
moduleDir,
],
moduleDir: path.resolve(__dirname, `../node_modules`),
modulePrefix: 'lws-'
}
super.execute(options, argv)
@ -64,12 +62,13 @@ class WsServe extends Serve {
class LocalWebServer extends Lws {
constructor (options) {
super (options)
/* override default serve command */
this.commands.add(null, WsServe)
/* add feature-list command */
this.commands.add('feature-list', require('./feature-list'))
}
getVersion () {
const path = require('path')
const pkg = require(path.resolve(__dirname, '..', 'package.json'))
return pkg.version
}

Loading…
Cancel
Save