AkurAI Build
Menu

Public repository / 3af23b0e937520000e1aa43c7e2eb9de2675abd1

AkurAI-Mail / scripts/build.ts

Latest change 3af23b0e937520000e1aa43c7e2eb9de2675abd1 - OLI-248: webmail list and reader as framework islands on a signals store by Ólafur Búi Ólafsson

// scripts/build.ts — assemble the no-build-step site into build/ (served by akurai-mail-api as AKURAI_STATIC_DIR).
//
//   bun scripts/build.ts [outDir]
//
// Copies app/ (HTML, CSS), the framework modules and the pure webmail modules (no tests) and
// static/ (icons, theme.js, monitor-client.js) into one directory. Nothing is transformed:
// the browser loads the same ES modules that `bun test` exercises.
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
import { join } from "node:path";

const OUT = process.argv[2] ?? "build";
const SKIP = /\.test\.(js|ts)$|\.d\.ts$/;

function copyTree(from: string, to: string) {
  mkdirSync(to, { recursive: true });
  for (const name of readdirSync(from)) {
    const src = join(from, name);
    if (statSync(src).isDirectory()) copyTree(src, join(to, name));
    else if (!SKIP.test(name)) cpSync(src, join(to, name));
  }
}

if (existsSync(OUT)) rmSync(OUT, { recursive: true });
copyTree("app", OUT);
copyTree("static", OUT);
copyTree("src/framework", join(OUT, "src/framework"));
copyTree("src/lib/webmail", join(OUT, "src/lib/webmail"));
const head = Bun.spawnSync(["git", "rev-parse", "HEAD"]).stdout.toString().trim();
await Bun.write(join(OUT, "deployed-head.txt"), `${head}\n`);
console.log(`built ${OUT} at ${head.slice(0, 7)}`);