import { build } from 'esbuild';
import { mkdir, readFile, rm } from 'node:fs/promises';
import { resolve } from 'node:path';
const manifest = JSON.parse(await readFile('package.json', 'utf8'));
if (manifest.name !== 'essential-tools-source-kit') throw new Error('Build the CLI inside the generated source kit, not the corporate site output directory.');
const output = resolve(process.cwd(), 'dist');
if (output !== resolve('dist')) throw new Error('Unexpected CLI build output path.');
await rm(output, { recursive: true, force: true });
await mkdir('dist/render', { recursive: true });
await build({ entryPoints: ['cli/tools-cli.ts'], outfile: 'dist/cli.mjs', bundle: true, packages: 'external', platform: 'node', format: 'esm', target: 'node24', sourcemap: false });
await build({ entryPoints: { renderer: 'cli/render-entry.ts' }, outdir: 'dist/render', bundle: true, platform: 'browser', format: 'esm', splitting: true, target: 'es2022', minify: true, sourcemap: false, logLevel: 'warning' });
console.log('Built local CLI and its isolated process renderer.');
