about summary refs log tree commit diff stats
path: root/bin/build.ts
blob: 69cfd6c62bd76a6947702cc2f83ec378fb128f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bun
import fs from "node:fs";
import log from "loglevel";

import generateSite from "../src/templates";

log.setLevel((import.meta.env["LOG_LEVEL"] || "info") as log.LogLevelDesc);

fs.mkdirSync("public", { recursive: true });
log.info("Generating site...");
try {
  await generateSite();
} catch (error) {
  log.error("Error generating site", error);
  process.exit(1);
}

log.info("Copying static files...");
if (!fs.existsSync("static")) {
  log.error("static directory not found");
  process.exit(1);
}
fs.readdirSync("static").map((file) => {
  log.debug(`Copying static/${file}`);
  fs.cpSync(`static/${file}`, `public/${file}`, {
    dereference: true,
    recursive: true,
    preserveTimestamps: true,
  });
});