rsnext/scripts/check-manifests.js
Delba de Oliveira f6ff2ef98e
[Next Docs] Update Git Workflow (#50579)
Update our git workflow in preparation for open-sourcing the content of
the docs ([linear
task](https://linear.app/vercel/issue/DX-1579/set-up-github-workflow)).

**Templates:**
- [x] Update docs issue template to encourage contributions
- [x] Update PR template to include link to new contribution guide 

**Code Owners / Reviewers:** 
- https://github.com/vercel/next.js/pull/50841

**Labels:** 
- [x] Add DevEx team to labeler.json so PRs get the "created by: DevEx
team"

**Other:** 
- [x] Remove docs manifest from CI checks as we no longer have one (keep
the manifest for errors as they live under `/pages`)
- [x] Add `unifiedjs.vscode-mdx` to the vscode extension list
2023-06-08 12:01:55 +02:00

66 lines
1.5 KiB
JavaScript
Executable file

#!/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 && !route.redirect) {
paths.push(route.path)
}
if (route.routes) {
collectPaths(route.routes, paths)
}
}
}
async function main() {
const manifest = 'errors/manifest.json'
let hadError = false
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) {
hadError = true
console.log(`Missing paths in ${manifest}:\n${missingFiles.join('\n')}`)
} else {
console.log(`No missing paths in ${manifest}`)
}
for (const filePath of paths) {
if (
!(await fs.promises
.access(path.join(process.cwd(), filePath), fs.constants.F_OK)
.then(() => true)
.catch(() => false))
) {
console.log('Could not find path:', filePath)
hadError = true
}
}
if (hadError) {
throw new Error('missing/incorrect manifest items detected see above')
}
}
main()
.then(() => console.log('success'))
.catch((err) => {
console.error(err)
process.exit(1)
})