-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,6 @@ out | |
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |