|
| 1 | +import { execSync } from "child_process"; |
| 2 | +import { existsSync, rmSync } from "fs"; |
| 3 | +import { dirname, join } from "path"; |
| 4 | +import process from "process"; |
| 5 | +import { fileURLToPath } from "url"; |
| 6 | + |
| 7 | +// Get script directory (equivalent to BASH_SOURCE in bash) |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = dirname(__filename); |
| 10 | + |
| 11 | +const CONTRACT_DIR = join(__dirname, "waku-rlnv2-contract"); |
| 12 | +const REPO_URL = "[email protected]:waku-org/waku-rlnv2-contract.git"; |
| 13 | + |
| 14 | +/** |
| 15 | + * Execute a shell command and print output in real-time |
| 16 | + * @param {string} command - The command to execute |
| 17 | + * @param {object} options - Options for execSync |
| 18 | + */ |
| 19 | +function exec(command, options = {}) { |
| 20 | + execSync(command, { |
| 21 | + stdio: "inherit", |
| 22 | + cwd: options.cwd || __dirname, |
| 23 | + ...options |
| 24 | + }); |
| 25 | +} |
| 26 | + |
| 27 | +async function main() { |
| 28 | + try { |
| 29 | + console.log("📦 Setting up waku-rlnv2-contract..."); |
| 30 | + |
| 31 | + // Remove existing directory if it exists |
| 32 | + if (existsSync(CONTRACT_DIR)) { |
| 33 | + console.log("🗑️ Removing existing waku-rlnv2-contract directory..."); |
| 34 | + rmSync(CONTRACT_DIR, { recursive: true, force: true }); |
| 35 | + } |
| 36 | + |
| 37 | + // Clone the repository |
| 38 | + console.log("📥 Cloning waku-rlnv2-contract..."); |
| 39 | + exec(`git clone ${REPO_URL} ${CONTRACT_DIR}`); |
| 40 | + |
| 41 | + // Install dependencies |
| 42 | + console.log("📦 Installing dependencies..."); |
| 43 | + exec("npm install", { cwd: CONTRACT_DIR }); |
| 44 | + |
| 45 | + // Build contracts with Foundry |
| 46 | + console.log("🔨 Building contracts with Foundry..."); |
| 47 | + exec("forge build", { cwd: CONTRACT_DIR }); |
| 48 | + |
| 49 | + // Generate ABIs with wagmi |
| 50 | + console.log("⚙️ Generating ABIs with wagmi..."); |
| 51 | + exec("npx wagmi generate"); |
| 52 | + |
| 53 | + console.log("✅ Contract ABIs generated successfully!"); |
| 54 | + } catch (error) { |
| 55 | + console.log( |
| 56 | + "❌ Error generating contract ABIs:", |
| 57 | + error instanceof Error ? error.message : error |
| 58 | + ); |
| 59 | + process.exit(1); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +main().catch((error) => { |
| 64 | + console.log(error); |
| 65 | + process.exit(1); |
| 66 | +}); |
0 commit comments