PulseCanvas / website / scripts / prepare-deploy.mjs
| 1 | import { cp, mkdir, rm, writeFile } from 'node:fs/promises'; |
| 2 | import { relative, resolve, sep } from 'node:path'; |
| 3 | import { execFileSync } from 'node:child_process'; |
| 4 | import { seoPages, websiteUrl } from '../seo.config.js'; |
| 5 | import { mediaBaseUrl } from '../media.config.js'; |
| 6 | |
| 7 | // Package only the built website; local captures and application files stay private. |
| 8 | // Videos, installers and source archives are served from Cloudflare R2 (media.config.js) and |
| 9 | // never ship in the deploy; /downloads/* redirects to the same path on the media host. |
| 10 | const output = resolve('.vercel/output'); |
| 11 | const staticDirectory = resolve(output, 'static'); |
| 12 | await rm(output, { recursive: true, force: true }); |
| 13 | await mkdir(output, { recursive: true }); |
| 14 | await cp(resolve('dist'), staticDirectory, { |
| 15 | recursive: true, |
| 16 | filter: (source) => !/\.(mp4|m4v|mov|webm)$/i.test(source) |
| 17 | && relative(resolve('dist'), source).split(sep)[0] !== 'downloads', |
| 18 | }); |
| 19 | await writeFile(resolve(output, 'config.json'), JSON.stringify({ |
| 20 | version: 3, |
| 21 | routes: [ |
| 22 | // Installed Creators builds and old direct downloads still use the legacy host. |
| 23 | { |
| 24 | src: '^(/(?!(?:appcast\\.xml|mac-release\\.json)$|downloads/|\\.well-known/).*)$', |
| 25 | has: [{ type: 'host', value: '^(?:www\\.)?pulsecanvas\\.si$' }], |
| 26 | status: 308, |
| 27 | headers: { Location: `${websiteUrl}$1` }, |
| 28 | }, |
| 29 | { src: '^/$', dest: '/index.html' }, |
| 30 | { src: '^/(?:donate|tips|support)(?:/index\\.html|/)?$', status: 301, headers: { Location: '/help/' } }, |
| 31 | // Old site video URLs (search results, shared links) point at the same file in R2. |
| 32 | { src: '^/media/(.+\\.mp4)$', status: 308, headers: { Location: `${mediaBaseUrl}/$1` } }, |
| 33 | { src: '^/(appcast\\.xml|mac-release\\.json)$', headers: { 'Cache-Control': 'no-cache' }, continue: true }, |
| 34 | { src: '^/downloads/(.+)$', status: 308, headers: { Location: `${mediaBaseUrl}/downloads/$1` } }, |
| 35 | { src: '^/assets/(.*)$', headers: { 'Cache-Control': 'public, max-age=31536000, immutable' }, continue: true }, |
| 36 | { src: '^/(images|media)/(.*)$', headers: { 'Cache-Control': 'public, max-age=86400' }, continue: true }, |
| 37 | { src: '^/(.*)/index\\.html$', status: 308, headers: { Location: '/$1/' } }, |
| 38 | { src: '^/index\\.html$', status: 308, headers: { Location: '/' } }, |
| 39 | ...Object.keys(seoPages).filter(path => path !== '/').flatMap(path => [ |
| 40 | { src: `^${path.slice(0, -1)}$`, status: 308, headers: { Location: path } }, |
| 41 | { src: `^${path}$`, dest: `${path}index.html` }, |
| 42 | ]), |
| 43 | { src: '^/404\\.html$', dest: '/404.html', status: 404 }, |
| 44 | { handle: 'filesystem' }, |
| 45 | { src: '^/.*$', dest: '/404.html', status: 404 }, |
| 46 | ], |
| 47 | }, null, 2) + '\n'); |
| 48 | // Generate the review from this exact package and fail if its assets are absent. |
| 49 | execFileSync('python3', [resolve('scripts/create-og-review.py')], { stdio: 'inherit' }); |
| 50 | execFileSync('python3', [resolve('scripts/check-seo.py'), staticDirectory], { stdio: 'inherit' }); |
| 51 | console.log('Static Vercel deployment prepared in .vercel/output.'); |