Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manifest check step and add missing items #27934

Merged
merged 3 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
with:
path: ./*
key: ${{ github.sha }}
- run: ./scripts/check-manifests.js
- run: yarn lint

checkPrecompiled:
Expand Down
8 changes: 8 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@
{
"title": "sharp-missing-in-production",
"path": "/errors/sharp-missing-in-production.md"
},
{
"title": "max-custom-routes-reached",
"path": "/errors/max-custom-routes-reached.md"
},
{
"title": "module-not-found",
"path": "/errors/module-not-found.md"
}
]
}
Expand Down
55 changes: 55 additions & 0 deletions scripts/check-manifests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const globOrig = require('glob')
const { promisify } = require('util')
const glob = promisify(globOrig)

function collectPaths(routes, paths = []) {
for (const route of routes) {
if (route.path) {
paths.push(route.path)
}

if (route.routes) {
collectPaths(route.routes, paths)
}
}
}

async function main() {
const manifests = ['errors/manifest.json', 'docs/manifest.json']
let hadMissing = false

for (const manifest of manifests) {
const dir = path.dirname(manifest)
const files = await glob(path.join(dir, '**/*.md'))

const manifestData = JSON.parse(
await fs.promises.readFile(manifest, 'utf8')
)

const paths = []
collectPaths(manifestData.routes, paths)

const missingFiles = files.filter(
(file) => !paths.includes(`/${file}`) && file !== 'errors/template.md'
)

if (missingFiles.length) {
hadMissing = true
console.log(`Missing paths in ${manifest}:\n${missingFiles.join('\n')}`)
} else {
console.log(`No missing paths in ${manifest}`)
}
}

if (hadMissing) {
throw new Error('missing manifest items detected see above')
}
}

main()
.then(() => console.log('success'))
.catch(console.error)