tools: make add-on scraper print filenames
authorBen Noordhuis <info@bnoordhuis.nl>
Thu, 20 Aug 2015 14:57:03 +0000 (16:57 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Tue, 25 Aug 2015 10:05:16 +0000 (12:05 +0200)
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: https://github.com/nodejs/node/pull/2428
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Rod Vagg <rod@vagg.org>
tools/doc/addon-verify.js

index f87cfec..4d1aaab 100644 (file)
@@ -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') {
@@ -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) {
@@ -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();
+      });
+    });
   });
 }