Skip to content

Commit df8efa4

Browse files
authored
Update dependencies (#560)
* also deprecated --private option in favor of --access
1 parent 803f4a8 commit df8efa4

File tree

18 files changed

+250
-273
lines changed

18 files changed

+250
-273
lines changed

bin/documentation.js

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,35 @@
11
#!/usr/bin/env node
22

3+
/* eslint no-console: 0 */
4+
35
'use strict';
46

5-
var documentation = require('../'),
6-
path = require('path'),
7-
yargs = require('yargs'),
8-
extend = require('extend'),
9-
loadConfig = require('../lib/load_config.js'),
7+
var yargs = require('yargs'),
108
commands = require('../lib/commands');
119

12-
var parsedArgs = parseArgs();
13-
commands[parsedArgs.command](documentation, parsedArgs);
14-
15-
function parseArgs() {
16-
17-
var rawArgv = addCommands(yargs)
18-
.version(function () {
19-
return require('../package').version;
20-
})
21-
.argv;
22-
23-
var command = rawArgv._[0];
24-
25-
if (!commands[command]) {
26-
yargs.showHelp();
27-
var suggestion = [rawArgv['$0'], 'build'].concat(process.argv.slice(2)).join(' ');
28-
process.stderr.write('Unknown command: ' + command + '. Did you mean "' + suggestion + '"?\n');
29-
process.exit(1);
30-
}
31-
32-
var argv = commands[command].parseArgs(yargs.reset()).argv;
33-
var inputs = argv._.slice(1);
34-
35-
var options = {};
36-
if (argv.config) {
37-
options = loadConfig(argv.config);
38-
}
39-
options = extend(options, argv);
40-
41-
if (typeof options.access === 'string') {
42-
options.access = [options.access];
43-
}
44-
45-
if (options.private) {
46-
options.access = (options.access || ['public', 'undefined', 'protected']).concat(['private']);
47-
}
48-
49-
if (inputs.length == 0) {
50-
try {
51-
var p = require(path.resolve('package.json'));
52-
options.package = p;
53-
inputs = [p.main || 'index.js'];
54-
} catch (e) {
55-
yargs.showHelp();
56-
throw new Error('documentation was given no files and was not run in a module directory');
57-
}
58-
}
10+
var argv = yargs
11+
.command(commands.serve)
12+
.command(commands.build)
13+
.command(commands.lint)
14+
.command(commands.readme)
15+
.version(function () {
16+
return require('../package').version;
17+
})
18+
.recommendCommands()
19+
.help()
20+
.argv;
21+
22+
if (argv.private) {
23+
console.error('--private is deprecated, please use the --access (or -a) option instead');
24+
console.error('for example: -a public -a private -a protected -a undefined');
25+
}
5926

60-
return {
61-
inputs: inputs,
62-
command: command,
63-
commandOptions: addCommands(yargs).argv,
64-
options: options
65-
};
27+
if (!argv._handled) {
28+
yargs.showHelp('error');
29+
process.exit(1);
6630
}
6731

68-
function addCommands(parser) {
69-
return Object.keys(commands).reduce(function (parser, cmd) {
70-
return parser.command(cmd, commands[cmd].description);
71-
}, parser.demand(1)).help('help');
32+
33+
if (!yargs.argv._.length) {
34+
yargs.showHelp();
7235
}

default_theme/test/format_markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var remark = require('remark');
33
var formatMarkdown = require('../lib/format_markdown');
44

55
test('main', function (t) {
6-
t.deepEqual(formatMarkdown(remark.parse('Converts from `Result<T>` to `?Error`')),
6+
t.deepEqual(formatMarkdown(remark().parse('Converts from `Result<T>` to `?Error`')),
77
'<p>Converts from <code>Result&lt;T&gt;</code> to <code>?Error</code></p>\n');
88
t.done();
99
});

default_theme/test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test('main', function (t) {
77
{
88
path: [],
99
context: {},
10-
description: remark.parse('test'),
10+
description: remark().parse('test'),
1111
members: {
1212
static: [],
1313
instance: []

lib/commands/build.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@ var streamArray = require('stream-array'),
44
sharedOptions = require('./shared_options'),
55
fs = require('fs'),
66
vfs = require('vinyl-fs'),
7+
extend = require('extend'),
78
chokidar = require('chokidar'),
9+
documentation = require('../../'),
810
debounce = require('debounce');
911

10-
module.exports = build;
11-
module.exports.description = 'build documentation';
12+
module.exports.command = 'build [input..]';
13+
module.exports.describe = 'build documentation';
1214

1315
/**
1416
* Add yargs parsing for the build command
1517
* @param {Object} yargs module instance
1618
* @returns {Object} yargs with options
1719
* @private
1820
*/
19-
module.exports.parseArgs = function (yargs) {
20-
return sharedOptions.sharedOutputOptions(
21-
sharedOptions.sharedInputOptions(yargs))
22-
.option('format', {
21+
module.exports.builder = extend({},
22+
sharedOptions.sharedOutputOptions,
23+
sharedOptions.sharedInputOptions, {
24+
format: {
2325
alias: 'f',
2426
default: 'json',
2527
choices: ['json', 'md', 'remark', 'html']
26-
})
27-
.option('output', {
28+
},
29+
output: {
2830
describe: 'output location. omit for stdout, otherwise is a filename ' +
29-
'for single-file outputs and a directory name for multi-file outputs like html',
31+
'for single-file outputs and a directory name for multi-file outputs like html',
3032
default: 'stdout',
3133
alias: 'o'
32-
})
33-
.example('documentation build foo.js -f md > API.md', 'parse documentation in a ' +
34-
'file and generate API documentation as Markdown');
35-
};
34+
},
35+
example: 'documentation build foo.js -f md > API.md'
36+
});
3637

3738
/*
3839
* The `build` command. Requires either `--output` or the `callback` argument.
@@ -42,22 +43,22 @@ module.exports.parseArgs = function (yargs) {
4243
* The former case, with the callback, is used by the `serve` command, which is
4344
* just a thin wrapper around this one.
4445
*/
45-
function build(documentation, parsedArgs, callback) {
46-
var inputs = parsedArgs.inputs;
47-
var buildOptions = parsedArgs.commandOptions;
48-
var options = parsedArgs.options;
49-
if (options.f === 'html' && options.o === 'stdout') {
46+
module.exports.handler = function build(argv, callback) {
47+
argv._handled = true;
48+
argv = sharedOptions.expandInputs(argv);
49+
if (argv.f === 'html' && argv.o === 'stdout') {
5050
throw new Error('The HTML output mode requires a destination directory set with -o');
5151
}
5252
var formatterOptions = {
53-
name: buildOptions.name || (options.package || {}).name,
54-
version: buildOptions['project-version'] || (options.package || {}).version,
55-
theme: buildOptions.theme,
56-
paths: options.paths,
57-
hljs: options.hljs || {}
53+
name: argv.name || (argv.package || {}).name,
54+
version: argv['project-version'] || (argv.package || {}).version,
55+
theme: argv.theme,
56+
paths: argv.paths,
57+
hljs: argv.hljs || {}
5858
};
5959

60-
var generator = documentation.build.bind(null, inputs, options, onDocumented);
60+
var generator = documentation.build
61+
.bind(null, argv.input, argv, onDocumented);
6162

6263
function onDocumented(err, comments) {
6364
if (err) {
@@ -67,38 +68,38 @@ function build(documentation, parsedArgs, callback) {
6768
throw err;
6869
}
6970

70-
documentation.formats[buildOptions.format](comments, formatterOptions, onFormatted);
71+
documentation.formats[argv.format](comments, formatterOptions, onFormatted);
7172
}
7273

7374
function onFormatted(err, output) {
74-
if (buildOptions.watch) {
75+
if (argv.watch) {
7576
updateWatcher();
7677
}
7778

7879
if (typeof callback === 'function') {
7980
callback(null, output);
80-
} else if (buildOptions.output === 'stdout') {
81+
} else if (argv.output === 'stdout') {
8182
process.stdout.write(output);
8283
} else if (Array.isArray(output)) {
83-
streamArray(output).pipe(vfs.dest(buildOptions.output));
84+
streamArray(output).pipe(vfs.dest(argv.output));
8485
} else {
85-
fs.writeFileSync(buildOptions.output, output);
86+
fs.writeFileSync(argv.output, output);
8687
}
8788
}
8889

89-
if (buildOptions.watch) {
90-
var watcher = chokidar.watch(inputs);
90+
if (argv.watch) {
91+
var watcher = chokidar.watch(argv.input);
9192
watcher.on('all', debounce(generator, 300));
9293
}
9394
generator();
9495

9596
function updateWatcher() {
96-
documentation.expandInputs(inputs, options, addNewFiles);
97+
documentation.expandInputs(argv.input, argv, addNewFiles);
9798
}
9899

99100
function addNewFiles(err, files) {
100101
watcher.add(files.map(function (data) {
101102
return typeof data === 'string' ? data : data.file;
102103
}));
103104
}
104-
}
105+
};

lib/commands/lint.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
'use strict';
22

3+
var documentation = require('../../');
4+
var sharedOptions = require('./shared_options');
5+
36
/* eslint no-console: 0 */
47

5-
module.exports = lint;
8+
module.exports.command = 'lint [input..]';
69
module.exports.description = 'check for common style and uniformity mistakes';
7-
8-
/**
9-
* Add yargs parsing for the lint command
10-
* @param {Object} yargs module instance
11-
* @returns {Object} yargs with options
12-
* @private
13-
*/
14-
module.exports.parseArgs = function (yargs) {
15-
return yargs
16-
.example('documentation lint project.js', 'check documentation style')
17-
.help('help');
18-
};
10+
module.exports.builder = {};
1911

2012
/**
2113
* Wrap around the documentation.lint method and add the additional
2214
* behavior of printing to stdout and setting an exit status.
2315
*
24-
* @param {Object} documentation self-module instance
25-
* @param {Object} parsedArgs cli arguments
16+
* @param {Object} argv cli arguments
2617
* @returns {undefined} has side-effects
2718
* @private
2819
*/
29-
function lint(documentation, parsedArgs) {
30-
documentation.lint(parsedArgs.inputs, parsedArgs.options, function (err, lintOutput) {
20+
module.exports.handler = function (argv) {
21+
argv._handled = true;
22+
argv = sharedOptions.expandInputs(argv);
23+
documentation.lint(argv.input, argv, function (err, lintOutput) {
3124
if (err) {
3225
throw err;
3326
}
@@ -38,4 +31,4 @@ function lint(documentation, parsedArgs) {
3831
process.exit(0);
3932
}
4033
});
41-
}
34+
};

0 commit comments

Comments
 (0)