From 4d75b601407377e2427918ff140788532f0434ad Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Sat, 15 Jun 2024 00:22:00 -0400 Subject: [PATCH] Modify structure of published metadata again --- package.json | 1 + scripts/prepublish.sh | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e385dfd2..b086132c 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.1.3", "files": [ "index.ts", + "publish", "contracts", "!contracts/mock" ], diff --git a/scripts/prepublish.sh b/scripts/prepublish.sh index 0788d032..b0cd4224 100755 --- a/scripts/prepublish.sh +++ b/scripts/prepublish.sh @@ -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