diff --git a/bin/cli.js b/bin/cli.js index 056796a..c44161b 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -3,6 +3,7 @@ const localWebServer = require('../') const cliOptions = require('../lib/cli-options') const commandLineArgs = require('command-line-args') +const commandLineUsage = require('command-line-usage') const ansi = require('ansi-escape-sequences') const loadConfig = require('config-master') const path = require('path') @@ -11,8 +12,7 @@ const arrayify = require('array-back') const t = require('typical') const flatten = require('reduce-flatten') -const cli = commandLineArgs(cliOptions.definitions) -const usage = cli.getUsage(cliOptions.usageData) +const usage = commandLineUsage(cliOptions.usageData) const stored = loadConfig('local-web-server') let options let isHttps = false @@ -116,7 +116,7 @@ function collectOptions () { let options = {} /* parse command line args */ - options = cli.parse() + options = commandLineArgs(cliOptions.definitions) const builtIn = { port: 8000, diff --git a/lib/cli-options.js b/lib/cli-options.js index e582ad0..7bf2a32 100644 --- a/lib/cli-options.js +++ b/lib/cli-options.js @@ -1,74 +1,85 @@ -module.exports = { - definitions: [ - { - name: 'port', alias: 'p', type: Number, defaultOption: true, - description: 'Web server port.', group: 'server' - }, - { - name: 'directory', alias: 'd', type: String, typeLabel: '[underline]{path}', - description: 'Root directory, defaults to the current directory.', group: 'server' - }, - { - name: 'log-format', alias: 'f', type: String, - description: "If a format is supplied an access log is written to stdout. If not, a dynamic statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url').", group: 'server' - }, - { - name: 'rewrite', alias: 'r', type: String, multiple: true, typeLabel: '[underline]{expression} ...', - description: "A list of URL rewrite rules. For each rule, separate the 'from' and 'to' routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from -> /to'.", group: 'server' - }, - { - name: 'spa', alias: 's', type: String, typeLabel: '[underline]{file}', - description: 'Path to a Single Page App, e.g. app.html.', group: 'server' - }, - { - name: 'compress', alias: 'c', type: Boolean, - description: 'Serve gzip-compressed resources, where applicable.', group: 'server' - }, - { - name: 'forbid', alias: 'b', type: String, multiple: true, typeLabel: '[underline]{path} ...', - description: 'A list of forbidden routes.', group: 'server' - }, - { - name: 'no-cache', alias: 'n', type: Boolean, - description: 'Disable etag-based caching - forces loading from disk each request.', group: 'server' - }, - { - name: 'key', type: String, typeLabel: '[underline]{file}', group: 'server', - description: 'SSL key. Supply along with --cert to launch a https server.' - }, - { - name: 'cert', type: String, typeLabel: '[underline]{file}', group: 'server', - description: 'SSL cert. Supply along with --key to launch a https server.' - }, - { - name: 'https', type: Boolean, group: 'server', - description: 'Enable HTTPS using a built-in key and cert, registered to the domain 127.0.0.1.' - }, - { - name: 'verbose', type: Boolean, - description: 'Verbose output, useful for debugging.', group: 'server' - }, - { - name: 'help', alias: 'h', type: Boolean, - description: 'Print these usage instructions.', group: 'misc' - }, - { - name: 'config', type: Boolean, - description: 'Print the stored config.', group: 'misc' - } - ], - usageData: { - title: 'local-web-server', - description: 'A simple web-server for productive front-end development.', - footer: 'Project home: [underline]{https://github.com/75lb/local-web-server}', - synopsis: [ +exports.definitions = [ + { + name: 'port', alias: 'p', type: Number, defaultOption: true, + description: 'Web server port.', group: 'server' + }, + { + name: 'directory', alias: 'd', type: String, typeLabel: '[underline]{path}', + description: 'Root directory, defaults to the current directory.', group: 'server' + }, + { + name: 'log-format', alias: 'f', type: String, + description: "If a format is supplied an access log is written to stdout. If not, a dynamic statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url').", group: 'server' + }, + { + name: 'rewrite', alias: 'r', type: String, multiple: true, typeLabel: '[underline]{expression} ...', + description: "A list of URL rewrite rules. For each rule, separate the 'from' and 'to' routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from -> /to'.", group: 'server' + }, + { + name: 'spa', alias: 's', type: String, typeLabel: '[underline]{file}', + description: 'Path to a Single Page App, e.g. app.html.', group: 'server' + }, + { + name: 'compress', alias: 'c', type: Boolean, + description: 'Serve gzip-compressed resources, where applicable.', group: 'server' + }, + { + name: 'forbid', alias: 'b', type: String, multiple: true, typeLabel: '[underline]{path} ...', + description: 'A list of forbidden routes.', group: 'server' + }, + { + name: 'no-cache', alias: 'n', type: Boolean, + description: 'Disable etag-based caching - forces loading from disk each request.', group: 'server' + }, + { + name: 'key', type: String, typeLabel: '[underline]{file}', group: 'server', + description: 'SSL key. Supply along with --cert to launch a https server.' + }, + { + name: 'cert', type: String, typeLabel: '[underline]{file}', group: 'server', + description: 'SSL cert. Supply along with --key to launch a https server.' + }, + { + name: 'https', type: Boolean, group: 'server', + description: 'Enable HTTPS using a built-in key and cert, registered to the domain 127.0.0.1.' + }, + { + name: 'verbose', type: Boolean, + description: 'Verbose output, useful for debugging.', group: 'server' + }, + { + name: 'help', alias: 'h', type: Boolean, + description: 'Print these usage instructions.', group: 'misc' + }, + { + name: 'config', type: Boolean, + description: 'Print the stored config.', group: 'misc' + } +] +exports.usageData = [ + { + header: 'local-web-server', + content: 'A simple web-server for productive front-end development.' + }, + { + header: 'Usage', + content: [ '$ ws []', '$ ws --config', '$ ws --help' - ], - groups: { - server: 'Server', - misc: 'Misc' - } + ] + }, + { + header: 'Server', + optionList: exports.definitions, + group: 'server' + }, + { + header: 'Misc', + optionList: exports.definitions, + group: 'misc' + }, + { + content: 'Project home: [underline]{https://github.com/75lb/local-web-server}' } -} +] diff --git a/package.json b/package.json index 8147a74..3130b43 100644 --- a/package.json +++ b/package.json @@ -29,18 +29,19 @@ "repository": "https://github.com/75lb/local-web-server", "author": "Lloyd Brookes <75pound@gmail.com>", "dependencies": { - "ansi-escape-sequences": "^2.2.2", + "ansi-escape-sequences": "^3.0.0", "array-back": "^1.0.3", - "command-line-args": "^2.1.6", - "config-master": "^2.0.2", + "command-line-args": "^3.0.1", + "command-line-usage": "^3.0.5", + "config-master": "^2.0.4", "debug": "^2.2.0", - "http-proxy": "^1.13.2", - "kcors": "^1.2.0", + "http-proxy": "^1.15.1", + "kcors": "^1.3.0", "koa": "^2.0.0", "koa-bodyparser": "^3.0.0", "koa-compress": "^1.0.9", "koa-conditional-get": "^1.0.3", - "koa-connect-history-api-fallback": "^0.3.0", + "koa-connect-history-api-fallback": "^0.3.1", "koa-convert": "^1.2.0", "koa-etag": "^2.1.1", "koa-json": "^1.1.3", @@ -50,16 +51,16 @@ "koa-send": "^3.2.0", "koa-serve-index": "^1.1.1", "koa-static": "^2.0.0", - "path-to-regexp": "^1.2.1", - "reduce-flatten": "^1.0.0", - "stream-log-stats": "^1.1.3", + "path-to-regexp": "^1.6.0", + "reduce-flatten": "^1.0.1", + "stream-log-stats": "^1.1.7", "string-tools": "^1.0.0", - "test-value": "^2.0.0", - "typical": "^2.4.2" + "test-value": "^2.1.0", + "typical": "^2.6.0" }, "devDependencies": { - "jsdoc-to-markdown": "^1.3.6", + "jsdoc-to-markdown": "^2.0.0", "req-then": "^0.2.4", - "tape": "^4.5.1" + "tape": "^4.6.2" } }