Skip to content

Commit aa3ceed

Browse files
committed
refactor(build-assets): restructure image data loading logic
simplify and improve code readability by using structured arrays for image data, including `bodies`, `accessories`, `heads`, and `glasses`. This ensures a more maintainable and consistent implementation.
1 parent 1ded232 commit aa3ceed

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

scripts/build-assets.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ async function readRemoteImageData(): Promise<any> {
7979
const bodyCount = await readLilNounsDescriptorBodyCount(config, {})
8080
console.log('Number of bodies: ', bodyCount.toString(), '')
8181
if (bodyCount !== localImageData.images.bodies.length) {
82+
let bodies: { filename: string; data: string }[] = []
8283
for (let i = 0; i < bodyCount; i++) {
83-
localImageData.images.bodies[i].data =
84-
await readLilNounsDescriptorBodies(config, {
84+
bodies[i] = {
85+
filename: localImageData.images.bodies[i].filename ?? `body-${i}`,
86+
data: await readLilNounsDescriptorBodies(config, {
8587
args: [BigInt(i)],
86-
})
88+
}),
89+
}
8790
}
91+
localImageData.images.bodies = bodies
8892
}
8993

9094
const accessoryCount = await readLilNounsDescriptorAccessoryCount(
@@ -93,36 +97,47 @@ async function readRemoteImageData(): Promise<any> {
9397
)
9498
console.log('Number of accessories: ', accessoryCount.toString(), '')
9599
if (accessoryCount !== localImageData.images.accessories.length) {
100+
let accessories: { filename: string; data: string }[] = []
96101
for (let i = 0; i < accessoryCount; i++) {
97-
localImageData.images.accessories[i].data =
98-
await readLilNounsDescriptorAccessories(config, {
102+
accessories[i] = {
103+
filename:
104+
localImageData.images.accessories[i].filename ?? `accessory-${i}`,
105+
data: await readLilNounsDescriptorAccessories(config, {
99106
args: [BigInt(i)],
100-
})
107+
}),
108+
}
101109
}
110+
localImageData.images.accessories = accessories
102111
}
103112

104113
const headCount = await readLilNounsDescriptorHeadCount(config, {})
105114
console.log('Number of heads: ', headCount.toString(), '')
106115
if (headCount !== localImageData.images.heads.length) {
116+
let heads: { filename: string; data: string }[] = []
107117
for (let i = 0; i < headCount; i++) {
108-
localImageData.images.heads[i].data = await readLilNounsDescriptorHeads(
109-
config,
110-
{
118+
heads[i] = {
119+
filename: localImageData.images.heads[i].filename ?? `head-${i}`,
120+
data: await readLilNounsDescriptorHeads(config, {
111121
args: [BigInt(i)],
112-
},
113-
)
122+
}),
123+
}
114124
}
125+
localImageData.images.heads = heads
115126
}
116127

117128
const glassesCount = await readLilNounsDescriptorGlassesCount(config, {})
118129
console.log('Number of glasses: ', glassesCount.toString(), '')
119130
if (glassesCount !== localImageData.images.glasses.length) {
131+
let glasses: { filename: string; data: string }[] = []
120132
for (let i = 0; i < glassesCount; i++) {
121-
localImageData.images.glasses[i].data =
122-
await readLilNounsDescriptorGlasses(config, {
133+
glasses[i] = {
134+
filename: localImageData.images.glasses[i].filename ?? `glasses-${i}`,
135+
data: await readLilNounsDescriptorGlasses(config, {
123136
args: [BigInt(i)],
124-
})
137+
}),
138+
}
125139
}
140+
localImageData.images.glasses = glasses
126141
}
127142

128143
console.log('Successfully loaded image data')
@@ -137,8 +152,6 @@ async function readRemoteImageData(): Promise<any> {
137152
return localImageData
138153
}
139154

140-
// Create an immediately invoked async function expression (IIFE) to use await
141155
;(async () => {
142-
const remoteImageData = await readRemoteImageData()
143-
console.log('Image data stored in variable: remoteImageData')
156+
await readRemoteImageData()
144157
})()

0 commit comments

Comments
 (0)