| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import { chmodSync, existsSync, mkdirSync } from 'fs'
- import { dirname } from 'path'
- const pkg = await Bun.file(new URL('../package.json', import.meta.url)).json() as {
- name: string
- version: string
- }
- const args = process.argv.slice(2)
- const compile = args.includes('--compile')
- const features: string[] = []
- for (let i = 0; i < args.length; i += 1) {
- const arg = args[i]
- if (arg === '--feature' && args[i + 1]) {
- features.push(args[i + 1]!)
- i += 1
- continue
- }
- if (arg.startsWith('--feature=')) {
- features.push(arg.slice('--feature='.length))
- }
- }
- const outfile = compile ? './dist/cli' : './cli'
- const buildTime = new Date().toISOString()
- mkdirSync(dirname(outfile), { recursive: true })
- const externals = [
- '@ant/*',
- 'audio-capture-napi',
- 'image-processor-napi',
- 'modifiers-napi',
- 'url-handler-napi',
- ]
- const defines = {
- 'process.env.USER_TYPE': JSON.stringify('external'),
- 'process.env.CLAUDE_CODE_VERIFY_PLAN': JSON.stringify('false'),
- 'MACRO.VERSION': JSON.stringify(pkg.version),
- 'MACRO.BUILD_TIME': JSON.stringify(buildTime),
- 'MACRO.PACKAGE_URL': JSON.stringify(pkg.name),
- 'MACRO.NATIVE_PACKAGE_URL': 'undefined',
- 'MACRO.FEEDBACK_CHANNEL': JSON.stringify('github'),
- 'MACRO.ISSUES_EXPLAINER': JSON.stringify(
- 'This reconstructed source snapshot does not include Anthropic internal issue routing.',
- ),
- 'MACRO.VERSION_CHANGELOG': JSON.stringify(
- 'https://github.com/paoloanzn/claude-code',
- ),
- } as const
- const cmd = [
- 'bun',
- 'build',
- './src/entrypoints/cli.tsx',
- '--compile',
- '--target',
- 'bun',
- '--format',
- 'esm',
- '--outfile',
- outfile,
- '--minify',
- '--bytecode',
- '--packages',
- 'bundle',
- '--conditions',
- 'bun',
- ]
- for (const external of externals) {
- cmd.push('--external', external)
- }
- for (const [key, value] of Object.entries(defines)) {
- cmd.push('--define', `${key}=${value}`)
- }
- const proc = Bun.spawnSync({
- cmd,
- cwd: process.cwd(),
- stdout: 'inherit',
- stderr: 'inherit',
- })
- if (proc.exitCode !== 0) {
- process.exit(proc.exitCode ?? 1)
- }
- if (existsSync(outfile)) {
- chmodSync(outfile, 0o755)
- }
- console.log(`Built ${outfile}`)
|