@@ -30,6 +30,22 @@ function readLocalImageData(): any {
30
30
}
31
31
}
32
32
33
+ // Function to write the image data back to the JSON file
34
+ function writeLocalImageData ( imageData : any ) : void {
35
+ try {
36
+ // Convert the data to a JSON string with proper formatting
37
+ const jsonData = JSON . stringify ( imageData , null , 2 )
38
+
39
+ // Write the data back to the file
40
+ fs . writeFileSync ( './src/assets/image-data.json' , jsonData , 'utf8' )
41
+
42
+ console . log ( 'Successfully wrote image data to file' )
43
+ } catch ( error ) {
44
+ console . error ( 'Error writing image data:' , error )
45
+ throw error
46
+ }
47
+ }
48
+
33
49
async function readRemoteImageData ( ) : Promise < any > {
34
50
const localImageData = readLocalImageData ( )
35
51
@@ -69,7 +85,6 @@ async function readRemoteImageData(): Promise<any> {
69
85
args : [ BigInt ( i ) ] ,
70
86
} )
71
87
}
72
- console . log ( 'Bodies: ' , localImageData . images . bodies )
73
88
}
74
89
75
90
const accessoryCount = await readLilNounsDescriptorAccessoryCount (
@@ -84,7 +99,6 @@ async function readRemoteImageData(): Promise<any> {
84
99
args : [ BigInt ( i ) ] ,
85
100
} )
86
101
}
87
- console . log ( 'Accessories: ' , localImageData . images . accessories )
88
102
}
89
103
90
104
const headCount = await readLilNounsDescriptorHeadCount ( config , { } )
@@ -98,7 +112,6 @@ async function readRemoteImageData(): Promise<any> {
98
112
} ,
99
113
)
100
114
}
101
- console . log ( 'Heads: ' , localImageData . images . heads )
102
115
}
103
116
104
117
const glassesCount = await readLilNounsDescriptorGlassesCount ( config , { } )
@@ -110,14 +123,18 @@ async function readRemoteImageData(): Promise<any> {
110
123
args : [ BigInt ( i ) ] ,
111
124
} )
112
125
}
113
- console . log ( 'Glasses: ' , localImageData . images . glasses )
114
126
}
115
127
116
128
console . log ( 'Successfully loaded image data' )
117
129
} catch ( error ) {
118
130
console . error ( 'Error reading image data:' , error )
119
131
throw error
120
132
}
133
+
134
+ // After all updates are complete, write the data back to the file
135
+ writeLocalImageData ( localImageData )
136
+
137
+ return localImageData
121
138
}
122
139
123
140
// Create an immediately invoked async function expression (IIFE) to use await
0 commit comments