refactor bin run
This commit is contained in:
14
bin/cli.js
14
bin/cli.js
@ -1,14 +1,2 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
'use strict'
|
require('../').run()
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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,
|
stack: [
|
||||||
moduleDir,
|
'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
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user