1
0
mirror of synced 2025-12-20 10:28:40 -05:00
Files
docs/script/check-internal-links.js
2021-01-22 09:28:06 -05:00

41 lines
1.0 KiB
JavaScript
Executable File

#!/usr/bin/env node
const linkinator = require('linkinator')
const checker = new linkinator.LinkChecker()
const { deprecated } = require('../lib/enterprise-server-releases')
const config = {
path: 'http://localhost:4002/en',
concurrency: 400,
recurse: true,
linksToSkip: [
// Skip any link that is not an internal link
'^((?!http://localhost:4002/en).)*$',
// Skip dist files
'/dist/index.*',
// Skip deprecated Enterprise content
`enterprise(-server@|/)(${deprecated.join('|')})/?`
]
}
main()
async function main () {
const result = (await checker.check(config)).links
const brokenLinks = result
.filter(link => link.state === 'BROKEN')
.map(link => { delete link.failureDetails; return link })
// Exit successfully if no broken links!
if (!brokenLinks.length) {
console.log('All links are good!')
process.exit(0)
}
console.log(`Found ${brokenLinks.length} total broken links: ${JSON.stringify([...brokenLinks], null, 2)}`)
// Exit unsuccessfully if broken links are found.
process.exit(1)
}