diff --git a/build.bun.ts b/build.bun.ts new file mode 100644 index 0000000..b537346 --- /dev/null +++ b/build.bun.ts @@ -0,0 +1,27 @@ +#!/usr/bin/env bun +import { $ } from "bun"; + +// Run TypeScript compiler for type declarations +await $`tsc`; + +const isDevelopment = Bun.env.NODE_ENV === "development"; + +// Build all JavaScript/TypeScript files +function buildJs(entrypoint: string, opts: Record = {}) { + return Bun.build({ + entrypoints: [entrypoint], + outdir: "dist", + target: "browser", + minify: !isDevelopment, + ...(isDevelopment ? { + sourcemap: "inline", + } : {}), + ...opts + }) +} + +await Promise.all([ + buildJs("src/app.ts", { outdir: "dist/src" }), + buildJs("src/app-bridge.ts", { outdir: "dist/src" }), + buildJs("src/react/index.tsx", { outdir: "dist/src/react" }), +]) \ No newline at end of file diff --git a/build.esbuild.ts b/build.esbuild.ts new file mode 100644 index 0000000..559c7fc --- /dev/null +++ b/build.esbuild.ts @@ -0,0 +1,30 @@ +#!/usr/bin/env tsx +import { execSync } from "child_process"; +import * as esbuild from "esbuild"; + +// Run TypeScript compiler for type declarations +execSync("tsc", { stdio: "inherit" }); + +const isDevelopment = process.env.NODE_ENV === "development"; + +// Build all JavaScript/TypeScript files +async function buildJs( + entrypoint: string, + opts: { outdir?: string; target?: "browser" | "node" } = {}, +) { + return esbuild.build({ + entryPoints: [entrypoint], + outdir: opts.outdir ?? "dist", + platform: opts.target === "node" ? "node" : "browser", + format: "esm", + bundle: true, + minify: !isDevelopment, + sourcemap: isDevelopment ? "inline" : false, + }); +} + +await Promise.all([ + buildJs("src/app.ts", { outdir: "dist/src" }), + buildJs("src/app-bridge.ts", { outdir: "dist/src" }), + buildJs("src/react/index.tsx", { outdir: "dist/src/react" }), +]); diff --git a/build.ts b/build.ts deleted file mode 100644 index 6cb67bd..0000000 --- a/build.ts +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env tsx -import { execSync } from "child_process"; -import * as esbuild from "esbuild"; -import { readFile, writeFile } from "fs/promises"; - -// Run TypeScript compiler for type declarations -execSync("tsc", { stdio: "inherit" }); - -const isDevelopment = process.env.NODE_ENV === "development"; - -// Build all JavaScript/TypeScript files -async function buildJs( - entrypoint: string, - opts: { outdir?: string; target?: "browser" | "node" } = {}, -) { - return esbuild.build({ - entryPoints: [entrypoint], - outdir: opts.outdir ?? "dist", - platform: opts.target === "node" ? "node" : "browser", - format: "esm", - bundle: true, - minify: !isDevelopment, - sourcemap: isDevelopment ? "inline" : false, - }); -} - -await Promise.all([ - buildJs("src/app.ts", { outdir: "dist/src" }), - buildJs("src/app-bridge.ts", { outdir: "dist/src" }), - buildJs("src/react/index.tsx", { outdir: "dist/src/react" }), - // buildJs("examples/example-ui-react.tsx", { outdir: "dist/examples" }), - // buildJs("examples/example-ui.ts", { outdir: "dist/examples" }), - // buildJs("examples/example-server.ts", { - // target: "node", - // outdir: "dist/examples", - // }), -]); - -// async function inlineHtml(htmlFilePath: string, outputFilePath: string) { -// let html = await readFile(htmlFilePath, "utf-8"); -// // Find all src sources, then fetch them, then replace them -// const files = html.matchAll( -// / to prevent premature script tag closing -// // This is the standard way to inline scripts safely -// scriptContent = scriptContent.replace(/<\/script>/gi, "<\\/script>"); -// return ``; -// }, -// ); -// await writeFile(outputFilePath, html); -// } - -// await inlineHtml("examples/example-ui.html", "dist/examples/example-ui.html"); -// await inlineHtml( -// "examples/example-ui-react.html", -// "dist/examples/example-ui-react.html", -// ); diff --git a/package.json b/package.json index 73b6ba8..552d893 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "start:sandbox-proxy": "python3 sandbox_proxy.py", "start": "npm run build && npm run start:example-server", "start:dev": "NODE_ENV=development npm start", - "build": "tsc && tsx build.ts", + "build": "bun build.bun.ts", "prepare": "npm run build", "prettier:base-cmd": "prettier -u --ignore-path ./.gitignore --ignore-path ./.prettierignore", "prettier": "yarn prettier:base-cmd \"$(pwd)/**/*.{js,jsx,ts,tsx,mjs,json,md,yml,yaml}\" --check", @@ -45,6 +45,7 @@ }, "dependencies": { "@modelcontextprotocol/sdk": "^1.20.1", + "bun": "^1.3.2", "esbuild": "~0.19.10", "react": "^19.2.0", "react-dom": "^19.2.0",