3
3
const linkinator = require ( 'linkinator' )
4
4
const checker = new linkinator . LinkChecker ( )
5
5
const { deprecated } = require ( '../lib/enterprise-server-releases' )
6
+ const englishRoot = 'http://localhost:4002/en'
6
7
7
8
// [start-readme]
8
9
//
9
10
// This script runs in CI via GitHub Action to check all *internal* links in English content,
10
11
// not including deprecated Enterprise Server content. This is different from script/check-english-links.js,
11
12
// which checks *all* links in the site, both internal and external, and is much slower.
12
13
//
14
+ // If you want to run it locally, you must have a local server running. You can use `npm run link-check`.
15
+ //
13
16
// [end-readme]
14
17
15
18
const config = {
16
- path : 'http://localhost:4002/en' ,
19
+ path : englishRoot ,
17
20
// Use concurrency = 10 to optimize for Actions
18
21
// See https://github.com/JustinBeckwith/linkinator/issues/135#issuecomment-623240879
19
22
concurrency : 10 ,
20
23
recurse : true ,
21
24
linksToSkip : [
22
- // Skip any link that is not an internal link
23
- '^((?!http://localhost:4002/en).)*$' ,
25
+ // Skip any link that is not an internal link.
26
+ // NOTE: If we want this test to check for broken asset paths in the future,
27
+ // we can remove `en` from the path below. This will increase the runtime, but that
28
+ // may be an acceptable tradeoff. For the record: `check-external-links`, which runs
29
+ // nightly, currently does check for broken asset paths.
30
+ `^((?!${ englishRoot } ).)*$` ,
24
31
// Skip dist files
25
32
'/dist/index.*' ,
26
33
// Skip deprecated Enterprise content
@@ -37,6 +44,11 @@ async function main () {
37
44
. filter ( link => link . state === 'BROKEN' )
38
45
. map ( link => { delete link . failureDetails ; return link } )
39
46
47
+ if ( brokenLinks . length === 1 && brokenLinks [ 0 ] . url === englishRoot ) {
48
+ console . log ( `You must be running ${ englishRoot } !\n\nTry instead: npm run link-check` )
49
+ process . exit ( 1 )
50
+ }
51
+
40
52
// Exit successfully if no broken links!
41
53
if ( ! brokenLinks . length ) {
42
54
console . log ( 'All links are good!' )
0 commit comments