Skip to content

Commit

Permalink
tools: make add-on scraper print filenames
Browse files Browse the repository at this point in the history
Make the tool that generates add-ons from doc/api/addons.markdown print
the names of the files it writes out.  Before this commit, it printed a
rather unhelpful "Done."

PR-URL: #2428
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Rod Vagg <rod@vagg.org>
  • Loading branch information
bnoordhuis authored and rvagg committed Aug 26, 2015
1 parent 944174b commit f2f0fe4
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions tools/doc/addon-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if (token.type === 'heading') {
if (files && Object.keys(files).length !== 0) {
verifyFiles(files, function(err) {
if (err)
console.log(err);
else
console.log('done');
});
verifyFiles(files,
console.log.bind(null, 'wrote'),
function(err) { if (err) throw err; });
}
files = {};
} else if (token.type === 'code') {
Expand All @@ -51,7 +48,7 @@ function once(fn) {
};
}

function verifyFiles(files, callback) {
function verifyFiles(files, onprogress, ondone) {
var dir = path.resolve(verifyDir, 'doc-' + id++);

files = Object.keys(files).map(function(name) {
Expand All @@ -78,17 +75,19 @@ function verifyFiles(files, callback) {
fs.mkdir(dir, function() {
// Ignore errors

var done = once(ondone);
var waiting = files.length;
for (var i = 0; i < files.length; i++)
fs.writeFile(files[i].path, files[i].content, next);
files.forEach(function(file) {
fs.writeFile(file.path, file.content, function(err) {
if (err)
return done(err);

var done = once(callback);
function next(err) {
if (err)
return done(err);
if (onprogress)
onprogress(file.path);

if (--waiting === 0)
done();
}
if (--waiting === 0)
done();
});
});
});
}

0 comments on commit f2f0fe4

Please sign in to comment.