From 768e53e23ab1e46e188da6c1b67d621308cd43ef Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:09:14 +0200 Subject: [PATCH 1/8] Bun build process --- build.ts | 35 +++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 build.ts diff --git a/build.ts b/build.ts new file mode 100644 index 000000000..f444002ed --- /dev/null +++ b/build.ts @@ -0,0 +1,35 @@ +import { watch } from "node:fs"; +import { cp } from "node:fs/promises"; +import path from "node:path"; + +const distDir = "./dist"; + +const runBuild = async () => { + return await Bun.build({ + entrypoints: ["./src/cli/index.ts"], + outdir: distDir, + target: "node", + format: "esm", + sourcemap: "inline", + }); +} + +await cp("./templates", path.join(distDir, "templates"), { recursive: true }); + +if (process.argv.includes("--watch")) { + console.log("\nWatching for changes..."); + + for (const dir of ["./src"]) { + watch(dir, { recursive: true }, async (event, filename) => { + const cliBuild = await runBuild(); + console.log(cliBuild.outputs.map((o) => o.path).join(", ")); + }); + } + + // Keep process alive + await new Promise(() => {}); +} else { + const cliBuild = await runBuild(); + console.log("✓ Build complete"); + console.log(cliBuild.outputs.map((o) => o.path).join(", ")); +} diff --git a/package.json b/package.json index 13b3a794f..64cb5fd4d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "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": "rm -rf dist && bun run build.ts", + "build:watch": "rm -rf dist && bun run build.ts --watch", "typecheck": "tsc --noEmit", "dev": "./bin/dev.ts", "start": "./bin/run.js", From 3ea4aec07ecc07a94c441fe3bbbb783106f808e7 Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:35:28 +0200 Subject: [PATCH 2/8] refactored --- build.ts | 35 ----------------------------------- infra/build.ts | 38 ++++++++++++++++++++++++++++++++++++++ package.json | 6 +++--- 3 files changed, 41 insertions(+), 38 deletions(-) delete mode 100644 build.ts create mode 100644 infra/build.ts diff --git a/build.ts b/build.ts deleted file mode 100644 index f444002ed..000000000 --- a/build.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { watch } from "node:fs"; -import { cp } from "node:fs/promises"; -import path from "node:path"; - -const distDir = "./dist"; - -const runBuild = async () => { - return await Bun.build({ - entrypoints: ["./src/cli/index.ts"], - outdir: distDir, - target: "node", - format: "esm", - sourcemap: "inline", - }); -} - -await cp("./templates", path.join(distDir, "templates"), { recursive: true }); - -if (process.argv.includes("--watch")) { - console.log("\nWatching for changes..."); - - for (const dir of ["./src"]) { - watch(dir, { recursive: true }, async (event, filename) => { - const cliBuild = await runBuild(); - console.log(cliBuild.outputs.map((o) => o.path).join(", ")); - }); - } - - // Keep process alive - await new Promise(() => {}); -} else { - const cliBuild = await runBuild(); - console.log("✓ Build complete"); - console.log(cliBuild.outputs.map((o) => o.path).join(", ")); -} diff --git a/infra/build.ts b/infra/build.ts new file mode 100644 index 000000000..aa49ce4c2 --- /dev/null +++ b/infra/build.ts @@ -0,0 +1,38 @@ +import { watch } from "node:fs"; + +const runBuild = async () => { + const result = await Bun.build({ + entrypoints: ["./src/cli/index.ts"], + outdir: "./dist/cli", + target: "node", + format: "esm", + sourcemap: "inline", + }); + if (!result.success) { + console.error("Build failed:"); + for (const log of result.logs) { + console.error(log); + } + process.exit(1); + } + return result; +} + +if (process.argv.includes("--watch")) { + console.log("\nWatching for changes..."); + const changeHandler = async (event: "rename" | "change", filename: string | null) => { + const cliBuild = await runBuild(); + console.log(cliBuild.outputs.map((o) => o.path).join(", ")); + } + + for (const dir of ["./src"]) { + watch(dir, { recursive: true }, changeHandler); + } + + // Keep process alive + await new Promise(() => {}); +} else { + const cliBuild = await runBuild(); + console.log("✓ Build complete"); + console.log(cliBuild.outputs.map((o) => o.path).join(", ")); +} diff --git a/package.json b/package.json index 64cb5fd4d..6b5703ecf 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "bin" ], "scripts": { - "build": "rm -rf dist && bun run build.ts", - "build:watch": "rm -rf dist && bun run build.ts --watch", + "build": "npm run clean && cp -r templates dist/ && bun run infra/build.ts", + "build:watch": "npm 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", "lint": "biome check src tests", "lint:fix": "biome check --write src tests", "test": "vitest run", From a9b3e5e4cc92caebd4b522ed33f19de68e64dc7a Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:39:04 +0200 Subject: [PATCH 3/8] added colors --- bin/run.js | 2 +- infra/build.ts | 46 +++++++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/bin/run.js b/bin/run.js index daa3a38de..8fd0e4b23 100755 --- a/bin/run.js +++ b/bin/run.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { runCLI } from "../dist/index.js"; +import { runCLI } from "../dist/cli/index.js"; // Disable Clack spinners and animations in non-interactive environments. // Clack only checks the CI env var, so we set it when stdin/stdout aren't TTYs. diff --git a/infra/build.ts b/infra/build.ts index aa49ce4c2..d655c7cca 100644 --- a/infra/build.ts +++ b/infra/build.ts @@ -1,6 +1,8 @@ import { watch } from "node:fs"; +import chalk from "chalk"; const runBuild = async () => { + const start = performance.now(); const result = await Bun.build({ entrypoints: ["./src/cli/index.ts"], outdir: "./dist/cli", @@ -8,31 +10,49 @@ const runBuild = async () => { format: "esm", sourcemap: "inline", }); + const duration = (performance.now() - start).toFixed(0); + if (!result.success) { - console.error("Build failed:"); + console.error(chalk.red.bold("\n✗ Build failed\n")); for (const log of result.logs) { - console.error(log); + console.error(chalk.red(` ${log}`)); } process.exit(1); } - return result; -} + + return { result, duration }; +}; + +const formatOutput = (outputs: { path: string }[]) => { + return outputs.map((o) => chalk.cyan(o.path)).join("\n "); +}; if (process.argv.includes("--watch")) { - console.log("\nWatching for changes..."); + console.log(chalk.yellow("Watching for changes...")); + const changeHandler = async (event: "rename" | "change", filename: string | null) => { - const cliBuild = await runBuild(); - console.log(cliBuild.outputs.map((o) => o.path).join(", ")); - } - + const time = new Date().toLocaleTimeString(); + console.log(chalk.dim(`[${time}]`), chalk.gray(`${filename} ${event}d`)); + + const { result, duration } = await runBuild(); + console.log( + chalk.green(` ✓ Rebuilt in ${chalk.bold(duration + "ms")}`), + chalk.dim(`→`), + chalk.cyan(result.outputs[0]?.path ?? "") + ); + }; + + await runBuild(); + for (const dir of ["./src"]) { watch(dir, { recursive: true }, changeHandler); } - + // Keep process alive await new Promise(() => {}); } else { - const cliBuild = await runBuild(); - console.log("✓ Build complete"); - console.log(cliBuild.outputs.map((o) => o.path).join(", ")); + const { result, duration } = await runBuild(); + console.log(chalk.green.bold(`\n✓ Build complete`), chalk.dim(`in ${duration}ms\n`)); + console.log(chalk.dim(" Output:")); + console.log(` ${formatOutput(result.outputs)}\n`); } From bf4c104e8d4cfdd6f183bce4b9e3e7748f702744 Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:40:41 +0200 Subject: [PATCH 4/8] upd --- infra/build.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/infra/build.ts b/infra/build.ts index d655c7cca..7530134e6 100644 --- a/infra/build.ts +++ b/infra/build.ts @@ -2,7 +2,6 @@ import { watch } from "node:fs"; import chalk from "chalk"; const runBuild = async () => { - const start = performance.now(); const result = await Bun.build({ entrypoints: ["./src/cli/index.ts"], outdir: "./dist/cli", @@ -10,7 +9,6 @@ const runBuild = async () => { format: "esm", sourcemap: "inline", }); - const duration = (performance.now() - start).toFixed(0); if (!result.success) { console.error(chalk.red.bold("\n✗ Build failed\n")); @@ -20,7 +18,7 @@ const runBuild = async () => { process.exit(1); } - return { result, duration }; + return result; }; const formatOutput = (outputs: { path: string }[]) => { @@ -34,9 +32,9 @@ if (process.argv.includes("--watch")) { const time = new Date().toLocaleTimeString(); console.log(chalk.dim(`[${time}]`), chalk.gray(`${filename} ${event}d`)); - const { result, duration } = await runBuild(); + const result = await runBuild(); console.log( - chalk.green(` ✓ Rebuilt in ${chalk.bold(duration + "ms")}`), + chalk.green(` ✓ Rebuilt`), chalk.dim(`→`), chalk.cyan(result.outputs[0]?.path ?? "") ); @@ -51,8 +49,8 @@ if (process.argv.includes("--watch")) { // Keep process alive await new Promise(() => {}); } else { - const { result, duration } = await runBuild(); - console.log(chalk.green.bold(`\n✓ Build complete`), chalk.dim(`in ${duration}ms\n`)); + const result = await runBuild(); + console.log(chalk.green.bold(`\n✓ Build complete\n`)); console.log(chalk.dim(" Output:")); console.log(` ${formatOutput(result.outputs)}\n`); } From f7ba5a0ba7eac49ff58537e76801e10f1f8e0c19 Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:46:05 +0200 Subject: [PATCH 5/8] fixed templates --- src/core/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/config.ts b/src/core/config.ts index 2f7b7c10b..7ec86e197 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -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/ 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"); } export function getTemplatesIndexPath(): string { From 89c411ad17add6dfb266ec8ae698229ecc0f9896 Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:51:02 +0200 Subject: [PATCH 6/8] fixed tests --- tests/cli/testkit/CLITestkit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/testkit/CLITestkit.ts b/tests/cli/testkit/CLITestkit.ts index 81f041745..d32c8357d 100644 --- a/tests/cli/testkit/CLITestkit.ts +++ b/tests/cli/testkit/CLITestkit.ts @@ -9,7 +9,7 @@ import type { CLIResult } from "./CLIResultMatcher.js"; import { CLIResultMatcher } from "./CLIResultMatcher.js"; const __dirname = dirname(fileURLToPath(import.meta.url)); -const DIST_INDEX_PATH = join(__dirname, "../../../dist/index.js"); +const DIST_INDEX_PATH = join(__dirname, "../../../dist/cli/index.js"); /** Type for CLIContext */ interface CLIContext { From b35160b9e05eec93c3873f528fe276d2eeaeda12 Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 11:58:47 +0200 Subject: [PATCH 7/8] fix --- infra/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/build.ts b/infra/build.ts index 7530134e6..0d9e3d459 100644 --- a/infra/build.ts +++ b/infra/build.ts @@ -36,7 +36,7 @@ if (process.argv.includes("--watch")) { console.log( chalk.green(` ✓ Rebuilt`), chalk.dim(`→`), - chalk.cyan(result.outputs[0]?.path ?? "") + formatOutput(result.outputs) ); }; From b24b73929dd6d3e4964e7966d7d8c6ebe929aa81 Mon Sep 17 00:00:00 2001 From: Artem Demochko Date: Thu, 5 Feb 2026 12:37:16 +0200 Subject: [PATCH 8/8] upd --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6b5703ecf..7fc0b3588 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "bin" ], "scripts": { - "build": "npm run clean && cp -r templates dist/ && bun run infra/build.ts", - "build:watch": "npm run clean && cp -r templates dist/ && bun run infra/build.ts --watch", + "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",