added console logging to image script
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
6f6510a5ee
commit
5263c6880d
|
@ -28,4 +28,4 @@ yarn-error.log*
|
|||
/public/events.ics
|
||||
|
||||
# Images should be optimized
|
||||
/public/images
|
||||
# /public/images
|
|
@ -36,14 +36,19 @@ void optimizeImages();
|
|||
|
||||
export async function optimizeImages() {
|
||||
const imagePaths = await getFilePathsInDirectory(SOURCE_DIRECTORY);
|
||||
await fse.emptyDir(DESTINATION_DIRECTORY);
|
||||
// await fse.emptyDir(DESTINATION_DIRECTORY);
|
||||
|
||||
// maximum number of workers is 4 in order to avoid running out of memory
|
||||
const numberOfWorkers = Math.min(cpus().length, 4);
|
||||
const imagePool = new ImagePool(numberOfWorkers);
|
||||
|
||||
let count = 0;
|
||||
await Promise.all(
|
||||
imagePaths.map(async (imagePath) => {
|
||||
console.time(`on file ${imagePath}`);
|
||||
count += 1;
|
||||
const num = count;
|
||||
console.time(`overall-timer${num}`);
|
||||
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
|
||||
const destinationPath = path.join(DESTINATION_DIRECTORY, imagePath);
|
||||
const fileExtension = imagePath.split(".").pop() ?? "";
|
||||
|
@ -54,7 +59,10 @@ export async function optimizeImages() {
|
|||
return;
|
||||
}
|
||||
|
||||
console.time(`read-file-timer${num}`);
|
||||
const rawImageFile = await fse.readFile(sourcePath);
|
||||
console.timeEnd(`read-file-timer${num}`);
|
||||
|
||||
const ingestedImage = imagePool.ingestImage(rawImageFile);
|
||||
const { width, height } = getImageDimensions(rawImageFile);
|
||||
|
||||
|
@ -84,6 +92,7 @@ export async function optimizeImages() {
|
|||
|
||||
const encodedImage = await ingestedImage.encodedWith[encoder];
|
||||
await fse.outputFile(destinationPath, encodedImage.binary);
|
||||
console.timeEnd(`overall-timer${num}`);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue