Skip to content

Commit

Permalink
Add script to build evm rpc types
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Dec 7, 2024
1 parent 4684b77 commit 802d294
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 17 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ coverage
# Build Outputs
.next/
out/
build
dist
build/
dist/
generated/

# Debug
npm-debug.log*
Expand Down
4 changes: 2 additions & 2 deletions packages/drift/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist
node_modules
execution-apis_temp.*
openrpc.json
18 changes: 7 additions & 11 deletions packages/drift/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@
},
"typesVersions": {
"*": {
".": [
"./dist/index.d.ts"
],
"testing": [
"./dist/testing.d.ts"
]
".": ["./dist/index.d.ts"],
"testing": ["./dist/testing.d.ts"]
}
},
"scripts": {
"build": "tsup",
"watch": "tsup --watch",
"build:evm-types": "sh scripts/buildEvmTypes.sh",
"build": "yarn build:evm-types && tsup",
"watch": "yarn build:evm-types && tsup --watch",
"test": "vitest run",
"test:watch": "vitest --reporter=verbose",
"coverage": "vitest run --coverage",
Expand All @@ -62,6 +59,7 @@
"safe-stable-stringify": "^2.5.0"
},
"devDependencies": {
"@open-rpc/typings": "^1.12.4",
"@repo/typescript-config": "*",
"@types/lodash.ismatch": "^4.4.9",
"@types/sinon": "^17.0.3",
Expand All @@ -85,7 +83,5 @@
"publishConfig": {
"access": "public"
},
"files": [
"dist"
]
"files": ["dist"]
}
50 changes: 50 additions & 0 deletions packages/drift/scripts/buildEvmTypes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -e

# Clones the ethereum/execution-apis repo and generates types from the open-rpc schema.
#
# Usage: $0 [branch] [repo_url]
#
# branch: The branch to clone. (default: $default_branch)
# repo_url: The url of the git repository to clone. (default: $default_repo_url)

# SETTINGS
default_branch="main"
default_repo_url="[email protected]:ethereum/execution-apis.git"
schema_doc="refs-openrpc.json"
src_dir="generated/execution-apis"

if [ ! -d "$src_dir" ]; then
branch=${1:-$default_branch}
repo_url=${2:-$default_repo_url}
temp_dir=$(mktemp -d "execution-apis_temp.XXXXXX")

# Echo settings
echo "Branch: $branch"
echo "Repo URL: $repo_url"
echo ""

git clone --depth 1 "$repo_url" --branch "$branch" "$temp_dir"

echo "Installing dependencies and generating OpenRPC schema..."
(
cd "$temp_dir"
npm i ci
npm run build
)
cp "$temp_dir/$schema_doc" openrpc.json

echo "Deleting temp clone..."
rm -rf "$temp_dir"
fi

echo "Generating types..."
if [ -d "$src_dir" ]; then
(
cd "$src_dir"
rm -rf ./*
)
else
mkdir -p "$src_dir"
fi
npx open-rpc-typings --output-ts "$src_dir"
Loading

0 comments on commit 802d294

Please sign in to comment.