middleware-list command is now --default-stack

This commit is contained in:
Lloyd Brookes
2019-05-27 11:25:06 +01:00
parent 7ad2f11720
commit 5d5c902cba
9 changed files with 1266 additions and 213 deletions

View File

@ -1,13 +1,62 @@
const LwsCliApp = require('lws/lib/cli-app')
const LwsCli = require('lws/lib/cli-app')
const path = require('path')
class WsCliApp extends LwsCliApp {
constructor (options) {
super(options)
/* override default serve command */
this.commands.add(null, require('./command/serve'))
/* add middleware-list command */
this.commands.add('middleware-list', require('./command/middleware-list'))
class WsCli extends LwsCli {
execute (options, argv) {
const commandLineArgs = require('command-line-args')
const cliOptions = commandLineArgs(this.partialDefinitions(), { camelCase: true, partial: true })
if (cliOptions.defaultStack) {
const list = require('./default-stack')
this.log(list)
} else {
options = {
stack: require('./default-stack').slice(),
moduleDir: path.resolve(__dirname, `../node_modules`),
modulePrefix: 'lws-'
}
return super.execute(options, argv)
}
}
partialDefinitions () {
return super.partialDefinitions().concat([
{
name: 'default-stack',
type: Boolean,
description: 'Print the default middleware stack. Any of these built-in middlewares are available to use in a custom stack.',
section: 'core'
}
])
}
usage () {
const sections = super.usage()
sections.shift()
sections.shift()
sections.pop()
sections.unshift(
{
header: 'local-web-server',
content: 'The modular web server for productive full-stack development.'
},
{
header: 'Synopsis',
content: [
'$ ws <options>',
'$ ws {underline command} <options>'
]
}
)
sections.push({
content: 'Project home: {underline https://github.com/lwsjs/local-web-server}'
})
return sections
}
showVersion () {
const pkg = require(path.resolve(__dirname, '..', 'package.json'))
this.log(pkg.version)
}
}
module.exports = WsCliApp
module.exports = WsCli

View File

@ -1,11 +0,0 @@
class MiddlewareList {
description () {
return 'Print available middleware'
}
execute (options) {
const list = require('../default-stack')
console.log(list)
}
}
module.exports = MiddlewareList

View File

@ -1,44 +0,0 @@
const ServeCommand = require('lws/lib/command/serve')
const path = require('path')
class WsServe extends ServeCommand {
execute (options, argv) {
options = {
stack: require('../default-stack'),
moduleDir: path.resolve(__dirname, `../../node_modules`),
modulePrefix: 'lws-'
}
return super.execute(options, argv)
}
usage () {
const sections = super.usage()
sections.shift()
sections.shift()
sections.pop()
sections.unshift(
{
header: 'local-web-server',
content: 'The modular web server for productive full-stack development.'
},
{
header: 'Synopsis',
content: [
'$ ws <options>',
'$ ws {underline command} <options>'
]
}
)
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