import { cp, mkdir, rm, stat, writeFile } from 'node:fs/promises'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..'); const distDir = join(rootDir, 'dist'); await rm(distDir, { force: true, recursive: true }); await mkdir(distDir, { recursive: true }); await copyRequired('index.html'); await copyRequired('poster.jpg'); await copyRequired('test-pages'); await copyRequired('vr180player'); await copyOptional('media'); await writeFile( join(distDir, '_headers'), [ '/vr180player/*', ' Cache-Control: public, max-age=3600', '', '/*', ' Cache-Control: public, max-age=300', '' ].join('\n') ); console.log(`Built test app in ${distDir}`); async function copyRequired(relativePath) { const source = join(rootDir, relativePath); const target = join(distDir, relativePath); await cp(source, target, { recursive: true }); } async function copyOptional(relativePath) { const source = join(rootDir, relativePath); if (!await pathExists(source)) { console.warn(`Optional ${relativePath}/ directory not found; bundled sample media will not be included.`); return; } await cp(source, join(distDir, relativePath), { recursive: true }); } async function pathExists(path) { try { await stat(path); return true; } catch (error) { if (error?.code === 'ENOENT') { return false; } throw error; } }