Refactor build process to use NOWATCH constant for conditional logic

This commit is contained in:
Seth 2025-01-17 18:34:34 -05:00
parent 770b1e9f06
commit 5b0716930f
No known key found for this signature in database
GPG key ID: 8B7A2C60CDF65CAC

View file

@ -6,6 +6,8 @@ import { join } from "node:path";
const glob = new Glob("**/*");
const NOWATCH = process.env.NOWATCH === "1";
const build = async () => {
const start = Date.now();
const built = await Bun.build({
@ -15,10 +17,10 @@ const build = async () => {
experimentalCss: true,
splitting: true,
sourcemap: "linked",
...(process.env.NOWATCH === "1" ? {minify: true} : {})
...(NOWATCH ? {minify: true} : {})
});
const end = Date.now();
//await cleanOldFiles(built.outputs);
if (NOWATCH) await cleanOldFiles(built.outputs);
console.log("Did build", built.success, built.logs);
console.log("Build time:", end - start, "ms");
};
@ -41,7 +43,7 @@ const cleanOldFiles = async (outputs: BuildArtifact[]) => {
);
};
if (process.env.NOWATCH !== "1") {
if (!NOWATCH) {
watch(import.meta.dir, { recursive: true }, async (_, file) => {
if (!file?.startsWith("dist")) return await build();
return;