From d2f5084c15ae12ab03572cca1ab7640e48ef00fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 18 Nov 2017 21:04:05 +0100 Subject: [PATCH] tools: make doc tool a bit more readable Backport-PR-URL: https://github.com/nodejs/node/pull/17788 PR-URL: https://github.com/nodejs/node/pull/17125 Reviewed-By: Colin Ihrig Reviewed-By: Anatoli Papirovski Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- tools/doc/generate.js | 33 ++++++++++++--------------------- tools/doc/html.js | 4 +--- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/tools/doc/generate.js b/tools/doc/generate.js index 1b04be832d954c..d6bf2d5e378979 100644 --- a/tools/doc/generate.js +++ b/tools/doc/generate.js @@ -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=')) { @@ -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: diff --git a/tools/doc/html.js b/tools/doc/html.js index 730031471fcc04..9ce0fdd5080630 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -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