Menu
Public repository / 054e5cda0171bd13facff3c16a38f2048a1052cc
AkurAI-Mail / scripts/build.ts
Latest change 054e5cda0171bd13facff3c16a38f2048a1052cc - OLI-249: compose, settings, admin console and sign-in on the framework; SvelteKit removed 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"));
// The API's mailbox logout lands on /webmail/login: same sign-in page.
mkdirSync(join(OUT, "webmail/login"), { recursive: true });
cpSync(join(OUT, "login/index.html"), join(OUT, "webmail/login/index.html"));
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)}`);