Lloyd Brookes
6 years ago
9 changed files with 1265 additions and 212 deletions
-
4README.md
-
11bin/cli.js
-
3index.js
-
67lib/cli-app.js
-
11lib/command/middleware-list.js
-
44lib/command/serve.js
-
1280package-lock.json
-
3package.json
-
26test/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')) { |
|
||||
require('../lib/cli-app').run() |
|
||||
|
if (nodeVersionMatches('>=8')) { |
||||
|
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/') |
||||
} |
} |
@ -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 |
@ -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 |
|
1280
package-lock.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue