How do I have so many partners??
1/**
2 * Bundles src/client/graph.ts for browser use (IIFE, minified),
3 * then writes the result as a TypeScript string constant to
4 * src/generated/client-bundle.ts so the CLI can inline it into HTML output.
5 *
6 * Run: npx tsx scripts/build-client.ts
7 */
8import { buildSync } from 'esbuild';
9import { writeFileSync, mkdirSync } from 'fs';
10import { resolve } from 'path';
11
12const root = resolve(process.cwd());
13
14const result = buildSync({
15 entryPoints: [resolve(root, 'src/client/graph.ts')],
16 bundle: true,
17 format: 'iife',
18 globalName: '_PM',
19 minify: true,
20 platform: 'browser',
21 target: ['es2017'],
22 write: false,
23 define: {
24 'process.env.NODE_ENV': '"production"',
25 },
26 logLevel: 'warning',
27});
28
29if (result.errors.length > 0) {
30 console.error('Client bundle errors:', result.errors);
31 process.exit(1);
32}
33
34const bundle = result.outputFiles[0].text;
35
36const output = `// AUTO-GENERATED — do not edit manually.
37// Regenerate with: npm run build:client
38export const CLIENT_BUNDLE = ${JSON.stringify(bundle)};
39`;
40
41mkdirSync(resolve(root, 'src/generated'), { recursive: true });
42writeFileSync(resolve(root, 'src/generated/client-bundle.ts'), output, 'utf8');
43
44console.log(`✓ Client bundle: ${(bundle.length / 1024).toFixed(1)} kB → src/generated/client-bundle.ts`);