tools: make doc tool a bit more readable

PR-URL: https://github.com/nodejs/node/pull/17125
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Tobias Nießen 2017-11-18 21:04:05 +01:00
parent e515a0eced
commit 2ba93f6ed7
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70
2 changed files with 12 additions and 23 deletions

View File

@ -30,13 +30,13 @@ const fs = require('fs');
const args = process.argv.slice(2); const args = process.argv.slice(2);
let format = 'json'; let format = 'json';
let template = null; let template = null;
let inputFile = null; let filename = null;
let nodeVersion = null; let nodeVersion = null;
let analytics = null; let analytics = null;
args.forEach(function(arg) { args.forEach(function(arg) {
if (!arg.startsWith('--')) { if (!arg.startsWith('--')) {
inputFile = arg; filename = arg;
} else if (arg.startsWith('--format=')) { } else if (arg.startsWith('--format=')) {
format = arg.replace(/^--format=/, ''); format = arg.replace(/^--format=/, '');
} else if (arg.startsWith('--template=')) { } else if (arg.startsWith('--template=')) {
@ -50,41 +50,32 @@ args.forEach(function(arg) {
nodeVersion = nodeVersion || process.version; nodeVersion = nodeVersion || process.version;
if (!inputFile) { if (!filename) {
throw new Error('No input file specified'); throw new Error('No input file specified');
} }
fs.readFile(inputFile, 'utf8', function(er, input) { fs.readFile(filename, 'utf8', (er, input) => {
if (er) throw er; if (er) throw er;
// process the input for @include lines // process the input for @include lines
processIncludes(inputFile, input, next); processIncludes(filename, input, next);
}); });
function next(er, input) { function next(er, input) {
if (er) throw er; if (er) throw er;
switch (format) { switch (format) {
case 'json': case 'json':
require('./json.js')(input, inputFile, function(er, obj) { require('./json.js')(input, filename, (er, obj) => {
console.log(JSON.stringify(obj, null, 2)); console.log(JSON.stringify(obj, null, 2));
if (er) throw er; if (er) throw er;
}); });
break; break;
case 'html': case 'html':
require('./html.js')( require('./html')({ input, filename, template, nodeVersion, analytics },
{ (err, html) => {
input: input, if (err) throw err;
filename: inputFile, console.log(html);
template: template, });
nodeVersion: nodeVersion,
analytics: analytics,
},
function(er, html) {
if (er) throw er;
console.log(html);
}
);
break; break;
default: default:

View File

@ -125,9 +125,7 @@ function toID(filename) {
* opts: lexed, filename, template, nodeVersion. * opts: lexed, filename, template, nodeVersion.
*/ */
function render(opts, cb) { function render(opts, cb) {
var lexed = opts.lexed; var { lexed, filename, template } = opts;
var filename = opts.filename;
var template = opts.template;
const nodeVersion = opts.nodeVersion || process.version; const nodeVersion = opts.nodeVersion || process.version;
// get the section // get the section