@@ -8,35 +8,41 @@ let res = "export const contracts = {";
88let dirEntries : fs . Dirent [ ] = [ ] ;
99
1010try {
11- dirEntries . push ( ...fs . readdirSync (
12- path . join ( ".deploys" , "pinned-contracts" ) ,
13- { recursive : true , withFileTypes : true }
14- ) ) ;
15- dirEntries . push ( ...fs . readdirSync (
16- path . join ( ".deploys" , "deployed-contracts" ) ,
17- { recursive : true , withFileTypes : true }
18- ) ) ;
11+ dirEntries . push (
12+ ...fs . readdirSync ( path . join ( ".deploys" , "pinned-contracts" ) , { recursive : true , withFileTypes : true } ) ,
13+ ) ;
14+ dirEntries . push (
15+ ...fs . readdirSync ( path . join ( ".deploys" , "deployed-contracts" ) , { recursive : true , withFileTypes : true } ) ,
16+ ) ;
1917} catch ( e : unknown ) {
20- if ( e instanceof Error && "code" in e && e . code === "ENOENT" ) {
21- console . warn ( "No contracts found; remember to pin deployed contracts in Remix in order to use them from frontend" ) ;
22- process . exit ( ) ;
18+ // One of those dirs can not exist, and it's fine
19+ if ( ! ( e instanceof Error && "code" in e && e . code === "ENOENT" ) ) {
20+ throw e ;
2321 }
2422}
2523
24+ dirEntries = dirEntries . filter (
25+ ( entry ) => entry . isFile ( ) && entry . name . startsWith ( "0x" ) && entry . name . endsWith ( ".json" ) ,
26+ ) ;
27+
28+ if ( dirEntries . length === 0 ) {
29+ console . warn (
30+ "No contracts found; remember to pin deployed contracts in Remix or build them locally, in order to use them from frontend" ,
31+ ) ;
32+ process . exit ( ) ;
33+ }
34+
2635for ( const entry of dirEntries ) {
27- if ( entry . isFile ( ) && entry . name . startsWith ( "0x" ) && entry . name . endsWith ( ".json" ) ) {
28- const strippedAddress = entry . name . slice ( 2 , entry . name . length - 5 ) ;
36+ const strippedAddress = entry . name . slice ( 2 , entry . name . length - 5 ) ;
2937
30- console . log ( `Processing contract ${ strippedAddress } ` ) ;
38+ console . log ( `Processing contract ${ strippedAddress } ` ) ;
3139
32- const value = fs . readFileSync ( path . join ( entry . parentPath , entry . name ) , "utf-8" ) ;
33- res += `\n "${ strippedAddress } ": ${ value } ,\n` ;
34- }
40+ const value = fs . readFileSync ( path . join ( entry . parentPath , entry . name ) , "utf-8" ) ;
41+ res += `\n "${ strippedAddress } ": ${ value } ,\n` ;
3542}
3643
3744res += "};" ;
3845const outPath = path . join ( "dist" , "contracts.js" ) ;
3946fs . writeFileSync ( outPath , res ) ;
4047
4148console . log ( `Exported contracts to ${ outPath } ` ) ;
42-
0 commit comments