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

Commit

Permalink
fixed progressbar code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Nelson committed Jun 24, 2017
1 parent 2ec5aaf commit b37f574
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
6 changes: 4 additions & 2 deletions asciidoc-link-check
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var statusLabels = {
var error = false;
var opts = {};
var stream = process.stdin; // read from stdin unless a filename is given
program.arguments('[filenameOrUrl]').action(function (filenameOrUrl) {
program.option('-p, --progress', 'show progress bar').arguments('[filenameOrUrl]').action(function (filenameOrUrl) {
if (/https?:/.test(filenameOrUrl)) {
stream = request.get(filenameOrUrl);
try { // extract baseUrl from supplied URL
Expand All @@ -36,6 +36,8 @@ program.arguments('[filenameOrUrl]').action(function (filenameOrUrl) {
}
}).parse(process.argv);

opts.showProgressBar = (program.progress === true); // force true or undefined to be true or false.

var asciidoc = ''; // collect the asciidoc data, then process it
stream.on('data', function (chunk) {
asciidoc += chunk.toString();
Expand All @@ -52,4 +54,4 @@ stream.on('data', function (chunk) {
process.exit(1);
}
});
});
});
23 changes: 10 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ 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 @@ -19,9 +13,10 @@ module.exports = function asciidocLinkCheck(asciidoc, opts, callback) {
opts = {};
}

var linksCollection = _.uniq(asciidocLinkExtractor(asciidoc))
if (showProgressBar) {
bar = bar || new ProgressBar('Checking... [:bar] :percent', {
var bar;
var linksCollection = _.uniq(asciidocLinkExtractor(asciidoc));
if (opts.showProgressBar) {
bar = new ProgressBar('Checking... [:bar] :percent', {
complete: '=',
incomplete: ' ',
width: 25,
Expand All @@ -30,9 +25,11 @@ module.exports = function asciidocLinkCheck(asciidoc, opts, callback) {
}

async.mapLimit(linksCollection, 2, function (link, callback) {
linkCheck(link, opts, callback)
if (showProgressBar) {
bar.tick();
}
linkCheck(link, opts, function (err, result) {
if (opts.showProgressBar) {
bar.tick();
}
callback(err, result);
});
}, callback);
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asciidoc-link-check",
"version": "1.0.2",
"version": "1.0.3",
"description": "Checks if all hyperlinks in an asciidoc file are alive(or dead).",
"bin": {
"asciidoc-link-check": "asciidoc-link-check"
Expand Down Expand Up @@ -31,12 +31,12 @@
"homepage": "https://github.com/gaurav-nelson/asciidoc-link-check#readme",
"dependencies": {
"asciidoc-link-extractor": "^1.0.0",
"async": "^2.1.4",
"async": "^2.4.1",
"chalk": "^1.1.3",
"commander": "^2.9.0",
"link-check": "^4.0.2",
"commander": "^2.10.0",
"link-check": "^4.0.3",
"lodash": "^4.17.4",
"progress": "^2.0.0",
"request": "^2.79.0"
"request": "^2.81.0"
}
}

0 comments on commit b37f574

Please sign in to comment.