import { cp, mkdir, rm, writeFile } from 'node:fs/promises'; import { relative, resolve, sep } from 'node:path'; import { execFileSync } from 'node:child_process'; import { seoPages, websiteUrl } from '../seo.config.js'; import { mediaBaseUrl } from '../media.config.js'; // Package only the built website; local captures and application files stay private. // Videos, installers and source archives are served from Cloudflare R2 (media.config.js) and // never ship in the deploy; /downloads/* redirects to the same path on the media host. const output = resolve('.vercel/output'); const staticDirectory = resolve(output, 'static'); await rm(output, { recursive: true, force: true }); await mkdir(output, { recursive: true }); await cp(resolve('dist'), staticDirectory, { recursive: true, filter: (source) => !/\.(mp4|m4v|mov|webm)$/i.test(source) && relative(resolve('dist'), source).split(sep)[0] !== 'downloads', }); await writeFile(resolve(output, 'config.json'), JSON.stringify({ version: 3, routes: [ // Installed Creators builds and old direct downloads still use the legacy host. { src: '^(/(?!(?:appcast\\.xml|mac-release\\.json)$|downloads/|\\.well-known/).*)$', has: [{ type: 'host', value: '^(?:www\\.)?pulsecanvas\\.si$' }], status: 308, headers: { Location: `${websiteUrl}$1` }, }, { src: '^/$', dest: '/index.html' }, { src: '^/(?:donate|tips|support)(?:/index\\.html|/)?$', status: 301, headers: { Location: '/help/' } }, // Old site video URLs (search results, shared links) point at the same file in R2. { src: '^/media/(.+\\.mp4)$', status: 308, headers: { Location: `${mediaBaseUrl}/$1` } }, { src: '^/(appcast\\.xml|mac-release\\.json)$', headers: { 'Cache-Control': 'no-cache' }, continue: true }, { src: '^/downloads/(.+)$', status: 308, headers: { Location: `${mediaBaseUrl}/downloads/$1` } }, { src: '^/assets/(.*)$', headers: { 'Cache-Control': 'public, max-age=31536000, immutable' }, continue: true }, { src: '^/(images|media)/(.*)$', headers: { 'Cache-Control': 'public, max-age=86400' }, continue: true }, { src: '^/(.*)/index\\.html$', status: 308, headers: { Location: '/$1/' } }, { src: '^/index\\.html$', status: 308, headers: { Location: '/' } }, ...Object.keys(seoPages).filter(path => path !== '/').flatMap(path => [ { src: `^${path.slice(0, -1)}$`, status: 308, headers: { Location: path } }, { src: `^${path}$`, dest: `${path}index.html` }, ]), { src: '^/404\\.html$', dest: '/404.html', status: 404 }, { handle: 'filesystem' }, { src: '^/.*$', dest: '/404.html', status: 404 }, ], }, null, 2) + '\n'); // Generate the review from this exact package and fail if its assets are absent. execFileSync('python3', [resolve('scripts/create-og-review.py')], { stdio: 'inherit' }); execFileSync('python3', [resolve('scripts/check-seo.py'), staticDirectory], { stdio: 'inherit' }); console.log('Static Vercel deployment prepared in .vercel/output.');