Skip to content

Commit

Permalink
fix: rename NodeType to MergeType, add s
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Jan 13, 2025
1 parent 28b1398 commit d60b4ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { uniqWith } from 'lodash';
import { AbiEvent, AbiFunction, type Abi } from 'abitype';

export type NodeType = 'event' | 'function';
export type MergeType = 'events' | 'functions';

export type AbiNode = AbiEvent | AbiFunction;

Expand All @@ -13,7 +13,7 @@ const nodesAreEqual = (nodeA: AbiNode, nodeB: AbiNode) =>
nodeA.name === nodeB.name &&
stringifyInputTypes(nodeA) === stringifyInputTypes(nodeB);

export const joinAbis = (abiA: Abi, abiB: Abi, nodeType: NodeType) => {
export const joinAbis = (abiA: Abi, abiB: Abi, nodeType: MergeType) => {
return uniqWith(
(abiA as AbiNode[]).concat(
(abiB as AbiNode[]).filter(({ type }: { type: string }) => type === nodeType),
Expand Down
12 changes: 6 additions & 6 deletions scripts/extract-contract-abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fg from 'fast-glob';
import { sync as mkdirpSync } from 'mkdirp';
import _ from 'lodash';

import { type AbiNode, type NodeType, joinAbis } from '../lib/utils';
import { type AbiNode, type MergeType, joinAbis } from '../lib/utils';

import { latest as LATEST_TAG } from '../dist/versions.json';

Expand All @@ -30,11 +30,11 @@ const OUTPUT_DIR = resolvePath(__dirname, '../dist/versions');
const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);

// This builds artificial ABIs that contain all nodes of a certain type across all versions of a versioned contract. Exact duplicates are discarded
const buildJoinedAbis = async (tag: string, nodeType: NodeType) => {
const buildJoinedAbis = async (tag: string, mergeType: MergeType) => {
const targetDir =
tag === 'next'
? resolvePath(__dirname, `../dist/${nodeType}s/next`)
: resolvePath(__dirname, `../dist/${nodeType}s`);
? resolvePath(__dirname, `../dist/${mergeType}/next`)
: resolvePath(__dirname, `../dist/${mergeType}`);
const nodeAbis: Record<string, AbiNode[]> = {};
readdirSync(OUTPUT_DIR).forEach((tag: string) => {
readdirSync(resolvePath(OUTPUT_DIR, tag)).forEach((filename) => {
Expand All @@ -46,7 +46,7 @@ const buildJoinedAbis = async (tag: string, nodeType: NodeType) => {
if (!nodeAbis[contractName]) {
nodeAbis[contractName] = [];
}
nodeAbis[contractName] = joinAbis(nodeAbis[contractName], abi, nodeType);
nodeAbis[contractName] = joinAbis(nodeAbis[contractName], abi, mergeType);
} catch (err) {
console.error(err);
// ignore
Expand All @@ -60,7 +60,7 @@ const buildJoinedAbis = async (tag: string, nodeType: NodeType) => {
};
mkdirpSync(targetDir);
writeFileSync(
resolvePath(targetDir, `${contractName}${capitalize(nodeType)}s.json`),
resolvePath(targetDir, `${contractName}${capitalize(mergeType)}.json`),
JSON.stringify(result),
);
});
Expand Down

0 comments on commit d60b4ad

Please sign in to comment.