Skip to content

Commit 55220ab

Browse files
committed
feat(build): standardize Claude Code version and enhance build flexibility
- Pin Claude Code version to 1.0.41 across all build scripts for consistency - Add version parameter support to fetch-and-build.js script - Enhance build script with improved CLI argument parsing - Add prebuild hook to automatically build current platform executables Changes made: • package.json: Add --version=1.0.41 to all build:executables scripts • package.json: Add prebuild script to run build:executables:current • scripts/fetch-and-build.js: Add parseArguments() function for CLI parsing • scripts/fetch-and-build.js: Add determineClaudeCodeVersion() for version resolution • scripts/fetch-and-build.js: Update fetchClaudeCodePackage() to accept version parameter • scripts/fetch-and-build.js: Enhance usage documentation and error messages
1 parent 11d9469 commit 55220ab

2 files changed

Lines changed: 68 additions & 15 deletions

File tree

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "tsc && vite build",
9-
"build:executables": "bun run scripts/fetch-and-build.js",
10-
"build:executables:current": "bun run scripts/fetch-and-build.js current",
11-
"build:executables:linux": "bun run scripts/fetch-and-build.js linux",
12-
"build:executables:macos": "bun run scripts/fetch-and-build.js macos",
13-
"build:executables:windows": "bun run scripts/fetch-and-build.js windows",
9+
"prebuild": "bun run build:executables:current",
10+
"build:executables": "bun run scripts/fetch-and-build.js --version=1.0.41",
11+
"build:executables:current": "bun run scripts/fetch-and-build.js current --version=1.0.41",
12+
"build:executables:linux": "bun run scripts/fetch-and-build.js linux --version=1.0.41",
13+
"build:executables:macos": "bun run scripts/fetch-and-build.js macos --version=1.0.41",
14+
"build:executables:windows": "bun run scripts/fetch-and-build.js windows --version=1.0.41",
1415
"preview": "vite preview",
1516
"tauri": "tauri"
1617
},

scripts/fetch-and-build.js

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
* 4. Cleans up temporary files
1111
*
1212
* Usage:
13-
* bun run fetch-and-build.js [platform]
13+
* bun run fetch-and-build.js [platform] [--version=X.X.X]
1414
*
1515
* Where platform can be: all, linux, macos, windows, current
16+
*
17+
* Version can be specified via:
18+
* - CLI argument: --version=1.0.41 (defaults to 1.0.41 if not specified)
1619
*/
1720

1821
import { spawn } from 'child_process';
@@ -65,12 +68,50 @@ async function pathExists(path) {
6568
}
6669
}
6770

71+
/**
72+
* Parse command line arguments to extract version and platform
73+
* @param {string[]} args - Command line arguments
74+
* @returns {object} - Parsed arguments with platform and version
75+
*/
76+
function parseArguments(args) {
77+
let platform = 'all';
78+
let version = null;
79+
80+
for (const arg of args) {
81+
if (arg.startsWith('--version=')) {
82+
version = arg.split('=')[1];
83+
} else if (!arg.startsWith('--')) {
84+
platform = arg;
85+
}
86+
}
87+
88+
return { platform, version };
89+
}
90+
91+
/**
92+
* Determine the Claude Code version to use
93+
* @param {string|null} cliVersion - Version from CLI argument
94+
* @returns {string} - The version to use
95+
*/
96+
function determineClaudeCodeVersion(cliVersion) {
97+
const defaultVersion = '1.0.41';
98+
99+
if (cliVersion) {
100+
console.log(`\n🔍 Using Claude Code version from CLI argument: ${cliVersion}`);
101+
return cliVersion;
102+
}
103+
104+
console.log(`\n🔍 Using default Claude Code version: ${defaultVersion}`);
105+
return defaultVersion;
106+
}
107+
68108
/**
69109
* Download and extract the Claude Code package from npm
110+
* @param {string} version - The version of the Claude Code package to download
70111
* @returns {Promise<string>} - Path to the extracted package directory
71112
*/
72-
async function fetchClaudeCodePackage() {
73-
console.log('\n📦 Fetching @anthropic-ai/claude-code package from npm...');
113+
async function fetchClaudeCodePackage(version) {
114+
console.log(`\n📦 Fetching @anthropic-ai/claude-code@${version} package from npm...`);
74115

75116
const tempDir = resolve('./temp-claude-package');
76117
const packageDir = join(tempDir, 'package');
@@ -86,8 +127,8 @@ async function fetchClaudeCodePackage() {
86127
await mkdir(tempDir, { recursive: true });
87128

88129
// Download the package tarball
89-
console.log('Downloading package tarball...');
90-
await runCommand('npm', ['pack', '@anthropic-ai/claude-code'], {
130+
console.log(`Downloading package tarball for version ${version}...`);
131+
await runCommand('npm', ['pack', `@anthropic-ai/claude-code@${version}`], {
91132
cwd: tempDir
92133
});
93134

@@ -238,12 +279,20 @@ async function buildExecutables(platform = 'all') {
238279
* Main execution function
239280
*/
240281
async function main() {
241-
const platform = process.argv[2] || 'all';
282+
// Parse command line arguments
283+
const args = process.argv.slice(2);
284+
const { platform, version: cliVersion } = parseArguments(args);
285+
242286
const validPlatforms = ['all', 'linux', 'macos', 'darwin', 'windows', 'win32', 'current'];
243287

244288
if (!validPlatforms.includes(platform)) {
245289
console.error(`Invalid platform: ${platform}`);
246290
console.error(`Valid platforms: ${validPlatforms.join(', ')}`);
291+
console.error('\nUsage: bun run fetch-and-build.js [platform] [--version=X.X.X]');
292+
console.error('Examples:');
293+
console.error(' bun run fetch-and-build.js');
294+
console.error(' bun run fetch-and-build.js linux');
295+
console.error(' bun run fetch-and-build.js macos --version=1.0.42');
247296
process.exit(1);
248297
}
249298

@@ -254,13 +303,16 @@ async function main() {
254303
let packageDir;
255304

256305
try {
257-
// Step 1: Fetch and extract the package
258-
packageDir = await fetchClaudeCodePackage();
306+
// Step 1: Determine version to use
307+
const version = determineClaudeCodeVersion(cliVersion);
308+
309+
// Step 2: Fetch and extract the package
310+
packageDir = await fetchClaudeCodePackage(version);
259311

260-
// Step 2: Copy required files
312+
// Step 3: Copy required files
261313
await copyRequiredFiles(packageDir);
262314

263-
// Step 3: Build executables
315+
// Step 4: Build executables
264316
await buildExecutables(platform);
265317

266318
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);

0 commit comments

Comments
 (0)