/** * Bundles the CodeMirror 6 entry (`scripts/codemirror-entry.mjs`) into a single * IIFE string inside `src/components/git/codemirror-bundle.ts`. * * Run with `npm run build:editor`. The generated module is committed so the app * builds without a JS bundling step at runtime. */ import { writeFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { build } from 'esbuild'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const entry = resolve(root, 'scripts/codemirror-entry.mjs'); const output = resolve(root, 'src/components/git/codemirror-bundle.ts'); const result = await build({ entryPoints: [entry], bundle: true, format: 'iife', minify: true, write: false, platform: 'browser', target: 'es2020', legalComments: 'none', }); const code = result.outputFiles[0].text; const safe = code.replace(/<\/script/gi, '<\\/script'); const module = `/** * AUTO-GENERATED by scripts/build-editor.mjs — do not edit by hand. * Bundled CodeMirror 6 editor (see scripts/codemirror-entry.mjs). */ export const CODE_MIRROR_BUNDLE = ${JSON.stringify(safe)}; `; writeFileSync(output, module); console.log(`Wrote ${output} (${code.length} bytes)`);