mirror of
https://github.com/musistudio/claude-code-router.git
synced 2026-02-02 06:40:50 +08:00
move to monorepo
This commit is contained in:
90
scripts/build-cli.js
Normal file
90
scripts/build-cli.js
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
console.log('Building CLI package...');
|
||||
|
||||
try {
|
||||
const rootDir = path.join(__dirname, '..');
|
||||
const sharedDir = path.join(rootDir, 'packages/shared');
|
||||
const cliDir = path.join(rootDir, 'packages/cli');
|
||||
const serverDir = path.join(rootDir, 'packages/server');
|
||||
const uiDir = path.join(rootDir, 'packages/ui');
|
||||
|
||||
// Step 0: Ensure shared package is built first
|
||||
console.log('Ensuring shared package is built...');
|
||||
const sharedDistDir = path.join(sharedDir, 'dist');
|
||||
if (!fs.existsSync(sharedDistDir) || !fs.existsSync(path.join(sharedDistDir, 'index.js'))) {
|
||||
console.log('Shared package not found, building it first...');
|
||||
execSync('node scripts/build-shared.js', {
|
||||
stdio: 'inherit',
|
||||
cwd: rootDir
|
||||
});
|
||||
}
|
||||
|
||||
// Step 1: Build Server package first
|
||||
console.log('Building Server package...');
|
||||
execSync('node scripts/build-server.js', {
|
||||
stdio: 'inherit',
|
||||
cwd: rootDir
|
||||
});
|
||||
|
||||
// Step 2: Build UI package
|
||||
console.log('Building UI package...');
|
||||
execSync('pnpm build', {
|
||||
stdio: 'inherit',
|
||||
cwd: uiDir
|
||||
});
|
||||
|
||||
// Step 3: Create CLI dist directory
|
||||
const cliDistDir = path.join(cliDir, 'dist');
|
||||
if (!fs.existsSync(cliDistDir)) {
|
||||
fs.mkdirSync(cliDistDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Step 4: Build the CLI application
|
||||
console.log('Building CLI application...');
|
||||
execSync('esbuild src/cli.ts --bundle --platform=node --outfile=dist/cli.js', {
|
||||
stdio: 'inherit',
|
||||
cwd: cliDir
|
||||
});
|
||||
|
||||
// Step 5: Copy tiktoken WASM file from server dist to CLI dist
|
||||
console.log('Copying tiktoken_bg.wasm from server to CLI dist...');
|
||||
const tiktokenSource = path.join(serverDir, 'dist/tiktoken_bg.wasm');
|
||||
const tiktokenDest = path.join(cliDistDir, 'tiktoken_bg.wasm');
|
||||
|
||||
if (fs.existsSync(tiktokenSource)) {
|
||||
fs.copyFileSync(tiktokenSource, tiktokenDest);
|
||||
console.log('✓ tiktoken_bg.wasm copied successfully!');
|
||||
} else {
|
||||
console.warn('⚠ Warning: tiktoken_bg.wasm not found in server dist, skipping...');
|
||||
}
|
||||
|
||||
// Step 6: Copy UI index.html from UI dist to CLI dist
|
||||
console.log('Copying index.html from UI to CLI dist...');
|
||||
const uiSource = path.join(uiDir, 'dist/index.html');
|
||||
const uiDest = path.join(cliDistDir, 'index.html');
|
||||
|
||||
if (fs.existsSync(uiSource)) {
|
||||
fs.copyFileSync(uiSource, uiDest);
|
||||
console.log('✓ index.html copied successfully!');
|
||||
} else {
|
||||
console.warn('⚠ Warning: index.html not found in UI dist, skipping...');
|
||||
}
|
||||
|
||||
console.log('CLI build completed successfully!');
|
||||
console.log('\nCLI dist contents:');
|
||||
const files = fs.readdirSync(cliDistDir);
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(cliDistDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
const size = (stats.size / 1024 / 1024).toFixed(2);
|
||||
console.log(` - ${file} (${size} MB)`);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('CLI build failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
40
scripts/build-server.js
Normal file
40
scripts/build-server.js
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
console.log('Building Server package...');
|
||||
|
||||
try {
|
||||
// Create dist directory
|
||||
const distDir = path.join(__dirname, '../packages/server/dist');
|
||||
if (!fs.existsSync(distDir)) {
|
||||
fs.mkdirSync(distDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Build the server application
|
||||
console.log('Building server application...');
|
||||
// 使用 minify 和 tree-shaking 优化体积
|
||||
execSync('esbuild src/index.ts --bundle --platform=node --minify --tree-shaking=true --outfile=dist/index.js', {
|
||||
stdio: 'inherit',
|
||||
cwd: path.join(__dirname, '../packages/server')
|
||||
});
|
||||
|
||||
// Copy the tiktoken WASM file
|
||||
console.log('Copying tiktoken WASM file...');
|
||||
const tiktokenSource = path.join(__dirname, '../packages/server/node_modules/tiktoken/tiktoken_bg.wasm');
|
||||
const tiktokenDest = path.join(__dirname, '../packages/server/dist/tiktoken_bg.wasm');
|
||||
|
||||
if (fs.existsSync(tiktokenSource)) {
|
||||
fs.copyFileSync(tiktokenSource, tiktokenDest);
|
||||
console.log('Tiktoken WASM file copied successfully!');
|
||||
} else {
|
||||
console.warn('Warning: tiktoken_bg.wasm not found, skipping...');
|
||||
}
|
||||
|
||||
console.log('Server build completed successfully!');
|
||||
} catch (error) {
|
||||
console.error('Server build failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
36
scripts/build-shared.js
Normal file
36
scripts/build-shared.js
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
console.log('Building Shared package...');
|
||||
|
||||
try {
|
||||
const sharedDir = path.join(__dirname, '../packages/shared');
|
||||
|
||||
// Create dist directory
|
||||
const distDir = path.join(sharedDir, 'dist');
|
||||
if (!fs.existsSync(distDir)) {
|
||||
fs.mkdirSync(distDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Generate type declaration files
|
||||
console.log('Generating type declaration files...');
|
||||
execSync('tsc --emitDeclarationOnly', {
|
||||
stdio: 'inherit',
|
||||
cwd: sharedDir
|
||||
});
|
||||
|
||||
// Build the shared package
|
||||
console.log('Building shared package...');
|
||||
execSync('esbuild src/index.ts --bundle --platform=node --minify --tree-shaking=true --outfile=dist/index.js', {
|
||||
stdio: 'inherit',
|
||||
cwd: sharedDir
|
||||
});
|
||||
|
||||
console.log('Shared package build completed successfully!');
|
||||
} catch (error) {
|
||||
console.error('Shared package build failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -1,34 +1,24 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
console.log('Building Claude Code Router...');
|
||||
console.log('Building Claude Code Router (Monorepo)...');
|
||||
|
||||
try {
|
||||
// Build the main CLI application
|
||||
console.log('Building CLI application...');
|
||||
execSync('esbuild src/cli.ts --bundle --platform=node --outfile=dist/cli.js', { stdio: 'inherit' });
|
||||
|
||||
// Copy the tiktoken WASM file
|
||||
console.log('Copying tiktoken WASM file...');
|
||||
execSync('shx cp node_modules/tiktoken/tiktoken_bg.wasm dist/tiktoken_bg.wasm', { stdio: 'inherit' });
|
||||
|
||||
// Build the UI
|
||||
console.log('Building UI...');
|
||||
// Check if node_modules exists in ui directory, if not install dependencies
|
||||
if (!fs.existsSync('ui/node_modules')) {
|
||||
console.log('Installing UI dependencies...');
|
||||
execSync('cd ui && npm install', { stdio: 'inherit' });
|
||||
}
|
||||
execSync('cd ui && npm run build', { stdio: 'inherit' });
|
||||
|
||||
// Copy the built UI index.html to dist
|
||||
console.log('Copying UI build artifacts...');
|
||||
execSync('shx cp ui/dist/index.html dist/index.html', { stdio: 'inherit' });
|
||||
|
||||
console.log('Build completed successfully!');
|
||||
// Build shared package first
|
||||
console.log('Building shared package...');
|
||||
execSync('node scripts/build-shared.js', { stdio: 'inherit' });
|
||||
|
||||
// Build CLI package (which will also build server and ui)
|
||||
console.log('Building CLI package (includes server and ui)...');
|
||||
execSync('node scripts/build-cli.js', { stdio: 'inherit' });
|
||||
|
||||
console.log('\n✅ Build completed successfully!');
|
||||
console.log('\nArtifacts are available in packages/*/dist:');
|
||||
console.log(' - packages/shared/dist/ (Shared package)');
|
||||
console.log(' - packages/cli/dist/ (CLI + UI + tiktoken)');
|
||||
console.log(' - packages/server/dist/ (Server standalone)');
|
||||
console.log(' - packages/ui/dist/ (UI standalone)');
|
||||
} catch (error) {
|
||||
console.error('Build failed:', error.message);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user