Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: remove unnecessary function declaration and make code a bit more readable #17125

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions tools/doc/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const fs = require('fs');
const args = process.argv.slice(2);
let format = 'json';
let template = null;
let inputFile = null;
let filename = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using filename here is consistent with the name of the variable in other files and allows to pass the options object without renaming properties.

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 @@ -50,41 +50,32 @@ args.forEach(function(arg) {

nodeVersion = nodeVersion || process.version;

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

fs.readFile(inputFile, 'utf8', function(er, input) {
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 @@ -125,9 +125,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;
const nodeVersion = opts.nodeVersion || process.version;

// get the section
Expand Down
6 changes: 1 addition & 5 deletions tools/doc/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ const includeData = {};

function preprocess(inputFile, input, cb) {
input = stripComments(input);
processIncludes(inputFile, input, function(err, data) {
if (err) return cb(err);

cb(null, data);
});
processIncludes(inputFile, input, cb);
}

function stripComments(input) {
Expand Down