|
| 1 | +#!/usr/bin/env bun |
| 2 | +/** |
| 3 | + * Script to test SDK types by running setup in each test subproject. |
| 4 | + * Removes the previous node_modules/@codebuff/sdk installation before running setup. |
| 5 | + */ |
| 6 | + |
| 7 | +import { execSync } from 'child_process' |
| 8 | +import { existsSync, rmSync } from 'fs' |
| 9 | +import { join } from 'path' |
| 10 | + |
| 11 | +const TEST_SUBPROJECTS = [ |
| 12 | + 'cjs-compatibility', |
| 13 | + 'esm-compatibility', |
| 14 | + 'ripgrep-bundling', |
| 15 | +] |
| 16 | + |
| 17 | +const sdkRoot = join(import.meta.dirname, '..') |
| 18 | +const testDir = join(sdkRoot, 'test') |
| 19 | + |
| 20 | +function log(message: string) { |
| 21 | + console.log(`\n📦 ${message}`) |
| 22 | +} |
| 23 | + |
| 24 | +function removeOldSdk(projectPath: string) { |
| 25 | + const sdkPath = join(projectPath, 'node_modules', '@codebuff', 'sdk') |
| 26 | + if (existsSync(sdkPath)) { |
| 27 | + console.log(` 🗑️ Removing old SDK at ${sdkPath}`) |
| 28 | + rmSync(sdkPath, { recursive: true, force: true }) |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +function runSetup(projectName: string) { |
| 33 | + const projectPath = join(testDir, projectName) |
| 34 | + |
| 35 | + if (!existsSync(projectPath)) { |
| 36 | + console.error(` ❌ Project not found: ${projectPath}`) |
| 37 | + process.exit(1) |
| 38 | + } |
| 39 | + |
| 40 | + log(`Setting up ${projectName}...`) |
| 41 | + |
| 42 | + // Remove old SDK installation |
| 43 | + removeOldSdk(projectPath) |
| 44 | + |
| 45 | + // Run npm install to ensure dependencies are present |
| 46 | + console.log(` 📥 Installing dependencies...`) |
| 47 | + execSync('npm install --silent', { cwd: projectPath, stdio: 'inherit' }) |
| 48 | + |
| 49 | + // Run the setup script |
| 50 | + console.log(` 🔧 Running setup script...`) |
| 51 | + execSync('npm run setup', { cwd: projectPath, stdio: 'inherit' }) |
| 52 | + |
| 53 | + // Run type tests |
| 54 | + console.log(` 🔍 Running type tests...`) |
| 55 | + execSync('npm run test:types', { cwd: projectPath, stdio: 'inherit' }) |
| 56 | + |
| 57 | + console.log(` ✅ ${projectName} types passed!`) |
| 58 | +} |
| 59 | + |
| 60 | +async function main() { |
| 61 | + console.log('🧪 SDK Type Testing Script') |
| 62 | + console.log('==========================') |
| 63 | + |
| 64 | + // Ensure the SDK is built first |
| 65 | + log('Checking SDK dist...') |
| 66 | + const distPath = join(sdkRoot, 'dist') |
| 67 | + if (!existsSync(distPath)) { |
| 68 | + console.log(' ⚠️ SDK dist not found, building...') |
| 69 | + execSync('bun run build', { cwd: sdkRoot, stdio: 'inherit' }) |
| 70 | + } |
| 71 | + |
| 72 | + // Run setup and type tests for each subproject |
| 73 | + for (const project of TEST_SUBPROJECTS) { |
| 74 | + runSetup(project) |
| 75 | + } |
| 76 | + |
| 77 | + console.log('\n🎉 All type tests passed!') |
| 78 | +} |
| 79 | + |
| 80 | +main().catch((error) => { |
| 81 | + console.error('\n❌ Type testing failed:', error.message) |
| 82 | + process.exit(1) |
| 83 | +}) |
0 commit comments