mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
0663861471
Adds scripts/build-client.mjs which uses esbuild to compile TypeScript files in src/scripts/client/ into minified IIFE bundles, then writes them as TypeScript string-constant modules in src/scripts/generated/. - Adds build:client npm script; wires it as prebuild and predev hooks - Adds src/scripts/client/tsconfig.json with DOM lib for IDE support - Excludes src/scripts/client/ from the root Worker tsconfig to avoid DOM type conflicts with the Cloudflare Workers runtime types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
// Compiles client-side TypeScript files with esbuild and writes the result
|
|
// as TypeScript string-constant modules importable by the Cloudflare Worker.
|
|
|
|
import { build } from 'esbuild';
|
|
import { writeFileSync, mkdirSync } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const root = join(__dirname, '..');
|
|
|
|
const entries = [
|
|
{
|
|
input: 'src/scripts/client/dashboard.ts',
|
|
exportName: 'dashboardScript',
|
|
output: 'src/scripts/generated/dashboard.ts',
|
|
},
|
|
{
|
|
input: 'src/scripts/client/emails-page.ts',
|
|
exportName: 'emailsPageScript',
|
|
output: 'src/scripts/generated/emails-page.ts',
|
|
},
|
|
];
|
|
|
|
mkdirSync(join(root, 'src/scripts/generated'), { recursive: true });
|
|
|
|
for (const { input, exportName, output } of entries) {
|
|
const result = await build({
|
|
entryPoints: [join(root, input)],
|
|
bundle: true,
|
|
minify: true,
|
|
write: false,
|
|
target: 'es2020',
|
|
platform: 'browser',
|
|
format: 'iife',
|
|
});
|
|
|
|
const code = new TextDecoder().decode(result.outputFiles[0].contents);
|
|
const content = [
|
|
'// AUTO-GENERATED by scripts/build-client.mjs — do not edit directly.',
|
|
'// Source: ' + input,
|
|
'// Run `npm run build:client` to regenerate.',
|
|
'/* eslint-disable */',
|
|
'export const ' + exportName + ' = ' + JSON.stringify(code) + ';',
|
|
'',
|
|
].join('\n');
|
|
|
|
writeFileSync(join(root, output), content);
|
|
console.log('Built:', output);
|
|
}
|