teleop / scripts /prepare-space.mjs
ebubar's picture
fix: serve prebuilt static app without paid build jobs
5699984
Raw History Blame Contribute Delete
851 Bytes
// Ship verified local output as plain static files: no paid HF build step.
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
import { resolve, dirname, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const output = resolve(root, 'site');
if (output !== resolve(root, 'site') || !output.startsWith(root + sep)) throw new Error('Unexpected output path');
if (!existsSync(resolve(root, 'dist/index.html'))) throw new Error('Build dist/index.html first');
mkdirSync(output, {recursive: true});
for (const entry of readdirSync(output)) rmSync(resolve(output, entry), {recursive: true, force: true});
cpSync(resolve(root, 'dist'), output, {recursive: true});
console.log('Prepared site/ for static publication. Commit it with the source.');