Skip to content

Commit e61ea6f

Browse files
authored
Add manifest check step and add missing items (#27934)
1 parent 94fc6f0 commit e61ea6f

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

.github/workflows/build_test_deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
with:
4242
path: ./*
4343
key: ${{ github.sha }}
44+
- run: ./scripts/check-manifests.js
4445
- run: yarn lint
4546

4647
checkPrecompiled:

errors/manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@
430430
{
431431
"title": "sharp-missing-in-production",
432432
"path": "/errors/sharp-missing-in-production.md"
433+
},
434+
{
435+
"title": "max-custom-routes-reached",
436+
"path": "/errors/max-custom-routes-reached.md"
437+
},
438+
{
439+
"title": "module-not-found",
440+
"path": "/errors/module-not-found.md"
433441
}
434442
]
435443
}

scripts/check-manifests.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const globOrig = require('glob')
6+
const { promisify } = require('util')
7+
const glob = promisify(globOrig)
8+
9+
function collectPaths(routes, paths = []) {
10+
for (const route of routes) {
11+
if (route.path) {
12+
paths.push(route.path)
13+
}
14+
15+
if (route.routes) {
16+
collectPaths(route.routes, paths)
17+
}
18+
}
19+
}
20+
21+
async function main() {
22+
const manifests = ['errors/manifest.json', 'docs/manifest.json']
23+
let hadMissing = false
24+
25+
for (const manifest of manifests) {
26+
const dir = path.dirname(manifest)
27+
const files = await glob(path.join(dir, '**/*.md'))
28+
29+
const manifestData = JSON.parse(
30+
await fs.promises.readFile(manifest, 'utf8')
31+
)
32+
33+
const paths = []
34+
collectPaths(manifestData.routes, paths)
35+
36+
const missingFiles = files.filter(
37+
(file) => !paths.includes(`/${file}`) && file !== 'errors/template.md'
38+
)
39+
40+
if (missingFiles.length) {
41+
hadMissing = true
42+
console.log(`Missing paths in ${manifest}:\n${missingFiles.join('\n')}`)
43+
} else {
44+
console.log(`No missing paths in ${manifest}`)
45+
}
46+
}
47+
48+
if (hadMissing) {
49+
throw new Error('missing manifest items detected see above')
50+
}
51+
}
52+
53+
main()
54+
.then(() => console.log('success'))
55+
.catch(console.error)

0 commit comments

Comments
 (0)