middleware-list command is now --default-stack
This commit is contained in:
@ -160,7 +160,7 @@ See [the tutorials](https://github.com/lwsjs/local-web-server/wiki#tutorials) fo
|
|||||||
```sh
|
```sh
|
||||||
$ npm install -g local-web-server
|
$ npm install -g local-web-server
|
||||||
```
|
```
|
||||||
|
|
||||||
* * *
|
* * *
|
||||||
|
|
||||||
© 2013-19
|
© 2013-19 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
|
||||||
Lloyd Brookes <75pound@gmail.com>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
|
|
||||||
|
11
bin/cli.js
11
bin/cli.js
@ -1,8 +1,15 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const nodeVersionMatches = require('node-version-matches')
|
const nodeVersionMatches = require('node-version-matches')
|
||||||
|
|
||||||
if (nodeVersionMatches('>=8.0.0')) {
|
if (nodeVersionMatches('>=8')) {
|
||||||
require('../lib/cli-app').run()
|
const WsCli = require('../lib/cli-app')
|
||||||
|
const cli = new WsCli()
|
||||||
|
try {
|
||||||
|
cli.start()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(require('util').inspect(err, { depth: 6, colors: true }))
|
||||||
|
process.exitCode = 1
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('Sorry, this app requires node v8.0.0 or above. Please upgrade https://nodejs.org/en/')
|
console.log('Sorry, this app requires node v8.0.0 or above. Please upgrade https://nodejs.org/en/')
|
||||||
}
|
}
|
||||||
|
3
index.js
3
index.js
@ -15,6 +15,9 @@ const path = require('path')
|
|||||||
* websocket: 'src/websocket-server.js'
|
* websocket: 'src/websocket-server.js'
|
||||||
* })
|
* })
|
||||||
* // secure, SPA server with listening websocket now ready on port 8050
|
* // secure, SPA server with listening websocket now ready on port 8050
|
||||||
|
*
|
||||||
|
* // shut down the server
|
||||||
|
* server.close()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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 {
|
class WsCli extends LwsCli {
|
||||||
constructor (options) {
|
execute (options, argv) {
|
||||||
super(options)
|
const commandLineArgs = require('command-line-args')
|
||||||
/* override default serve command */
|
const cliOptions = commandLineArgs(this.partialDefinitions(), { camelCase: true, partial: true })
|
||||||
this.commands.add(null, require('./command/serve'))
|
if (cliOptions.defaultStack) {
|
||||||
/* add middleware-list command */
|
const list = require('./default-stack')
|
||||||
this.commands.add('middleware-list', require('./command/middleware-list'))
|
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
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
class MiddlewareList {
|
|
||||||
description () {
|
|
||||||
return 'Print available middleware'
|
|
||||||
}
|
|
||||||
execute (options) {
|
|
||||||
const list = require('../default-stack')
|
|
||||||
console.log(list)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = MiddlewareList
|
|
@ -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
|
|
1310
package-lock.json
generated
1310
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -36,7 +36,7 @@
|
|||||||
"index.js"
|
"index.js"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lws": "^1.3.2",
|
"lws": "^2.0.0-3",
|
||||||
"lws-basic-auth": "^0.1.1",
|
"lws-basic-auth": "^0.1.1",
|
||||||
"lws-blacklist": "^1.0.0",
|
"lws-blacklist": "^1.0.0",
|
||||||
"lws-body-parser": "^0.2.4",
|
"lws-body-parser": "^0.2.4",
|
||||||
@ -58,6 +58,7 @@
|
|||||||
"coveralls": "^3.0.3",
|
"coveralls": "^3.0.3",
|
||||||
"jsdoc-to-markdown": "^5.0.0",
|
"jsdoc-to-markdown": "^5.0.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
|
"nyc": "^14.1.1",
|
||||||
"test-runner": "^0.6.0"
|
"test-runner": "^0.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
test/cli.js
26
test/cli.js
@ -1,6 +1,6 @@
|
|||||||
const Tom = require('test-runner').Tom
|
const Tom = require('test-runner').Tom
|
||||||
const a = require('assert')
|
const a = require('assert')
|
||||||
const CliApp = require('../lib/cli-app')
|
const WsCli = require('../lib/cli-app')
|
||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
|
|
||||||
const tom = module.exports = new Tom('cli')
|
const tom = module.exports = new Tom('cli')
|
||||||
@ -9,7 +9,8 @@ tom.test('cli.run', async function () {
|
|||||||
const port = 7500 + this.index
|
const port = 7500 + this.index
|
||||||
const origArgv = process.argv.slice()
|
const origArgv = process.argv.slice()
|
||||||
process.argv = [ 'node', 'something', '--port', `${port}` ]
|
process.argv = [ 'node', 'something', '--port', `${port}` ]
|
||||||
const server = CliApp.run()
|
const cli = new WsCli({ logError: function () {} })
|
||||||
|
const server = cli.start()
|
||||||
process.argv = origArgv
|
process.argv = origArgv
|
||||||
const response = await fetch(`http://127.0.0.1:${port}/`)
|
const response = await fetch(`http://127.0.0.1:${port}/`)
|
||||||
server.close()
|
server.close()
|
||||||
@ -20,7 +21,8 @@ tom.test('cli.run: bad option', async function () {
|
|||||||
const origArgv = process.argv.slice()
|
const origArgv = process.argv.slice()
|
||||||
process.argv = [ 'node', 'something', '--should-fail' ]
|
process.argv = [ 'node', 'something', '--should-fail' ]
|
||||||
const exitCode = process.exitCode
|
const exitCode = process.exitCode
|
||||||
const server = CliApp.run()
|
const cli = new WsCli({ logError: function () {} })
|
||||||
|
const server = cli.start()
|
||||||
if (!exitCode) process.exitCode = 0
|
if (!exitCode) process.exitCode = 0
|
||||||
process.argv = origArgv
|
process.argv = origArgv
|
||||||
a.strictEqual(server, undefined)
|
a.strictEqual(server, undefined)
|
||||||
@ -29,20 +31,28 @@ tom.test('cli.run: bad option', async function () {
|
|||||||
tom.test('cli.run: --help', async function () {
|
tom.test('cli.run: --help', async function () {
|
||||||
const origArgv = process.argv.slice()
|
const origArgv = process.argv.slice()
|
||||||
process.argv = [ 'node', 'something', '--help' ]
|
process.argv = [ 'node', 'something', '--help' ]
|
||||||
CliApp.run()
|
const cli = new WsCli({ log: function () {} })
|
||||||
|
cli.start()
|
||||||
process.argv = origArgv
|
process.argv = origArgv
|
||||||
})
|
})
|
||||||
|
|
||||||
tom.test('cli.run: --version', async function () {
|
tom.test('cli.run: --version', async function () {
|
||||||
const origArgv = process.argv.slice()
|
const origArgv = process.argv.slice()
|
||||||
process.argv = [ 'node', 'something', '--version' ]
|
process.argv = [ 'node', 'something', '--version' ]
|
||||||
CliApp.run()
|
let logMsg = ''
|
||||||
|
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
|
||||||
|
cli.start()
|
||||||
|
const pkg = require('../package.json')
|
||||||
|
a.strictEqual(logMsg.trim(), pkg.version)
|
||||||
process.argv = origArgv
|
process.argv = origArgv
|
||||||
})
|
})
|
||||||
|
|
||||||
tom.test('cli.run: middleware-list', async function () {
|
tom.test('cli.run: default-stack', async function () {
|
||||||
const origArgv = process.argv.slice()
|
const origArgv = process.argv.slice()
|
||||||
process.argv = [ 'node', 'something', 'middleware-list' ]
|
process.argv = [ 'node', 'something', '--default-stack' ]
|
||||||
CliApp.run()
|
let logMsg = ''
|
||||||
|
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
|
||||||
|
cli.start()
|
||||||
|
a.ok(/lws-rewrite/.test(logMsg))
|
||||||
process.argv = origArgv
|
process.argv = origArgv
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user