diff --git a/bin/cli.js b/bin/cli.js index b3eed89..c108e2e 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('../').run() +require('../lib/cli-app').run() diff --git a/lib/cli-app.js b/lib/cli-app.js new file mode 100644 index 0000000..941003c --- /dev/null +++ b/lib/cli-app.js @@ -0,0 +1,17 @@ +'use strict' +const LwsCliApp = require('lws/lib/cli-app') + +/** + * @alias module:local-web-server + */ +class WsCliApp extends LwsCliApp { + constructor (options) { + super (options) + /* override default serve command */ + this.commands.add(null, require('./command/serve')) + /* add feature-list command */ + this.commands.add('feature-list', require('./command/feature-list')) + } +} + +module.exports = WsCliApp diff --git a/lib/feature-list.js b/lib/command/feature-list.js similarity index 100% rename from lib/feature-list.js rename to lib/command/feature-list.js diff --git a/lib/command/serve.js b/lib/command/serve.js new file mode 100644 index 0000000..e03f405 --- /dev/null +++ b/lib/command/serve.js @@ -0,0 +1,62 @@ +const ServeCommand = require('lws/lib/command/serve') +const path = require('path') + +/** + * @module local-web-server + */ + +class WsServe extends ServeCommand { + execute (options, argv) { + options = { + 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-' + } + super.execute(options, argv) + } + + usage () { + const sections = super.usage() + sections.shift() + sections.shift() + sections.pop() + sections.unshift( + { + header: 'local-web-server', + content: 'A convenient local web server to support productive, full-stack Javascript development.' + }, + { + header: 'Synopsis', + content: [ + '$ ws ', + '$ ws [underline]{command} ' + ] + } + ) + sections.push({ + content: 'Project home: [underline]{https://github.com/lwsjs/local-web-server}' + }) + return sections + } + + showVersion () { + const pkg = require(path.resolve(__dirname, '..', 'package.json')) + console.log(pkg.version) + } +} + +module.exports = WsServe diff --git a/lib/local-web-server.js b/lib/local-web-server.js index cfe7c88..e69de29 100644 --- a/lib/local-web-server.js +++ b/lib/local-web-server.js @@ -1,77 +0,0 @@ -'use strict' -const Lws = require('lws') -const Serve = require('lws/lib/command/serve') -const path = require('path') - -/** - * @module local-web-server - */ - -class WsServe extends Serve { - execute (options, argv) { - options = { - 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-' - } - super.execute(options, argv) - } - - usage () { - const sections = super.usage() - sections.shift() - sections.shift() - sections.pop() - sections.unshift( - { - header: 'local-web-server', - content: 'A convenient local web server to support productive, full-stack Javascript development.' - }, - { - header: 'Synopsis', - content: [ - '$ ws ', - '$ ws [underline]{command} ' - ] - } - ) - sections.push({ - content: 'Project home: [underline]{https://github.com/lwsjs/local-web-server}' - }) - return sections - } - - showVersion () { - const pkg = require(path.resolve(__dirname, '..', 'package.json')) - console.log(pkg.version) - } -} - -/** - * @alias module:local-web-server - */ -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')) - } -} - -module.exports = LocalWebServer