Cleaned script
This commit is contained in:
parent
4f79c73cd3
commit
a0a1e4626b
|
@ -18,7 +18,7 @@ const SOURCE_DIRECTORY = "images";
|
|||
const DESTINATION_DIRECTORY = path.join("public", "images");
|
||||
const ALREADY_OPTIMIZED_SAVE_FILE_PATH = path.join(
|
||||
"scripts",
|
||||
"optimize-images-already-optimized-files.json"
|
||||
"already-optimized-images.json"
|
||||
);
|
||||
|
||||
console.log(ALREADY_OPTIMIZED_SAVE_FILE_PATH);
|
||||
|
@ -73,8 +73,10 @@ export async function optimizeImages() {
|
|||
|
||||
await Promise.all(
|
||||
imagePaths.map(async (imagePath) => {
|
||||
const num = `- ${imagePath}`;
|
||||
console.time(`overall-timer${num} -`);
|
||||
console.log(`Optimizing file ${imagePath}`);
|
||||
const timerName = `File ${imagePath} took: `;
|
||||
console.time(timerName);
|
||||
|
||||
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
|
||||
const destinationPath = path.join(DESTINATION_DIRECTORY, imagePath);
|
||||
const fileExtension = imagePath.split(".").pop() ?? "";
|
||||
|
@ -85,13 +87,11 @@ export async function optimizeImages() {
|
|||
return;
|
||||
}
|
||||
|
||||
console.time(`read-file-timer${num}`);
|
||||
const rawImageFile = await fse.readFile(sourcePath);
|
||||
console.timeEnd(`read-file-timer${num}`);
|
||||
|
||||
console.time(`hash-timer${num}`);
|
||||
const fileHash = SparkMD5.hash(rawImageFile.toString());
|
||||
|
||||
if (alreadyOptimizedImageHashes.has(fileHash)) {
|
||||
console.log(`Skipping ${imagePath}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ export async function optimizeImages() {
|
|||
const encodedImage = await ingestedImage.encodedWith[encoder];
|
||||
await fse.outputFile(destinationPath, encodedImage.binary);
|
||||
alreadyOptimizedImageHashes.add(fileHash);
|
||||
console.timeEnd(`overall-timer${num}`);
|
||||
console.timeEnd(timerName);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue