// Bundle the omni_pca side panel into a single ESM file the HA static // path serves at /api/omni_pca/panel.js. // // Usage: // node build.mjs # one-shot production build // node build.mjs --watch # rebuild on source change // // Output is intentionally placed at ../www/panel.js so the Python side // (websocket.py:async_register_side_panel) finds it without extra // configuration. The frontend dir + the Python integration sit in the // same custom_components/omni_pca/ tree so end-users just install the // integration; no separate HACS package needed. import { build, context } from "esbuild"; import { fileURLToPath } from "node:url"; import { dirname, resolve } from "node:path"; const __dirname = dirname(fileURLToPath(import.meta.url)); const watch = process.argv.includes("--watch"); const opts = { entryPoints: [resolve(__dirname, "src/omni-panel-programs.ts")], bundle: true, format: "esm", target: "es2022", minify: !watch, sourcemap: watch ? "inline" : false, outfile: resolve(__dirname, "../www/panel.js"), // Lit ships its own ESM build; bundle it inline so the panel is a // single self-contained file (matches how HACS-distributed cards work). loader: { ".ts": "ts" }, banner: { js: "// omni_pca side panel — generated by frontend/build.mjs. Edit src/, not this file.", }, }; if (watch) { const ctx = await context(opts); await ctx.watch(); console.log("watching for changes…"); } else { await build(opts); console.log("built ->", opts.outfile); }