You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

8 years ago
8 years ago
  1. const LwsCli = require('lws/lib/cli-app')
  2. const path = require('path')
  3. class WsCli extends LwsCli {
  4. execute (options, argv) {
  5. const commandLineArgs = require('command-line-args')
  6. const cliOptions = commandLineArgs(this.partialDefinitions(), { camelCase: true, partial: true })
  7. if (cliOptions.defaultStack) {
  8. const list = require('./default-stack')
  9. this.log(list)
  10. } else {
  11. options = {
  12. stack: require('./default-stack').slice(),
  13. moduleDir: path.resolve(__dirname, `../node_modules`),
  14. modulePrefix: 'lws-'
  15. }
  16. return super.execute(options, argv)
  17. }
  18. }
  19. partialDefinitions () {
  20. return super.partialDefinitions().concat([
  21. {
  22. name: 'default-stack',
  23. type: Boolean,
  24. description: 'Print the default middleware stack. Any of these built-in middlewares are available to use in a custom stack.',
  25. section: 'core'
  26. }
  27. ])
  28. }
  29. usage () {
  30. const sections = super.usage()
  31. sections.shift()
  32. sections.shift()
  33. sections.pop()
  34. sections.unshift(
  35. {
  36. header: 'local-web-server',
  37. content: 'The modular web server for productive full-stack development.'
  38. },
  39. {
  40. header: 'Synopsis',
  41. content: [
  42. '$ ws <options>',
  43. '$ ws {underline command} <options>'
  44. ]
  45. }
  46. )
  47. sections.push({
  48. content: 'Project home: {underline https://github.com/lwsjs/local-web-server}'
  49. })
  50. return sections
  51. }
  52. showVersion () {
  53. const pkg = require(path.resolve(__dirname, '..', 'package.json'))
  54. this.log(pkg.version)
  55. }
  56. }
  57. module.exports = WsCli