From 299cf8c5d706099d4e80c0a36bb62e5bc87fdf49 Mon Sep 17 00:00:00 2001 From: Gaurav Nelson Date: Fri, 23 Jun 2017 14:59:46 +1000 Subject: [PATCH] Added command line switches to show progress --- README.adoc | 6 ++++-- index.js | 26 +++++++++++++++++++++++--- package-lock.json | 15 +++++++++++++++ package.json | 7 ++++--- readme.md | 6 ++++-- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/README.adoc b/README.adoc index 3a49206..6f51ddb 100644 --- a/README.adoc +++ b/README.adoc @@ -45,10 +45,12 @@ asciidocLinkCheck('xref:https://www.google.com[Google]', function (err, results) ---- === Command Line +(Optional) Use the `-p` or `--progress` switch to view progress. + ==== Check links for a local file [source,bash] ---- -asciidoc-link-check README.adoc +asciidoc-link-check README.adoc --progress ---- ==== Check links for an online file @@ -60,5 +62,5 @@ asciidoc-link-check https://github.com/gaurav-nelson/asciidoc-link-check/blob/ma ==== Check links from standard input [source,bash] ---- -cat *.adoc | asciidoc-link-check +cat *.adoc | asciidoc-link-check -p ---- diff --git a/index.js b/index.js index 77185e6..08cdca2 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,13 @@ var _ = require('lodash'); var async = require('async'); var linkCheck = require('link-check'); var asciidocLinkExtractor = require('asciidoc-link-extractor'); +var ProgressBar = require('progress'); +var bar; +var showProgressBar = false; + +if (_.includes(process.argv, "--progress") || _.includes(process.argv, "-p")) { + showProgressBar = true; +} module.exports = function asciidocLinkCheck(asciidoc, opts, callback) { if (arguments.length === 2 && typeof opts === 'function') { @@ -12,7 +19,20 @@ module.exports = function asciidocLinkCheck(asciidoc, opts, callback) { opts = {}; } - async.mapLimit(_.uniq(asciidocLinkExtractor(asciidoc)), 2, function (link, callback) { - linkCheck(link, opts, callback); + var linksCollection = _.uniq(asciidocLinkExtractor(asciidoc)) + if (showProgressBar) { + bar = bar || new ProgressBar('Checking... [:bar] :percent', { + complete: '=', + incomplete: ' ', + width: 25, + total: linksCollection.length + }); + } + + async.mapLimit(linksCollection, 2, function (link, callback) { + linkCheck(link, opts, callback) + if (showProgressBar) { + bar.tick(); + } }, callback); -}; +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d7d97e2..208b711 100644 --- a/package-lock.json +++ b/package-lock.json @@ -117,6 +117,11 @@ "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", "optional": true }, + "editions": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/editions/-/editions-1.3.3.tgz", + "integrity": "sha1-CQcQG92iD6w8vjNMJ8vQaI3Jmls=" + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -282,6 +287,16 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", "integrity": "sha1-M+8wxcd9TqIcWlOGnZG1bY8lVeU=" }, + "progress": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", + "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=" + }, + "progressbar": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/progressbar/-/progressbar-1.1.1.tgz", + "integrity": "sha1-m051ghYJwjY6YvX3RMcR2Io65wA=" + }, "punycode": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", diff --git a/package.json b/package.json index 9dccfa2..2f2cc6b 100644 --- a/package.json +++ b/package.json @@ -30,12 +30,13 @@ }, "homepage": "https://github.com/gaurav-nelson/asciidoc-link-check#readme", "dependencies": { + "asciidoc-link-extractor": "^1.0.0", "async": "^2.1.4", "chalk": "^1.1.3", "commander": "^2.9.0", "link-check": "^4.0.2", - "asciidoc-link-extractor": "^1.0.0", - "request": "^2.79.0", - "lodash": "^4.17.4" + "lodash": "^4.17.4", + "progress": "^2.0.0", + "request": "^2.79.0" } } diff --git a/readme.md b/readme.md index b2c352e..47c3fcf 100644 --- a/readme.md +++ b/readme.md @@ -45,10 +45,12 @@ asciidocLinkCheck('xref:https://www.google.com[Google]', function (err, results) ``` ### Command Line +(Optional) Use the `-p` or `--progress` switch to view progress. + #### Check links for a local file ```bash -asciidoc-link-check README.adoc +asciidoc-link-check README.adoc --progress ``` #### Check links for an online file @@ -60,5 +62,5 @@ asciidoc-link-check https://github.com/gaurav-nelson/asciidoc-link-check/blob/ma #### Check links from standard input ```bash -cat *.adoc | asciidoc-link-check +cat *.adoc | asciidoc-link-check -p ```