-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathvalidate-externals-doc.js
69 lines (58 loc) · 1.5 KB
/
validate-externals-doc.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
61
62
63
64
65
66
67
68
69
const fs = require('fs')
const path = require('path')
const serverExternals = require('../packages/next/src/lib/server-external-packages.json')
function validate(docPath) {
const docContent = fs.readFileSync(
path.join(__dirname, '..', docPath),
'utf8'
)
const docPkgs = []
const extraPkgs = []
const missingPkgs = []
for (let docPkg of docContent
.split('opt-ed out:')
.pop()
.split('| Version')
.shift()
.split('\n')) {
docPkg = docPkg.split('`')[1]
if (!docPkg) {
continue
}
docPkgs.push(docPkg)
if (!serverExternals.includes(docPkg)) {
extraPkgs.push(docPkg)
}
}
for (const pkg of serverExternals) {
if (!docPkgs.includes(pkg)) {
missingPkgs.push(pkg)
}
}
if (extraPkgs.length || missingPkgs.length) {
console.log(
'server externals doc out of sync!\n' +
`Extra packages included: ` +
JSON.stringify(extraPkgs, null, 2) +
'\n' +
`Missing packages: ` +
JSON.stringify(missingPkgs, null, 2) +
'\n' +
`doc path: ${docPath}`
)
return false
}
return true
}
const appRouterValid = validate(
`docs/01-app/05-api-reference/05-config/01-next-config-js/serverExternalPackages.mdx`
)
const pagesRouterValid = validate(
`docs/02-pages/03-api-reference/04-config/01-next-config-js/serverExternalPackages.mdx`
)
if (appRouterValid && pagesRouterValid) {
console.log('server externals doc is in sync')
process.exit(0)
} else {
process.exit(1)
}