()
| 20 | const CLI_BUNDLE = resolve(DIST, 'cli.mjs') |
| 21 | |
| 22 | function main() { |
| 23 | // Verify the bundle exists |
| 24 | if (!existsSync(CLI_BUNDLE)) { |
| 25 | console.error('Error: dist/cli.mjs not found. Run `bun run build:prod` first.') |
| 26 | process.exit(1) |
| 27 | } |
| 28 | |
| 29 | // Read source package.json |
| 30 | const srcPkg = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf-8')) |
| 31 | |
| 32 | // Create npm output directory |
| 33 | mkdirSync(NPM_DIR, { recursive: true }) |
| 34 | |
| 35 | // Copy the bundled CLI |
| 36 | copyFileSync(CLI_BUNDLE, resolve(NPM_DIR, 'cli.mjs')) |
| 37 | chmodSync(resolve(NPM_DIR, 'cli.mjs'), 0o755) |
| 38 | |
| 39 | // Copy source map if it exists |
| 40 | const sourceMap = resolve(DIST, 'cli.mjs.map') |
| 41 | if (existsSync(sourceMap)) { |
| 42 | copyFileSync(sourceMap, resolve(NPM_DIR, 'cli.mjs.map')) |
| 43 | } |
| 44 | |
| 45 | // Generate a publishable package.json |
| 46 | const npmPkg = { |
| 47 | name: srcPkg.name || '@anthropic-ai/claude-code', |
| 48 | version: srcPkg.version || '0.0.0', |
| 49 | description: srcPkg.description || 'Anthropic Claude Code CLI', |
| 50 | license: 'MIT', |
| 51 | type: 'module', |
| 52 | main: './cli.mjs', |
| 53 | bin: { |
| 54 | claude: './cli.mjs', |
| 55 | }, |
| 56 | engines: { |
| 57 | node: '>=20.0.0', |
| 58 | }, |
| 59 | os: ['darwin', 'linux', 'win32'], |
| 60 | files: [ |
| 61 | 'cli.mjs', |
| 62 | 'cli.mjs.map', |
| 63 | 'README.md', |
| 64 | ], |
| 65 | } |
| 66 | |
| 67 | writeFileSync( |
| 68 | resolve(NPM_DIR, 'package.json'), |
| 69 | JSON.stringify(npmPkg, null, 2) + '\n', |
| 70 | ) |
| 71 | |
| 72 | // Copy README if it exists |
| 73 | const readme = resolve(ROOT, 'README.md') |
| 74 | if (existsSync(readme)) { |
| 75 | copyFileSync(readme, resolve(NPM_DIR, 'README.md')) |
| 76 | } |
| 77 | |
| 78 | // Summary |
| 79 | const bundleSize = readFileSync(CLI_BUNDLE).byteLength |
no test coverage detected