Files
JustZoe101 883440b8be feat: CodeMirror 6 editor with in-editor search/replace
- bundle CodeMirror 6 (+ langs/search) via scripts/build-editor.mjs into a
  generated TS module (inlined into the WebView; no remote code, no asset
  pipeline)
- CodeEditor now renders CodeMirror 6 with line numbers, language modes and a
  search/replace panel exposed from a toolbar button
- npm run build:editor; language mapping by file extension
2026-10-09 19:08:38 +02:00

42 lines
1.2 KiB
JavaScript

/**
* 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)`);