-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchecker.js
60 lines (51 loc) · 1.1 KB
/
checker.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import chalk from 'chalk';
import {
getScrapperInstance,
killScrapperInstance,
validateSidebarLinks,
} from './scrapper.js';
import { checkExternalLinks, checkInternalLinks } from './utils.js';
export const checkLinks = async (linkCache, storybookURL, ignorePattern) => {
const errorFiles = [];
let browser;
if (storybookURL) {
browser = await getScrapperInstance();
}
for (const file in linkCache) {
const { storybookLinks, externalLinks, internalLinks, filePathAbs } =
linkCache[file];
console.info(chalk.cyan(`\nFILE: ${filePathAbs}`));
// validate external links are valid using link - checker
checkExternalLinks(
filePathAbs,
externalLinks,
ignorePattern,
errorFiles
);
checkInternalLinks(
linkCache,
filePathAbs,
internalLinks,
ignorePattern,
errorFiles
);
if (storybookURL) {
try {
await validateSidebarLinks(
browser,
storybookURL,
storybookLinks,
filePathAbs,
ignorePattern,
errorFiles
);
} catch (err) {
throw err;
}
}
}
if (browser) {
await killScrapperInstance(browser);
}
return errorFiles;
};