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
|
/public/events.ics
|
||||||
|
|
||||||
# Images should be optimized
|
# Images should be optimized
|
||||||
/public/images
|
# /public/images
|
|
@ -36,14 +36,19 @@ void optimizeImages();
|
||||||
|
|
||||||
export async function optimizeImages() {
|
export async function optimizeImages() {
|
||||||
const imagePaths = await getFilePathsInDirectory(SOURCE_DIRECTORY);
|
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
|
// maximum number of workers is 4 in order to avoid running out of memory
|
||||||
const numberOfWorkers = Math.min(cpus().length, 4);
|
const numberOfWorkers = Math.min(cpus().length, 4);
|
||||||
const imagePool = new ImagePool(numberOfWorkers);
|
const imagePool = new ImagePool(numberOfWorkers);
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
imagePaths.map(async (imagePath) => {
|
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 sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
|
||||||
const destinationPath = path.join(DESTINATION_DIRECTORY, imagePath);
|
const destinationPath = path.join(DESTINATION_DIRECTORY, imagePath);
|
||||||
const fileExtension = imagePath.split(".").pop() ?? "";
|
const fileExtension = imagePath.split(".").pop() ?? "";
|
||||||
|
@ -54,7 +59,10 @@ export async function optimizeImages() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.time(`read-file-timer${num}`);
|
||||||
const rawImageFile = await fse.readFile(sourcePath);
|
const rawImageFile = await fse.readFile(sourcePath);
|
||||||
|
console.timeEnd(`read-file-timer${num}`);
|
||||||
|
|
||||||
const ingestedImage = imagePool.ingestImage(rawImageFile);
|
const ingestedImage = imagePool.ingestImage(rawImageFile);
|
||||||
const { width, height } = getImageDimensions(rawImageFile);
|
const { width, height } = getImageDimensions(rawImageFile);
|
||||||
|
|
||||||
|
@ -84,6 +92,7 @@ export async function optimizeImages() {
|
||||||
|
|
||||||
const encodedImage = await ingestedImage.encodedWith[encoder];
|
const encodedImage = await ingestedImage.encodedWith[encoder];
|
||||||
await fse.outputFile(destinationPath, encodedImage.binary);
|
await fse.outputFile(destinationPath, encodedImage.binary);
|
||||||
|
console.timeEnd(`overall-timer${num}`);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue