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.

77 lines
1.7 KiB

8 years ago
8 years ago
7 years ago
7 years ago
  1. 'use strict'
  2. const Lws = require('lws')
  3. const Serve = require('lws/lib/command/serve')
  4. const path = require('path')
  5. /**
  6. * @module local-web-server
  7. */
  8. class WsServe extends Serve {
  9. execute (options, argv) {
  10. options = {
  11. stack: [
  12. 'lws-log',
  13. 'lws-cors',
  14. 'lws-json',
  15. 'lws-rewrite',
  16. 'lws-body-parser',
  17. 'lws-blacklist',
  18. 'lws-conditional-get',
  19. 'lws-mime',
  20. 'lws-compress',
  21. 'lws-mock-response',
  22. 'lws-spa',
  23. 'lws-static',
  24. 'lws-index'
  25. ],
  26. moduleDir: path.resolve(__dirname, `../node_modules`),
  27. modulePrefix: 'lws-'
  28. }
  29. super.execute(options, argv)
  30. }
  31. usage () {
  32. const sections = super.usage()
  33. sections.shift()
  34. sections.shift()
  35. sections.pop()
  36. sections.unshift(
  37. {
  38. header: 'local-web-server',
  39. content: 'A convenient local web server to support productive, full-stack Javascript development.'
  40. },
  41. {
  42. header: 'Synopsis',
  43. content: [
  44. '$ ws <options>',
  45. '$ ws [underline]{command} <options>'
  46. ]
  47. }
  48. )
  49. sections.push({
  50. content: 'Project home: [underline]{https://github.com/lwsjs/local-web-server}'
  51. })
  52. return sections
  53. }
  54. }
  55. /**
  56. * @alias module:local-web-server
  57. */
  58. class LocalWebServer extends Lws {
  59. constructor (options) {
  60. super (options)
  61. /* override default serve command */
  62. this.commands.add(null, WsServe)
  63. /* add feature-list command */
  64. this.commands.add('feature-list', require('./feature-list'))
  65. }
  66. getVersion () {
  67. const pkg = require(path.resolve(__dirname, '..', 'package.json'))
  68. return pkg.version
  69. }
  70. }
  71. module.exports = LocalWebServer