Skip to content

Commit

Permalink
Modify structure of published metadata again
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Jun 15, 2024
1 parent 6ab7ebb commit 4d75b60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.3",
"files": [
"index.ts",
"publish",
"contracts",
"!contracts/mock"
],
Expand Down
26 changes: 19 additions & 7 deletions scripts/prepublish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ npm run test

npx hardhat export --export-all deployments.json

rm index.ts
rm -rf publish && mkdir publish

# Step 1: Remove the `abi`, `name`, and `chainId` keys
jq 'walk(if type == "object" then del(.abi, .name, .chainId) else . end)' deployments.json > temp_addresses.json
jq 'to_entries | map({key: .key, value: .value[0]}) | from_entries' temp_addresses.json > addresses.json
# Step 2: Replace array with its single object item
jq 'to_entries | map({key: .key, value: .value[0]}) | from_entries' temp_addresses.json > temp_flat_addresses.json
# Step 3: Flatten the structure to remove bottom level objects
jq 'to_entries | map({key: .key, value: .value.contracts | map_values(.address)}) | from_entries' temp_flat_addresses.json > addresses.json
# Step 4: Wrap the JSON content in TypeScript format and append "as const;"
echo "export default $(cat addresses.json) as const;" > publish/addresses.ts
rm temp_addresses.json addresses.json
# Step 5: Cleanup
rm temp_addresses.json temp_flat_addresses.json addresses.json


jq '."1"[0].contracts' deployments.json > temp_abis.json
jq 'to_entries | map({key: .key, value: {abi: .value.abi}}) | from_entries' temp_abis.json > abis.json
# Step 1: Extract `abi` values directly under each contract key
jq '."1"[0].contracts | to_entries | map({key: .key, value: .value.abi}) | from_entries' deployments.json > abis.json
# Step 2: Wrap the JSON content in TypeScript format and append "as const;"
echo "export default $(cat abis.json) as const;" > publish/abis.ts
rm temp_abis.json abis.json
# Step 3: Cleanup
rm abis.json

rm deployments.json

cat << EOF > index.ts
import abis from "./publish/abis.ts";
import addresses from "./publish/addresses.ts";
import abis from "./publish/abis";
import addresses from "./publish/addresses";
export { abis, addresses };
EOF

0 comments on commit 4d75b60

Please sign in to comment.