Skip to content

Commit

Permalink
Add manifest check step and add missing items (#27934)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Aug 11, 2021
1 parent 94fc6f0 commit e61ea6f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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)

0 comments on commit e61ea6f

Please # to comment.