(tokenDefinitions: TokenDefinition[])
| 304 | } |
| 305 | |
| 306 | async function writeTokenSets(tokenDefinitions: TokenDefinition[]) { |
| 307 | const allNames = getDefinitionExports(tokenDefinitions) |
| 308 | const tempoNames = tokenDefinitions |
| 309 | .map((token) => token.importName) |
| 310 | .sort((a, b) => a.localeCompare(b)) |
| 311 | const popularNames = allNames.filter((name) => { |
| 312 | const file = new URL(`${name}.ts`, definitionsDir) |
| 313 | return /\bpopular:\s*true\b/.test(readFileSync(file, 'utf8')) |
| 314 | }) |
| 315 | |
| 316 | const list = (names: string[]) => |
| 317 | names.length === 0 |
| 318 | ? '[] as const satisfies Tokens' |
| 319 | : `[\n${names.map((name) => ` ${name},`).join('\n')}\n] as const satisfies Tokens` |
| 320 | |
| 321 | await Bun.write( |
| 322 | tokenSetsFile, |
| 323 | `${generatedBanner} |
| 324 | |
| 325 | import type { Tokens } from './defineToken.js' |
| 326 | ${allNames.map((name) => `import { ${name} } from './definitions/${name}.js'`).join('\n')} |
| 327 | |
| 328 | /** Every token definition. */ |
| 329 | const all = ${list(allNames)} |
| 330 | |
| 331 | /** Tokens flagged as popular. */ |
| 332 | const popular = ${list(popularNames)} |
| 333 | |
| 334 | /** All tokens available on Tempo chains. */ |
| 335 | const tempo = ${list(tempoNames)} |
| 336 | |
| 337 | /** Curated token sets that can be passed to a Client's \`tokens\` property. */ |
| 338 | export const tokens = { all, popular, tempo } |
| 339 | `, |
| 340 | ) |
| 341 | } |
| 342 | |
| 343 | function getTokenDefinitionSource(token: TokenDefinition) { |
| 344 | const addresses = Array.from(token.addresses.entries()) |
no test coverage detected