From 23342e37524f733fa9a3969956911f9dac6d018f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Sun, 24 Mar 2024 20:59:43 +0100 Subject: [PATCH] chore: add dev & comp scripts --- .gitignore | 1 - bun.lockb | Bin 11630 -> 11993 bytes package.json | 6 ++--- scripts/build.ts | 65 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/dev.ts | 22 ++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 scripts/build.ts create mode 100644 scripts/dev.ts diff --git a/.gitignore b/.gitignore index 9b1ee42..2c8942c 100644 --- a/.gitignore +++ b/.gitignore @@ -118,7 +118,6 @@ out # Nuxt.js build / generate output .nuxt -dist # Gatsby files diff --git a/bun.lockb b/bun.lockb index c4022d8dc401777afd622fa523896f16663dc73e..cbb78ffd00bb6074966d55ac2cddce16281b0f81 100755 GIT binary patch delta 3486 zcmb_fc{r478-L$1mL|r|*oGO5u{4$m2ibDSa0y z$4SdMMdpiRC*n5RQ;RB0-uRB8sDt+0iM%-hv3S z0zneWxmXNwCG@F62qFrR=j*`EMCfM;BZvyb7>G&`{UDMcx&!out)Un$?Qn@=-xNj41#-a9W^4fP@NjED1c%a_3u_e5-?RNeJ@W@vTh0 z)xozUgha(mU>@kw>=6QIluVq6WB{D0#a9f4$DnoKjF2@t3VNVs00m)d$-Qtj%wby@ z7zM5lLguxVtbq(K3N#TMpQ(m3-^z{upA10+K{kGq*#Q~1Z!(pTarq`Q0~wERGR|;g z*MF1Afy}qZ8G+1ykE06?5{m7y6@)vDz~K-z_+X;O(f3jcy-^fgTe%r( zq9~>VIr^sP=B+SS6j>Bsga~(;FL<5W{=N^nB8_wJnoE=PR^*HQVzO5l7Zh$9bK2vm zuhKmA;c-jJOBanjMW*Kuhs|PoV9e<#gK5@a+cM!gI9anjQ*a<_;bfJq&|{rkLI#D zW1j~q;=bhSm55ac7Mm3n@366$d!=*0u5_wV_6`cjM0r+0Y4o^H>Ymyp`>gDZt4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e(%15wN4XfEqeMe{^hIFf*1(xh%w(4%`@~;5yw9)d3xJ1{k5+ z(XiLohmM6J$Q@~b^y`n^pHsnl#(Y%`sHww0hMJ(3!JtWxlI-rcFa^U53#^KNoa8{9-YRW!F2>{P4pZw|6=IJYP^M+sx-Hb&H6Gw z^n}SqvWS8EI#1Me%SV=)=s95{GiCmqm#rHTluFtsM#}5Xos#h8eHt%Kad1vM?(|s* zauSTedFAz}@b*#O$xW>hI5cq<*O5ET4v|-=0^5KLi;J#KI25Z@+UlBh~S>-R6Z6YFKq|E*>4_TD&Z!A za3`&2C6!M4xR5?HXTW!erFOQtm`Y;;Se%tp5) zf@n(RLHx6f#t_k6uC8p_ I0_~&!1@ndz7XSbN diff --git a/package.json b/package.json index f6c28f8..09e363b 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ }, "scripts": { "start": "NODE_ENV=production bun ./src/index.tsx", - "dev": "bun ./src/index.tsx", - "build": "bun build --target=bun ./src/index.ts --outdir ./build", + "dev": "bun ./scripts/dev.ts", + "comp": "bun ./scripts/build.ts", "format": "biome format . --changed", "format:fix": "biome format . --write --changed", "typecheck": "tsc", @@ -39,6 +39,6 @@ }, "type": "module", "bin": { - "conmmit": "./src/index.tsx" + "conmmit": "./dist/conmmit.js" } } diff --git a/scripts/build.ts b/scripts/build.ts new file mode 100644 index 0000000..4750ab6 --- /dev/null +++ b/scripts/build.ts @@ -0,0 +1,65 @@ +import { $, file } from "bun" +import c from "picocolors" + +const ENTRYPOINT = "./src/index.tsx" +const OUTDIR = "./dist" +const COMP_OUTFILE = `${OUTDIR}/conmmit` +const BUILD_OUTFILE = `${OUTDIR}/conmmit.js` +const SHOULD_COMPILE = false // not sure if shipping binaries tbh... + +const build = await $`bun build --target=bun --minify ${ENTRYPOINT} --outfile ${BUILD_OUTFILE}`.quiet() + +if (SHOULD_COMPILE) { + const comp = await $`bun build --compile --minify --sourcemap ${ENTRYPOINT} --outfile ${COMP_OUTFILE}`.quiet() + if (comp.exitCode === 0) { + const stdout = formatStdout(comp.stdout) + const size = fileSize(COMP_OUTFILE, "mb") + + console.log(` + ${c.bold("--- Compilation ---")} + + ${stdout} + + File size: ${size} MB + `) + } else { + console.error(` + Compilation error: + + ${comp.stderr.toString()} + `) + } +} + +if (build.exitCode === 0) { + const stdout = c.dim(build.stdout.toString().trim()) + const size = fileSize(BUILD_OUTFILE, "kb") + + console.log(` + ${c.bold("--- Build ---")} + + ${stdout} + + File size: ${size} KB + `) +} else { + console.error(` + Build error: + + ${build.stderr.toString()} + `) +} + +function bytesTo(bytes: number, to: "mb" | "kb") { + const base = 1024 + if (to === "mb") return (bytes / base ** 2).toFixed(2) + return (bytes / base).toFixed(2) +} + +function formatStdout(stdout: Buffer) { + return c.italic(c.dim(stdout.toString().trim())) +} + +function fileSize(path: string, unit: "mb" | "kb") { + return bytesTo(file(path).size, unit) +} diff --git a/scripts/dev.ts b/scripts/dev.ts new file mode 100644 index 0000000..cb7a403 --- /dev/null +++ b/scripts/dev.ts @@ -0,0 +1,22 @@ +import { watch } from "node:fs/promises" +import path from "node:path" +import { $ } from "bun" + +const WATCH_DIR = path.join(__dirname, "../src") + +const watcher = watch(WATCH_DIR, { recursive: true }) +console.log(`Watching ${WATCH_DIR}`) + +for await (const event of watcher) { + console.log(`Detected ${event.eventType} in ${event.filename}`) + + const compp = await $`bun comp`.quiet() + + if (compp.exitCode === 0) + console.log("Compiled") +} + +process.on("SIGINT", () => { + console.log("Closing watcher...") + process.exit(0) +})