#!/usr/bin/env node /** * Bundles a dev page into a standalone HTML file: * - Bundles all module scripts (external + inline) with esbuild * - Bundles the Aura theme CSS (flattens @imports) * - Inlines both into a copy of the page * * Run from the workspace root, the page path is resolved * relative to the current working directory: * * node scripts/bundle-dev-page.js dev/.html [output.html] [--theme=aura:light] */ import { build } from 'esbuild'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const rootDir = path.resolve(__dirname, '..'); const args = process.argv.slice(2); const theme = args.find((arg) => arg.startsWith('--theme='))?.slice('--theme='.length) ?? 'aura:light'; const [input, output = input?.replace(/\.html$/u, '.standalone.html')] = args.filter((arg) => !arg.startsWith('--')); if (!input || !input.endsWith('.html')) { console.error('Usage: node scripts/bundle-dev-page.js dev/.html [output.html] [--theme=aura:light]'); process.exit(1); } const inputPath = path.resolve(input); let html = fs.readFileSync(inputPath, 'utf8'); // Collect module scripts in document order and remove them from the HTML const entryParts = []; html = html.replace( /[ \t]*\n`); fs.writeFileSync(output, html); console.log(`Wrote ${output} (js: ${(js.length / 1024).toFixed(1)} kB, css: ${(css.length / 1024).toFixed(1)} kB)`);