|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Copy Addresses for Publishing |
| 5 | + * |
| 6 | + * This script copies the actual addresses.json files from horizon and subgraph-service |
| 7 | + * packages to replace the symlinks before npm publish. |
| 8 | + * |
| 9 | + * Why we need this: |
| 10 | + * - Development uses symlinks (committed to git) for convenience |
| 11 | + * - npm publish doesn't include symlinks in the published package |
| 12 | + * - We need actual files in the published package for consumers |
| 13 | + * |
| 14 | + * The postpublish script will restore the symlinks after publishing. |
| 15 | + */ |
| 16 | + |
| 17 | +const fs = require('fs') |
| 18 | +const path = require('path') |
| 19 | + |
| 20 | +const FILES_TO_COPY = [ |
| 21 | + { |
| 22 | + source: '../../../horizon/addresses.json', |
| 23 | + target: 'src/horizon/addresses.json', |
| 24 | + }, |
| 25 | + { |
| 26 | + source: '../../../subgraph-service/addresses.json', |
| 27 | + target: 'src/subgraph-service/addresses.json', |
| 28 | + }, |
| 29 | +] |
| 30 | + |
| 31 | +function copyFileForPublish(source, target) { |
| 32 | + const targetPath = path.resolve(__dirname, '..', target) |
| 33 | + const sourcePath = path.resolve(path.dirname(targetPath), source) |
| 34 | + |
| 35 | + // Ensure source exists |
| 36 | + if (!fs.existsSync(sourcePath)) { |
| 37 | + console.error(`❌ Source file ${sourcePath} does not exist`) |
| 38 | + process.exit(1) |
| 39 | + } |
| 40 | + |
| 41 | + // Remove existing symlink |
| 42 | + if (fs.existsSync(targetPath)) { |
| 43 | + fs.unlinkSync(targetPath) |
| 44 | + } |
| 45 | + |
| 46 | + // Copy actual file |
| 47 | + try { |
| 48 | + fs.copyFileSync(sourcePath, targetPath) |
| 49 | + console.log(`✅ Copied for publish: ${target} <- ${source}`) |
| 50 | + } catch (error) { |
| 51 | + console.error(`❌ Failed to copy ${source} to ${target}:`, error.message) |
| 52 | + process.exit(1) |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +function main() { |
| 57 | + console.log('📦 Copying address files for npm publish...') |
| 58 | + |
| 59 | + for (const { source, target } of FILES_TO_COPY) { |
| 60 | + copyFileForPublish(source, target) |
| 61 | + } |
| 62 | + |
| 63 | + console.log('✅ Address files copied for publish!') |
| 64 | +} |
| 65 | + |
| 66 | +if (require.main === module) { |
| 67 | + main() |
| 68 | +} |
0 commit comments