« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/upd8-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'upd8-util.js')
-rw-r--r--upd8-util.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/upd8-util.js b/upd8-util.js
index b36fbc93..b94ffe3a 100644
--- a/upd8-util.js
+++ b/upd8-util.js
@@ -43,3 +43,17 @@ module.exports.joinNoOxford = function(array, plural = 'and') {
 
     return `${array.slice(0, -1).join(', ')} ${plural} ${array[array.length - 1]}`;
 };
+
+module.exports.progressPromiseAll = function (msg, array) {
+    let done = 0, total = array.length;
+    process.stdout.write(`\r${msg} [0/${total}]`);
+    return Promise.all(array.map(promise => promise.then(val => {
+        done++;
+        if (done === total) {
+            process.stdout.write(`\r\x1b[2m${msg} [${done}/${total}] \x1b[0;32mDone!\x1b[0m \n`)
+        } else {
+            process.stdout.write(`\r${msg} [${done}/${total}]`);
+        }
+        return val;
+    })));
+};