37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
// 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" });
|
|
|
|
const pages = {
|
|
"index.md": "# Home\n\nWelcome.\n",
|
|
"Projects/index.md": "# Projects\n\n## Todo\n\n- [ ] first task\n- [x] second task\n",
|
|
"Projects/Alpha/index.md": "# Alpha\n\nAlpha page.\n",
|
|
"Projects/Beta/index.md": "# Beta\n\nBeta page.\n",
|
|
"Notes/index.md": "# Notes\n\nSome notes.\n",
|
|
};
|
|
for (const [p, body] of Object.entries(pages)) {
|
|
mkdirSync(dirname(join(wiki, p)), { recursive: true });
|
|
writeFileSync(join(wiki, p), body);
|
|
}
|
|
writeFileSync(join(wiki, "Projects", "readme.txt"), "a file\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());
|