|
| 1 | +#!/usr/bin/env node |
| 2 | +import { cp, rm } from 'fs/promises'; |
| 3 | +import { join, dirname } from 'path'; |
| 4 | +import { fileURLToPath } from 'url'; |
| 5 | +import { execSync } from 'child_process'; |
| 6 | + |
| 7 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 8 | + |
| 9 | +async function prepare() { |
| 10 | + console.log('Preparing for publish...'); |
| 11 | + |
| 12 | + // First, ensure TypeScript is available |
| 13 | + console.log('Installing TypeScript for build...'); |
| 14 | + try { |
| 15 | + execSync('npm install --no-save typescript @types/node', { stdio: 'inherit' }); |
| 16 | + } catch (e) { |
| 17 | + console.error('Failed to install TypeScript:', e.message); |
| 18 | + process.exit(1); |
| 19 | + } |
| 20 | + |
| 21 | + // Build shared directory first |
| 22 | + const sharedDir = join(__dirname, '../shared'); |
| 23 | + console.log('Building shared directory...'); |
| 24 | + try { |
| 25 | + execSync('npm install && npm run build', { cwd: sharedDir, stdio: 'inherit' }); |
| 26 | + } catch (e) { |
| 27 | + console.error('Failed to build shared directory:', e.message); |
| 28 | + process.exit(1); |
| 29 | + } |
| 30 | + |
| 31 | + // Set up the shared directory for the build |
| 32 | + console.log('Setting up shared directory for build...'); |
| 33 | + try { |
| 34 | + // Create a symlink for the build process (like setup-dev.js does) |
| 35 | + await rm(join(__dirname, 'shared'), { recursive: true, force: true }); |
| 36 | + execSync(`node setup-dev.js`, { cwd: __dirname, stdio: 'inherit' }); |
| 37 | + } catch (e) { |
| 38 | + console.error('Failed to set up shared directory:', e.message); |
| 39 | + process.exit(1); |
| 40 | + } |
| 41 | + |
| 42 | + // Now build the local package |
| 43 | + console.log('Building local package...'); |
| 44 | + try { |
| 45 | + execSync('npx tsc && npx tsc -p tsconfig.integration.json', { stdio: 'inherit' }); |
| 46 | + } catch (e) { |
| 47 | + console.error('Failed to build local package:', e.message); |
| 48 | + process.exit(1); |
| 49 | + } |
| 50 | + |
| 51 | + // Clean up the symlink and copy the actual files for publishing |
| 52 | + try { |
| 53 | + await rm(join(__dirname, 'shared'), { recursive: true, force: true }); |
| 54 | + } catch (e) { |
| 55 | + // Ignore if doesn't exist |
| 56 | + } |
| 57 | + |
| 58 | + // Copy the built shared files |
| 59 | + await cp(join(__dirname, '../shared/build'), join(__dirname, 'shared'), { recursive: true }); |
| 60 | + |
| 61 | + console.log('Copied shared files to local package'); |
| 62 | +} |
| 63 | + |
| 64 | +prepare().catch(console.error); |
0 commit comments