// Build the Studio into dist/: studio.js (the bundled interface), worker.js // (the engine's worker), studio.css, tokens.css and index.html. The engine // package itself is not bundled: a host serves it and names it in the mount // element's data-engine-pkg. // // node build.mjs [--pkg DIR] (--pkg copies an engine package into dist/pkg/) import { build } from 'esbuild'; import { copyFileSync, cpSync, mkdirSync, rmSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const here = dirname(fileURLToPath(import.meta.url)); const dist = join(here, 'dist'); rmSync(dist, { recursive: true, force: true }); mkdirSync(dist, { recursive: true }); const common = { bundle: true, format: 'esm', target: ['es2022'], minify: true, legalComments: 'eof', logLevel: 'warning' }; await build({ ...common, entryPoints: [join(here, 'src/main.js')], outfile: join(dist, 'studio.js') }); await build({ ...common, entryPoints: [join(here, 'src/worker.js')], outfile: join(dist, 'worker.js') }); for (const f of ['studio.css', 'tokens.css', 'index.html']) copyFileSync(join(here, 'src', f), join(dist, f)); const at = process.argv.indexOf('--pkg'); if (at > 0) cpSync(process.argv[at + 1], join(dist, 'pkg'), { recursive: true }); console.log(`built ${dist}`);