From 021ddb69dae85c6a47c6712375d79332c80522ad Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 11 Aug 2021 04:17:57 -0500 Subject: [PATCH] Add manifest check step and add missing items (#27934) --- .github/workflows/build_test_deploy.yml | 1 + errors/manifest.json | 8 ++++ scripts/check-manifests.js | 55 +++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100755 scripts/check-manifests.js diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 5f633e11c0104..e68400734eab8 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -41,6 +41,7 @@ jobs: with: path: ./* key: ${{ github.sha }} + - run: ./scripts/check-manifests.js - run: yarn lint checkPrecompiled: diff --git a/errors/manifest.json b/errors/manifest.json index 09bc27b3a8e7e..4d42da82bef73 100644 --- a/errors/manifest.json +++ b/errors/manifest.json @@ -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" } ] } diff --git a/scripts/check-manifests.js b/scripts/check-manifests.js new file mode 100755 index 0000000000000..7531c2efb7840 --- /dev/null +++ b/scripts/check-manifests.js @@ -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)