Skip to content

Commit

Permalink
tools: make doc tool a bit more readable
Browse files Browse the repository at this point in the history
Backport-PR-URL: #17788
PR-URL: #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>
  • Loading branch information
tniessen authored and MylesBorins committed Jan 2, 2018
1 parent b8a5d6d commit 1d70602
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
33 changes: 12 additions & 21 deletions tools/doc/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const fs = require('fs');
const args = process.argv.slice(2);
let format = 'json';
let template = null;
let inputFile = null;
let filename = null;
let nodeVersion = null;
let analytics = null;

args.forEach(function(arg) {
if (!arg.startsWith('--')) {
inputFile = arg;
filename = arg;
} else if (arg.startsWith('--format=')) {
format = arg.replace(/^--format=/, '');
} else if (arg.startsWith('--template=')) {
Expand All @@ -29,42 +29,33 @@ args.forEach(function(arg) {

nodeVersion = nodeVersion || process.version;

if (!inputFile) {
if (!filename) {
throw new Error('No input file specified');
}

console.error('Input file = %s', inputFile);
fs.readFile(inputFile, 'utf8', function(er, input) {
console.error('Input file = %s', filename);
fs.readFile(filename, 'utf8', (er, input) => {
if (er) throw er;
// process the input for @include lines
processIncludes(inputFile, input, next);
processIncludes(filename, input, next);
});

function next(er, input) {
if (er) throw er;
switch (format) {
case 'json':
require('./json.js')(input, inputFile, function(er, obj) {
require('./json.js')(input, filename, (er, obj) => {
console.log(JSON.stringify(obj, null, 2));
if (er) throw er;
});
break;

case 'html':
require('./html.js')(
{
input: input,
filename: inputFile,
template: template,
nodeVersion: nodeVersion,
analytics: analytics,
},

function(er, html) {
if (er) throw er;
console.log(html);
}
);
require('./html')({ input, filename, template, nodeVersion, analytics },
(err, html) => {
if (err) throw err;
console.log(html);
});
break;

default:
Expand Down
4 changes: 1 addition & 3 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ function toID(filename) {
* opts: lexed, filename, template, nodeVersion.
*/
function render(opts, cb) {
var lexed = opts.lexed;
var filename = opts.filename;
var template = opts.template;
var { lexed, filename, template } = opts;
var nodeVersion = opts.nodeVersion || process.version;

// get the section
Expand Down

0 comments on commit 1d70602

Please sign in to comment.