Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Added progress bar command line switch #1

Merged
merged 2 commits into from
Jun 23, 2017
Merged
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
6 changes: 4 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
----
26 changes: 23 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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);
};
};
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asciidoc-link-check",
"version": "1.0.1",
"version": "1.0.2",
"description": "Checks if all hyperlinks in an asciidoc file are alive(or dead).",
"bin": {
"asciidoc-link-check": "asciidoc-link-check"
Expand Down Expand Up @@ -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"
}
}
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```