|
| 1 | +#!/usr/bin/env node |
| 2 | +/* eslint-disable no-console */ |
| 3 | + |
| 4 | +const { spawnSync } = require("child_process"); |
| 5 | +const fs = require("fs"); |
| 6 | +const path = require("path"); |
| 7 | + |
| 8 | +function run(cmd, args, opts = {}) { |
| 9 | + const res = spawnSync(cmd, args, { |
| 10 | + cwd: opts.cwd, |
| 11 | + stdio: "inherit", |
| 12 | + shell: false, |
| 13 | + }); |
| 14 | + |
| 15 | + if (res.error) { |
| 16 | + return { ok: false, code: 1 }; |
| 17 | + } |
| 18 | + |
| 19 | + return { ok: res.status === 0, code: res.status ?? 1 }; |
| 20 | +} |
| 21 | + |
| 22 | +function header(title) { |
| 23 | + console.log(`\n== ${title} ==`); |
| 24 | +} |
| 25 | + |
| 26 | +function main() { |
| 27 | + const repoRoot = path.resolve(__dirname, ".."); |
| 28 | + const failures = []; |
| 29 | + |
| 30 | + header("Aavegotchi Contracts Doctor"); |
| 31 | + |
| 32 | + header("Repo Root"); |
| 33 | + console.log(repoRoot); |
| 34 | + |
| 35 | + header("Node"); |
| 36 | + console.log(`node ${process.version}`); |
| 37 | + |
| 38 | + header("Submodules"); |
| 39 | + const forgeStdPath = path.join(repoRoot, "lib", "forge-std"); |
| 40 | + if (!fs.existsSync(forgeStdPath)) { |
| 41 | + failures.push("Missing submodule: lib/forge-std"); |
| 42 | + console.error("Expected git submodules to be initialized."); |
| 43 | + console.error("Run: git submodule update --init --recursive"); |
| 44 | + } else { |
| 45 | + console.log("OK: lib/forge-std present"); |
| 46 | + } |
| 47 | + |
| 48 | + header("Environment"); |
| 49 | + const envPath = path.join(repoRoot, ".env"); |
| 50 | + if (fs.existsSync(envPath)) { |
| 51 | + require("dotenv").config({ path: envPath }); |
| 52 | + console.log("Loaded .env"); |
| 53 | + } else { |
| 54 | + console.log("No .env found (this is OK for some workflows)."); |
| 55 | + } |
| 56 | + |
| 57 | + // Many workflows/tests use a local Base mainnet fork (Hardhat hardhat network). |
| 58 | + // BASE_RPC_URL is required for fork-based tests and may also be required by hardhat config. |
| 59 | + const requiredEnv = ["BASE_RPC_URL"]; |
| 60 | + const missingEnv = requiredEnv.filter((k) => { |
| 61 | + const v = process.env[k]; |
| 62 | + return typeof v !== "string" || v.trim().length === 0; |
| 63 | + }); |
| 64 | + if (missingEnv.length > 0) { |
| 65 | + failures.push(`Missing env vars: ${missingEnv.join(", ")}`); |
| 66 | + console.error(`Missing required environment variables: ${missingEnv.join(", ")}`); |
| 67 | + console.error("Create a local .env file (ignored by git) and set these values."); |
| 68 | + console.error("If this repo has a .env.example, start with: cp .env.example .env"); |
| 69 | + } else { |
| 70 | + console.log(`OK: required env vars present: ${requiredEnv.join(", ")}`); |
| 71 | + } |
| 72 | + |
| 73 | + header("Foundry"); |
| 74 | + if (!run("forge", ["--version"], { cwd: repoRoot }).ok) { |
| 75 | + failures.push("Foundry not available (forge not found)"); |
| 76 | + console.error("Install Foundry: https://book.getfoundry.sh/getting-started/installation"); |
| 77 | + } else { |
| 78 | + if (!run("forge", ["build", "--sizes"], { cwd: repoRoot }).ok) { |
| 79 | + failures.push("forge build failed"); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + header("Hardhat"); |
| 84 | + if (!run("npx", ["hardhat", "compile"], { cwd: repoRoot }).ok) { |
| 85 | + failures.push("hardhat compile failed"); |
| 86 | + } |
| 87 | + |
| 88 | + header("Result"); |
| 89 | + if (failures.length > 0) { |
| 90 | + console.error("Doctor found issues:"); |
| 91 | + for (const f of failures) console.error(`- ${f}`); |
| 92 | + process.exit(1); |
| 93 | + } |
| 94 | + |
| 95 | + console.log("OK: environment looks healthy"); |
| 96 | +} |
| 97 | + |
| 98 | +main(); |
| 99 | + |
0 commit comments