|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Complete build script for the interfaces package |
| 3 | +# Complete build script for the interfaces package with incremental build support |
4 | 4 | # This script handles:
|
5 | 5 | # 1. Hardhat compilation (generates artifacts and ethers-v6 types)
|
6 | 6 | # 2. Type generation (WAGMI and ethers-v5 types)
|
7 | 7 | # 3. TypeScript compilation (both v6 and v5 types)
|
8 | 8 |
|
9 | 9 | set -e # Exit on any error
|
10 | 10 |
|
11 |
| -echo "🔨 Starting complete build process..." |
| 11 | +echo "🔨 Starting build process..." |
| 12 | + |
| 13 | +# Helper function to check if target is newer than sources |
| 14 | +is_newer() { |
| 15 | + local target="$1" |
| 16 | + shift |
| 17 | + local sources=("$@") |
| 18 | + |
| 19 | + # If target doesn't exist, it needs to be built |
| 20 | + if [[ ! -e "$target" ]]; then |
| 21 | + return 1 |
| 22 | + fi |
| 23 | + |
| 24 | + # Check if any source is newer than target |
| 25 | + for source in "${sources[@]}"; do |
| 26 | + if [[ -e "$source" && "$source" -nt "$target" ]]; then |
| 27 | + return 1 |
| 28 | + fi |
| 29 | + done |
| 30 | + |
| 31 | + return 0 |
| 32 | +} |
| 33 | + |
| 34 | +# Helper function to find files matching patterns |
| 35 | +find_files() { |
| 36 | + local pattern="$1" |
| 37 | + find . -path "$pattern" -type f 2>/dev/null || true |
| 38 | +} |
12 | 39 |
|
13 | 40 | # Step 1: Hardhat compilation
|
14 | 41 | echo "📦 Compiling contracts with Hardhat..."
|
15 |
| -hardhat compile |
16 |
| - |
17 |
| -# Step 2: Generate types |
18 |
| -echo "🏗️ Generating type definitions..." |
19 |
| - |
20 |
| -# Build wagmi types |
21 |
| -echo " - Generating WAGMI types..." |
22 |
| -pnpm wagmi generate |
23 |
| - |
24 |
| -# Build ethers-v5 types |
25 |
| -echo " - Generating ethers-v5 types..." |
26 |
| -pnpm typechain \ |
27 |
| - --target ethers-v5 \ |
28 |
| - --out-dir types-v5 \ |
29 |
| - 'artifacts/contracts/**/!(*.dbg).json' \ |
30 |
| - 'artifacts/@openzeppelin/**/!(*.dbg).json' |
31 |
| - |
32 |
| -# Step 3: TypeScript compilation |
33 |
| -echo "🔧 Compiling TypeScript..." |
34 |
| - |
35 |
| -# Compile v6 types (default tsconfig) |
36 |
| -echo " - Compiling ethers-v6 types..." |
37 |
| -tsc |
38 |
| - |
39 |
| -# Compile v5 types (separate tsconfig) |
40 |
| -echo " - Compiling ethers-v5 types..." |
41 |
| -tsc -p tsconfig.v5.json |
42 |
| - |
43 |
| -# Step 4: Merge v5 types into dist directory |
44 |
| -echo "📁 Organizing compiled types..." |
45 |
| -mkdir -p dist/types-v5 |
46 |
| -cp -r dist-v5/* dist/types-v5/ |
| 42 | +pnpm hardhat compile |
| 43 | + |
| 44 | +# Step 2: Generate types (only if needed) |
| 45 | +echo "🏗️ Checking type definitions..." |
| 46 | + |
| 47 | +# Check if WAGMI types need regeneration |
| 48 | +wagmi_sources=( |
| 49 | + "wagmi.config.mts" |
| 50 | + $(find_files "./artifacts/contracts/**/!(*.dbg).json") |
| 51 | +) |
| 52 | +if ! is_newer "wagmi/generated.ts" "${wagmi_sources[@]}"; then |
| 53 | + echo " - Generating WAGMI types..." |
| 54 | + pnpm wagmi generate |
| 55 | +else |
| 56 | + echo " - WAGMI types are up to date" |
| 57 | +fi |
| 58 | + |
| 59 | +# Check if ethers-v5 types need regeneration |
| 60 | +v5_artifacts=($(find_files "./artifacts/contracts/**/!(*.dbg).json") $(find_files "./artifacts/@openzeppelin/**/!(*.dbg).json")) |
| 61 | +if ! is_newer "types-v5/index.ts" "${v5_artifacts[@]}"; then |
| 62 | + echo " - Generating ethers-v5 types..." |
| 63 | + pnpm typechain \ |
| 64 | + --target ethers-v5 \ |
| 65 | + --out-dir types-v5 \ |
| 66 | + 'artifacts/contracts/**/!(*.dbg).json' \ |
| 67 | + 'artifacts/@openzeppelin/**/!(*.dbg).json' |
| 68 | +else |
| 69 | + echo " - ethers-v5 types are up to date" |
| 70 | +fi |
| 71 | + |
| 72 | +# Step 3: TypeScript compilation (only if needed) |
| 73 | +echo "🔧 Checking TypeScript compilation..." |
| 74 | + |
| 75 | +# Check if v6 types need compilation |
| 76 | +v6_sources=( |
| 77 | + "hardhat.config.ts" |
| 78 | + $(find_files "./src/**/*.ts") |
| 79 | + $(find_files "./types/**/*.ts") |
| 80 | + $(find_files "./wagmi/**/*.ts") |
| 81 | +) |
| 82 | +if ! is_newer "dist/tsconfig.tsbuildinfo" "${v6_sources[@]}"; then |
| 83 | + echo " - Compiling ethers-v6 types..." |
| 84 | + pnpm tsc |
| 85 | + touch dist/tsconfig.tsbuildinfo |
| 86 | +else |
| 87 | + echo " - ethers-v6 types are up to date" |
| 88 | +fi |
| 89 | + |
| 90 | +# Check if v5 types need compilation |
| 91 | +v5_sources=($(find_files "./types-v5/**/*.ts")) |
| 92 | +if ! is_newer "dist-v5/tsconfig.v5.tsbuildinfo" "${v5_sources[@]}"; then |
| 93 | + echo " - Compiling ethers-v5 types..." |
| 94 | + pnpm tsc -p tsconfig.v5.json |
| 95 | + touch dist-v5/tsconfig.v5.tsbuildinfo |
| 96 | +else |
| 97 | + echo " - ethers-v5 types are up to date" |
| 98 | +fi |
| 99 | + |
| 100 | +# Step 4: Merge v5 types into dist directory (only if needed) |
| 101 | +needs_copy=false |
| 102 | +if [[ -d "dist-v5" ]]; then |
| 103 | + if [[ ! -d "dist/types-v5" ]]; then |
| 104 | + needs_copy=true |
| 105 | + else |
| 106 | + # Check if any file in dist-v5 is newer than the corresponding file in dist/types-v5 |
| 107 | + while IFS= read -r -d '' file; do |
| 108 | + relative_path="${file#dist-v5/}" |
| 109 | + target_file="dist/types-v5/$relative_path" |
| 110 | + if [[ ! -e "$target_file" || "$file" -nt "$target_file" ]]; then |
| 111 | + needs_copy=true |
| 112 | + break |
| 113 | + fi |
| 114 | + done < <(find dist-v5 -type f -print0) |
| 115 | + fi |
| 116 | +fi |
| 117 | + |
| 118 | +if [[ "$needs_copy" == "true" ]]; then |
| 119 | + echo "📁 Organizing compiled types..." |
| 120 | + mkdir -p dist/types-v5 |
| 121 | + cp -r dist-v5/* dist/types-v5/ |
| 122 | +else |
| 123 | + echo "📁 Compiled types organization is up to date" |
| 124 | +fi |
47 | 125 |
|
48 | 126 | echo "✅ Build completed successfully!"
|
49 | 127 | echo "📄 Generated types:"
|
|
0 commit comments