@@ -4,7 +4,6 @@ import crypto from 'crypto';
44
55interface ExternalTokenList {
66 name : string ;
7- chainIds : number [ ] ;
87 url : string ;
98}
109
@@ -46,29 +45,22 @@ async function checkExternalTokenLists() {
4645 process . exit ( 1 ) ;
4746 }
4847
49- // Validate chainIds are all numbers
50- for ( const tokenList of externalData . externalTokenLists ) {
51- if ( ! Array . isArray ( tokenList . chainIds ) ) {
52- console . error ( `Error: chainIds for ${ tokenList . name } is not an array` ) ;
53- process . exit ( 1 ) ;
54- }
55-
56- const nonNumberChainIds = tokenList . chainIds . filter ( id => typeof id !== 'number' ) ;
57- if ( nonNumberChainIds . length > 0 ) {
58- console . error ( `Error: Non-number chainIds found for ${ tokenList . name } : ${ nonNumberChainIds . join ( ', ' ) } ` ) ;
59- process . exit ( 1 ) ;
60- }
61- }
62-
6348 // Create the _external directory if it doesn't exist
6449 const externalDir = path . join ( process . cwd ( ) , 'index' , '_external' ) ;
6550 if ( ! fs . existsSync ( externalDir ) ) {
6651 fs . mkdirSync ( externalDir , { recursive : true } ) ;
52+ } else {
53+ // Empty the directory first
54+ const existingFiles = fs . readdirSync ( externalDir ) ;
55+ for ( const file of existingFiles ) {
56+ fs . unlinkSync ( path . join ( externalDir , file ) ) ;
57+ }
58+ console . log ( `Cleared ${ existingFiles . length } files from _external directory` ) ;
6759 }
6860
6961 // Check each URL
7062 const results = await Promise . allSettled (
71- externalData . externalTokenLists . map ( async ( tokenList ) => {
63+ externalData . externalTokenLists . map ( async ( tokenList , index ) => {
7264 try {
7365 console . log ( `Fetching ${ tokenList . name } from ${ tokenList . url } ...` ) ;
7466 const response = await fetch ( tokenList . url , { redirect : 'follow' } ) ;
@@ -92,8 +84,8 @@ async function checkExternalTokenLists() {
9284 // Validate JSON
9385 const jsonData = JSON . parse ( text ) ;
9486
95- // Write the file to disk
96- const fileName = `${ tokenList . name } .json` ;
87+ // Write the file to disk with numbered prefix to maintain order
88+ const fileName = `${ index + 1 } - ${ tokenList . name } .json` ;
9789 const filePath = path . join ( externalDir , fileName ) ;
9890 fs . writeFileSync ( filePath , JSON . stringify ( jsonData , null , 2 ) ) ;
9991
0 commit comments