// Builds datascape, seeds a throwaway wiki and runs the server in the // foreground. Playwright's webServer starts this and kills it after the run. import { execFileSync, spawn } from "node:child_process"; import { mkdirSync, rmSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const here = dirname(fileURLToPath(import.meta.url)); const tmp = join(here, ".tmp"); const wiki = join(tmp, "wiki"); const bin = join(tmp, process.platform === "win32" ? "datascape.exe" : "datascape"); const port = process.env.E2E_PORT || "8765"; rmSync(tmp, { recursive: true, force: true }); mkdirSync(wiki, { recursive: true }); execFileSync("go", ["build", "-o", bin, "."], { cwd: join(here, ".."), stdio: "inherit" }); // Tests create their own pages (see sandbox in tests/pages.spec.js); the seed // is only the home page. writeFileSync(join(wiki, "index.md"), "# Home\n\nWelcome.\n"); const srv = spawn(bin, ["-dir", wiki, "-cache", join(tmp, "cache"), "-addr", "127.0.0.1:" + port, "-calendars", ""], { stdio: "inherit", }); srv.on("exit", (code) => process.exit(code ?? 0)); for (const sig of ["SIGINT", "SIGTERM"]) process.on(sig, () => srv.kill());