mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
feat: add progress to asset generation (#8357)
This commit is contained in:
parent
b74dacdb6a
commit
6b1e798146
3 changed files with 24 additions and 14 deletions
6
.changeset/polite-scissors-invent.md
Normal file
6
.changeset/polite-scissors-invent.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Added counter to show progress for assets image generation.
|
||||||
|
Fixed small unit of measurement error.
|
|
@ -155,12 +155,12 @@ export async function generateImage(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStaticImageList(): Iterable<
|
export function getStaticImageList(): Map<
|
||||||
[string, { path: string; options: ImageTransform }]
|
string, { path: string; options: ImageTransform }
|
||||||
> {
|
> {
|
||||||
if (!globalThis?.astroAsset?.staticImages) {
|
if (!globalThis?.astroAsset?.staticImages) {
|
||||||
return [];
|
return new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
return globalThis.astroAsset.staticImages?.entries();
|
return globalThis.astroAsset.staticImages;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,9 +196,12 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(null, `\n${bgGreen(black(` generating optimized images `))}`);
|
const staticImageList = getStaticImageList()
|
||||||
for (const imageData of getStaticImageList()) {
|
|
||||||
await generateImage(pipeline, imageData[1].options, imageData[1].path);
|
if (staticImageList.size) logger.info(null, `\n${bgGreen(black(` generating optimized images `))}`); let count = 0;
|
||||||
|
for (const imageData of staticImageList.entries()) {
|
||||||
|
count++
|
||||||
|
await generateImage(pipeline, imageData[1].options, imageData[1].path, count, staticImageList.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete globalThis?.astroAsset?.addStaticImage;
|
delete globalThis?.astroAsset?.addStaticImage;
|
||||||
|
@ -211,7 +214,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
|
||||||
logger.info(null, dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`));
|
logger.info(null, dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateImage(pipeline: BuildPipeline, transform: ImageTransform, path: string) {
|
async function generateImage(pipeline: BuildPipeline, transform: ImageTransform, path: string, count: number, totalCount: number) {
|
||||||
const logger = pipeline.getLogger();
|
const logger = pipeline.getLogger();
|
||||||
let timeStart = performance.now();
|
let timeStart = performance.now();
|
||||||
const generationData = await generateImageInternal(pipeline, transform, path);
|
const generationData = await generateImageInternal(pipeline, transform, path);
|
||||||
|
@ -225,8 +228,9 @@ async function generateImage(pipeline: BuildPipeline, transform: ImageTransform,
|
||||||
const timeIncrease = `(+${timeChange})`;
|
const timeIncrease = `(+${timeChange})`;
|
||||||
const statsText = generationData.cached
|
const statsText = generationData.cached
|
||||||
? `(reused cache entry)`
|
? `(reused cache entry)`
|
||||||
: `(before: ${generationData.weight.before}kb, after: ${generationData.weight.after}kb)`;
|
: `(before: ${generationData.weight.before}kB, after: ${generationData.weight.after}kB)`;
|
||||||
logger.info(null, ` ${green('▶')} ${path} ${dim(statsText)} ${dim(timeIncrease)}`);
|
const counter = `(${count}/${totalCount})`;
|
||||||
|
logger.info(null, ` ${green('▶')} ${path} ${dim(statsText)} ${dim(timeIncrease)} ${dim(counter)}}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generatePage(
|
async function generatePage(
|
||||||
|
@ -390,10 +394,10 @@ function getInvalidRouteSegmentError(
|
||||||
...AstroErrorData.InvalidDynamicRoute,
|
...AstroErrorData.InvalidDynamicRoute,
|
||||||
message: invalidParam
|
message: invalidParam
|
||||||
? AstroErrorData.InvalidDynamicRoute.message(
|
? AstroErrorData.InvalidDynamicRoute.message(
|
||||||
route.route,
|
route.route,
|
||||||
JSON.stringify(invalidParam),
|
JSON.stringify(invalidParam),
|
||||||
JSON.stringify(received)
|
JSON.stringify(received)
|
||||||
)
|
)
|
||||||
: `Generated path for ${route.route} is invalid.`,
|
: `Generated path for ${route.route} is invalid.`,
|
||||||
hint,
|
hint,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue