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
This commit is contained in:
Jeff Williams 2020-06-07 16:41:06 -07:00
parent 495093600d
commit fa693fdd85
3 changed files with 14 additions and 7 deletions

View File

@ -76,7 +76,6 @@ module.exports = {
},
readme: {
alias: 'R',
boolean: true,
description: 'The `README` file to include in the documentation.',
normalize: true,
requiresArg: true

View File

@ -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`);
}
}

View File

@ -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;