Skip to content

Commit

Permalink
Update with latest chains
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorjdawson committed Dec 7, 2021
1 parent aef6269 commit 16b7775
Show file tree
Hide file tree
Showing 5 changed files with 4,670 additions and 2,297 deletions.
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export {default as chains, Chain, ChainId, ChainName, NativeCurrency, Explorer } from './src'
export {
default as chains,
Chain,
ChainId,
ChainName,
NativeCurrency,
Explorer
} from './src'
30 changes: 18 additions & 12 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@ const getEnumKey = (chainName: string) => {
return enumKey // `${enumKey} = '${chainName}'`
}

const getBuildEnums = (chains: Chain[]) => chains.reduce( (enumStrings, chain, index, array) => {
const key = getEnumKey(chain.name)
const tail = index === array.length - 1 ? ' }': ', '
enumStrings[0] += `${key} = '${chain.name}'${tail}`
enumStrings[1] += `${key} = ${chain.chainId}${tail}`
return enumStrings
}, ['export enum ChainName { ', 'export enum ChainId { ']).join('\n')
const getBuildEnums = (chains: Chain[]) =>
chains
.reduce(
(enumStrings, chain, index, array) => {
const key = getEnumKey(chain.name)
const tail = index === array.length - 1 ? ' }' : ', '
enumStrings[0] += `${key} = '${chain.name}'${tail}`
enumStrings[1] += `${key} = ${chain.chainId}${tail}`
return enumStrings
},
['export enum ChainName { ', 'export enum ChainId { ']
)
.join('\n')

const generateEnumFile = async (chains: Chain[]) => {
fs.writeFile(
'./src/enums.ts',
format(
getBuildEnums(chains),
{ ...(prettierOptions as Options), parser: 'typescript' }
)
format(getBuildEnums(chains), {
...(prettierOptions as Options),
parser: 'typescript'
})
)
}

Expand All @@ -46,7 +52,7 @@ const generateChainsFile = async () => {
await generateEnumFile(chains)

const chainsJs = chains
.map(chain => `${chain.chainId}: ${inspect(chain)}`)
.map(chain => `${chain.chainId}: ${inspect(chain, { depth: null })}`)
.join(',\n')

fs.writeFile(
Expand Down
Loading

0 comments on commit 16b7775

Please sign in to comment.