Skip to content

Commit 1ded232

Browse files
committed
refactor(scripts): add function to persist image data
introduce `writeLocalImageData` to save updated image data to file; removes redundant `console.log` statements. ensures image data is consistently saved and improves code clarity.
1 parent 41abdae commit 1ded232

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

scripts/build-assets.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ function readLocalImageData(): any {
3030
}
3131
}
3232

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+
3349
async function readRemoteImageData(): Promise<any> {
3450
const localImageData = readLocalImageData()
3551

@@ -69,7 +85,6 @@ async function readRemoteImageData(): Promise<any> {
6985
args: [BigInt(i)],
7086
})
7187
}
72-
console.log('Bodies: ', localImageData.images.bodies)
7388
}
7489

7590
const accessoryCount = await readLilNounsDescriptorAccessoryCount(
@@ -84,7 +99,6 @@ async function readRemoteImageData(): Promise<any> {
8499
args: [BigInt(i)],
85100
})
86101
}
87-
console.log('Accessories: ', localImageData.images.accessories)
88102
}
89103

90104
const headCount = await readLilNounsDescriptorHeadCount(config, {})
@@ -98,7 +112,6 @@ async function readRemoteImageData(): Promise<any> {
98112
},
99113
)
100114
}
101-
console.log('Heads: ', localImageData.images.heads)
102115
}
103116

104117
const glassesCount = await readLilNounsDescriptorGlassesCount(config, {})
@@ -110,14 +123,18 @@ async function readRemoteImageData(): Promise<any> {
110123
args: [BigInt(i)],
111124
})
112125
}
113-
console.log('Glasses: ', localImageData.images.glasses)
114126
}
115127

116128
console.log('Successfully loaded image data')
117129
} catch (error) {
118130
console.error('Error reading image data:', error)
119131
throw error
120132
}
133+
134+
// After all updates are complete, write the data back to the file
135+
writeLocalImageData(localImageData)
136+
137+
return localImageData
121138
}
122139

123140
// Create an immediately invoked async function expression (IIFE) to use await

0 commit comments

Comments
 (0)