From fa693fdd85955f24be8b009901ca077a8d35dbaf Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sun, 7 Jun 2020 16:41:06 -0700 Subject: [PATCH] fix: make the --readme flag usable + fix(jsdoc): resolve the path to the README file + fix(jsdoc-cli): don't treat --readme as a boolean --- packages/jsdoc-cli/lib/flags.js | 1 - packages/jsdoc-cli/test/specs/lib/flags.js | 12 ++++++++---- packages/jsdoc/cli.js | 8 ++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/jsdoc-cli/lib/flags.js b/packages/jsdoc-cli/lib/flags.js index 3582bbbc..1afe13c7 100644 --- a/packages/jsdoc-cli/lib/flags.js +++ b/packages/jsdoc-cli/lib/flags.js @@ -76,7 +76,6 @@ module.exports = { }, readme: { alias: 'R', - boolean: true, description: 'The `README` file to include in the documentation.', normalize: true, requiresArg: true diff --git a/packages/jsdoc-cli/test/specs/lib/flags.js b/packages/jsdoc-cli/test/specs/lib/flags.js index 6a2baa2c..6fb7ce4e 100644 --- a/packages/jsdoc-cli/test/specs/lib/flags.js +++ b/packages/jsdoc-cli/test/specs/lib/flags.js @@ -5,21 +5,25 @@ function validate(name, opts) { name = `--${name}`; if (!opts.description) { - throw new TypeError(`${name} is missing its description.`); + throw new TypeError(`${name} is missing its description`); } if (opts.array && opts.boolean) { - throw new TypeError(`${name} can be an array or a boolean, but not both.`); + throw new TypeError(`${name} can be an array or a boolean, but not both`); + } + + if (opts.requiresArg && opts.boolean) { + throw new TypeError(`${name} can require an argument or be a boolean, but not both`); } try { ow(opts.coerce, ow.optional.function); } catch (e) { - throw new TypeError(`The coerce value for ${name} is not a function.`); + throw new TypeError(`The coerce value for ${name} is not a function`); } if (opts.choices && !opts.requiresArg) { - throw new TypeError(`${name} specifies choices, but not requiresArg.`); + throw new TypeError(`${name} specifies choices, but not requiresArg`); } } diff --git a/packages/jsdoc/cli.js b/packages/jsdoc/cli.js index f81cff24..2aadfb0d 100644 --- a/packages/jsdoc/cli.js +++ b/packages/jsdoc/cli.js @@ -4,6 +4,7 @@ const { config } = require('@jsdoc/core'); const Engine = require('@jsdoc/cli'); const env = require('jsdoc/env'); const { EventBus, log } = require('@jsdoc/util'); +const path = require('path'); const stripBom = require('strip-bom'); const stripJsonComments = require('strip-json-comments'); const Promise = require('bluebird'); @@ -32,7 +33,6 @@ module.exports = (() => { // TODO: docs cli.setVersionInfo = () => { const fs = require('fs'); - const path = require('path'); // allow this to throw--something is really wrong if we can't read our own package file const info = JSON.parse(stripBom(fs.readFileSync(path.join(env.dirname, 'package.json'), @@ -260,6 +260,11 @@ module.exports = (() => { } } + // Resolve the path to the README. + if (env.opts.readme) { + env.opts.readme = path.resolve(env.opts.readme); + } + props.packageJson = packageJson; return sourceFiles; @@ -348,7 +353,6 @@ module.exports = (() => { cli.generateDocs = () => { let message; - const path = require('path'); const taffy = require('taffydb').taffy; let template;