Skip to content
Source
Sign inSign up
samwillis/hackernews-realtime
Open History to see the last commit

clean-build.mjs

52 lines1.3 KB

1import { cp, mkdir, readFile, writeFile } from "node:fs/promises";
2import { execFileSync } from "node:child_process";
3import { resolve } from "node:path";
4const root = resolve(import.meta.dirname, "..");
5const directory = resolve(root, `.local/clean-build-${Date.now()}`);
6await mkdir(directory, { recursive: true });
7const paths = [
8 "app",
9 "lib",
10 "ingest",
11 "functions",
12 "scripts",
13 "migrations",
14 "tests",
15 "package.json",
16 "package-lock.json",
17 "neon-toolchain.lock.json",
18 "tsconfig.json",
19 "next.config.ts",
20 "next-env.d.ts",
21 "neon.ts",
22 ".gitignore",
23 ".vercelignore",
24];
25for (const path of paths)
26 await cp(resolve(root, path), resolve(directory, path), { recursive: true });
27const run = (cmd, args) =>
28 execFileSync(cmd, args, {
29 cwd: directory,
30 stdio: "inherit",
31 env: process.env,
32 });
33run("node", ["scripts/bootstrap.mjs"]);
34run("npm", ["ci"]);
35run("npm", ["run", "typecheck"]);
36run("npm", ["test"]);
37// The production fixture guard and dynamic SSR allow building without secrets.
38run("npm", ["run", "build"]);
39await writeFile(
40 resolve(root, ".local/clean-build-result.json"),
41 JSON.stringify(
42 {
43 directory,
44 passedAt: new Date().toISOString(),
45 commit: JSON.parse(
46 await readFile(resolve(root, "neon-toolchain.lock.json"), "utf8"),
47 ).commit,
48 },
49 null,
50 2,
51 ),
52);