forked from webpack/webpack.js.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-links.js
executable file
·46 lines (37 loc) · 1.15 KB
/
check-links.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
// Check piped links while allowing a fixed amount to fail
// Adapted from tap-json.
var parser = require('tap-parser');
var through = require('through2');
var duplexer = require('duplexer');
var minimist = require('minimist');
process.stdin
.pipe(checkLinks())
.pipe(process.stdout);
function checkLinks(args) {
var argv = minimist(process.argv.slice(2));
var skip = argv.skip || 0;
var tap = parser();
var out = through.obj();
var dup = duplexer(tap, out);
var data = [];
var name = null;
tap.on('complete', function(res) {
const failures = res.failures.filter(failure => !failure.diag || !failure.diag.at ||
!failure.diag.at.match(/class="(support__item|support__backers-avatar|support__sponsors-avatar)"/));
if (failures.length > 0) {
console.log(formatFailures(failures));
}
// Fail hard only if over skip threshold
if (failures.length > skip) {
process.exit(1);
}
});
return dup;
}
function formatFailures(failures) {
return failures.map(failure => {
let { diag = {} } = failure;
return failure.name + '\n' + diag.actual + ' at ' + diag.at;
}).join('\n\n');
}