@@ -8,6 +8,37 @@ const pkg = await Bun.file(new URL('../package.json', import.meta.url)).json() a |
8 | 8 |
|
9 | 9 | const args = process.argv.slice(2) |
10 | 10 | const compile = args.includes('--compile') |
| 11 | +const dev = args.includes('--dev') |
| 12 | + |
| 13 | +function runCommand(cmd: string[]): string | null { |
| 14 | + const proc = Bun.spawnSync({ |
| 15 | + cmd, |
| 16 | + cwd: process.cwd(), |
| 17 | + stdout: 'pipe', |
| 18 | + stderr: 'pipe', |
| 19 | + }) |
| 20 | + |
| 21 | + if (proc.exitCode !== 0) { |
| 22 | + return null |
| 23 | + } |
| 24 | + |
| 25 | + return new TextDecoder().decode(proc.stdout).trim() || null |
| 26 | +} |
| 27 | + |
| 28 | +function getDevVersion(baseVersion: string): string { |
| 29 | + const timestamp = new Date().toISOString() |
| 30 | + const date = timestamp.slice(0, 10).replaceAll('-', '') |
| 31 | + const time = timestamp.slice(11, 19).replaceAll(':', '') |
| 32 | + const sha = runCommand(['git', 'rev-parse', '--short=8', 'HEAD']) ?? 'unknown' |
| 33 | + return `${baseVersion}-dev.${date}.t${time}.sha${sha}` |
| 34 | +} |
| 35 | + |
| 36 | +function getVersionChangelog(): string { |
| 37 | + return ( |
| 38 | + runCommand(['git', 'log', '--format=%h %s', '-20']) ?? |
| 39 | + 'Local development build' |
| 40 | + ) |
| 41 | +} |
11 | 42 |
|
12 | 43 | const features: string[] = [] |
13 | 44 | for (let i = 0; i < args.length; i += 1) { |
@@ -22,8 +53,15 @@ for (let i = 0; i < args.length; i += 1) { |
22 | 53 | } |
23 | 54 | } |
24 | 55 |
|
25 | | -const outfile = compile ? './dist/cli' : './cli' |
| 56 | +const outfile = compile |
| 57 | + ? dev |
| 58 | + ? './dist/cli-dev' |
| 59 | + : './dist/cli' |
| 60 | + : dev |
| 61 | + ? './cli-dev' |
| 62 | + : './cli' |
26 | 63 | const buildTime = new Date().toISOString() |
| 64 | +const version = dev ? getDevVersion(pkg.version) : pkg.version |
27 | 65 |
|
28 | 66 | mkdirSync(dirname(outfile), { recursive: true }) |
29 | 67 |
|
@@ -37,8 +75,16 @@ const externals = [ |
37 | 75 |
|
38 | 76 | const defines = { |
39 | 77 | 'process.env.USER_TYPE': JSON.stringify('external'), |
| 78 | + ...(dev |
| 79 | + ? { 'process.env.NODE_ENV': JSON.stringify('development') } |
| 80 | + : {}), |
| 81 | + ...(dev |
| 82 | + ? { |
| 83 | + 'process.env.CLAUDE_CODE_EXPERIMENTAL_BUILD': JSON.stringify('true'), |
| 84 | + } |
| 85 | + : {}), |
40 | 86 | 'process.env.CLAUDE_CODE_VERIFY_PLAN': JSON.stringify('false'), |
41 | | - 'MACRO.VERSION': JSON.stringify(pkg.version), |
| 87 | + 'MACRO.VERSION': JSON.stringify(version), |
42 | 88 | 'MACRO.BUILD_TIME': JSON.stringify(buildTime), |
43 | 89 | 'MACRO.PACKAGE_URL': JSON.stringify(pkg.name), |
44 | 90 | 'MACRO.NATIVE_PACKAGE_URL': 'undefined', |
@@ -47,7 +93,7 @@ const defines = { |
47 | 93 | 'This reconstructed source snapshot does not include Anthropic internal issue routing.', |
48 | 94 | ), |
49 | 95 | 'MACRO.VERSION_CHANGELOG': JSON.stringify( |
50 | | - 'https://github.com/paoloanzn/claude-code', |
| 96 | + dev ? getVersionChangelog() : 'https://github.com/paoloanzn/claude-code', |
51 | 97 | ), |
52 | 98 | } as const |
53 | 99 |
|
@@ -74,6 +120,10 @@ for (const external of externals) { |
74 | 120 | cmd.push('--external', external) |
75 | 121 | } |
76 | 122 |
|
| 123 | +for (const feature of features) { |
| 124 | + cmd.push(`--feature=${feature}`) |
| 125 | +} |
| 126 | + |
77 | 127 | for (const [key, value] of Object.entries(defines)) { |
78 | 128 | cmd.push('--define', `${key}=${value}`) |
79 | 129 | } |
|