This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manifest check step and add missing items (vercel#27934)
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |