-
Notifications
You must be signed in to change notification settings - Fork 26
Bun build with watch #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bun build with watch #198
Changes from all commits
768e53e
3ea4aec
a9b3e5e
bf4c104
f7ba5a0
89c411a
b35160b
b24b739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { watch } from "node:fs"; | ||
| import chalk from "chalk"; | ||
|
|
||
| const runBuild = async () => { | ||
| const result = await Bun.build({ | ||
| entrypoints: ["./src/cli/index.ts"], | ||
| outdir: "./dist/cli", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving pure |
||
| target: "node", | ||
| format: "esm", | ||
| sourcemap: "inline", | ||
| }); | ||
|
|
||
| if (!result.success) { | ||
| console.error(chalk.red.bold("\n✗ Build failed\n")); | ||
| for (const log of result.logs) { | ||
| console.error(chalk.red(` ${log}`)); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| const formatOutput = (outputs: { path: string }[]) => { | ||
| return outputs.map((o) => chalk.cyan(o.path)).join("\n "); | ||
| }; | ||
|
|
||
| if (process.argv.includes("--watch")) { | ||
| console.log(chalk.yellow("Watching for changes...")); | ||
|
|
||
| const changeHandler = async (event: "rename" | "change", filename: string | null) => { | ||
| const time = new Date().toLocaleTimeString(); | ||
| console.log(chalk.dim(`[${time}]`), chalk.gray(`${filename} ${event}d`)); | ||
|
|
||
| const result = await runBuild(); | ||
| console.log( | ||
| chalk.green(` ✓ Rebuilt`), | ||
| chalk.dim(`→`), | ||
| formatOutput(result.outputs) | ||
| ); | ||
| }; | ||
|
|
||
| await runBuild(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch mode should start with fully building the code, otherwise it will wait for the first change to happen. |
||
|
|
||
| for (const dir of ["./src"]) { | ||
| watch(dir, { recursive: true }, changeHandler); | ||
| } | ||
|
|
||
| // Keep process alive | ||
| await new Promise(() => {}); | ||
| } else { | ||
| const result = await runBuild(); | ||
| console.log(chalk.green.bold(`\n✓ Build complete\n`)); | ||
| console.log(chalk.dim(" Output:")); | ||
| console.log(` ${formatOutput(result.outputs)}\n`); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,12 @@ | |
| "bin" | ||
| ], | ||
| "scripts": { | ||
| "build": "rm -rf dist && bun build src/cli/index.ts --outdir dist --target node --format esm --sourcemap=inline && cp -r templates dist/", | ||
| "build": "bun run clean && cp -r templates dist/ && bun run infra/build.ts", | ||
| "build:watch": "bun run clean && cp -r templates dist/ && bun run infra/build.ts --watch", | ||
| "typecheck": "tsc --noEmit", | ||
| "dev": "./bin/dev.ts", | ||
| "start": "./bin/run.js", | ||
| "clean": "rm -rf dist", | ||
| "clean": "rm -rf dist && mkdir -p dist", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recreating |
||
| "lint": "biome check src tests", | ||
| "lint:fix": "biome check --write src tests", | ||
| "test": "vitest run", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import { | |
| } from "@/core/project/schema.js"; | ||
|
|
||
| // After bundling, import.meta.url points to dist/cli/index.js | ||
| // Templates are copied to dist/cli/templates/ | ||
| // Templates are copied to dist/templates/ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment was originally incorrect. templates were always in
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice one |
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| export function getBase44GlobalDir(): string { | ||
|
|
@@ -20,7 +20,7 @@ export function getAuthFilePath(): string { | |
| } | ||
|
|
||
| export function getTemplatesDir(): string { | ||
| return join(__dirname, "templates"); | ||
| return join(__dirname, "../templates"); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we just need to make sure it's working fine in dev + in dist
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when you say |
||
| } | ||
|
|
||
| export function getTemplatesIndexPath(): string { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments about output changes below