-
Notifications
You must be signed in to change notification settings - Fork 54
/
link-check.js
44 lines (35 loc) · 1.09 KB
/
link-check.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
#!/usr/bin/env node
'use strict';
var markdownLinkCheck = require('markdown-link-check');
var fs = require("fs");
var glob = require("glob");
var path = require("path");
var chalk = require("chalk");
var url = require("url");
var files = glob.sync("**/*.md", {
ignore: ["**/node_modules/**/*.md"],
realpath: true
})
var config = JSON.parse(fs.readFileSync(".markdown-link-check.json"));
config.timeout = '30s'
files.forEach(function (file) {
var markdown = fs.readFileSync(file).toString();
let opts = Object.assign({}, config);
opts.baseUrl = 'file://' + path.dirname(path.resolve(file));
markdownLinkCheck(markdown, opts, function (err, results) {
if (err) {
console.error('Error', err);
return;
}
console.log(chalk.green("Reading: " + file));
results.forEach(function (result) {
if (result.status === "dead") {
process.exitCode = 1
console.log(chalk.red("Dead: " + result.link));
} else if (result.status == "error") {
process.exitCode = 1
console.log(chalk.red("Link Error: " + result.link));
}
});
});
});