|
| 1 | +/** |
| 2 | + * sync-vercel-redirects — mirror redirects.config.js into vercel.json. |
| 3 | + * |
| 4 | + * The list in redirects.config.js is the single source of truth. Vocs only |
| 5 | + * applies it in local dev (via the middleware in vocs.config.tsx), so this |
| 6 | + * script mirrors it into vercel.json so Vercel serves the redirects in |
| 7 | + * production. Vercel reads vercel.json at the start of a deployment (before the |
| 8 | + * build command runs), so the generated file is committed. |
| 9 | + * |
| 10 | + * Run with `npm run sync-redirects` (also runs on `npm run build` via prebuild). |
| 11 | + * |
| 12 | + * Patterned on OffchainLabs/arbitrum-docs (scripts/sync-vercel-redirects.ts). |
| 13 | + * That repo splices a sentinel-bounded block into a hand-maintained vercel.json |
| 14 | + * to coexist with manual entries; ZeroDev's vercel.json is fully generated, so |
| 15 | + * here we (re)write it wholesale. Written as `.mjs` because this repo has no |
| 16 | + * `tsx`; it imports the `.js` config natively. |
| 17 | + */ |
| 18 | + |
| 19 | +import { writeFile } from "node:fs/promises"; |
| 20 | +import path from "node:path"; |
| 21 | +import { fileURLToPath } from "node:url"; |
| 22 | + |
| 23 | +import { redirects } from "../redirects.config.js"; |
| 24 | + |
| 25 | +const root = path.join(path.dirname(fileURLToPath(import.meta.url)), ".."); |
| 26 | +const vercelPath = path.join(root, "vercel.json"); |
| 27 | + |
| 28 | +// permanent: false -> 307, matching the arbitrum-docs convention. Temporary |
| 29 | +// redirects aren't cached aggressively by browsers/crawlers, which keeps future |
| 30 | +// doc reorganizations easy to revert. |
| 31 | +const json = |
| 32 | + JSON.stringify( |
| 33 | + { |
| 34 | + redirects: redirects.map(({ from, to }) => ({ |
| 35 | + source: from, |
| 36 | + destination: to, |
| 37 | + permanent: false, |
| 38 | + })), |
| 39 | + }, |
| 40 | + null, |
| 41 | + 2, |
| 42 | + ) + "\n"; |
| 43 | + |
| 44 | +await writeFile(vercelPath, json); |
| 45 | +console.log(`sync-redirects: wrote ${redirects.length} redirects into vercel.json.`); |
0 commit comments