mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 10:54:06 -06:00
made entire array emitter process async
This commit is contained in:
parent
ef25f903ca
commit
59b836bd79
@ -261,35 +261,35 @@ async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildD
|
|||||||
.map((file) => file.content),
|
.map((file) => file.content),
|
||||||
)
|
)
|
||||||
|
|
||||||
let emittedFiles = 0
|
const emittedFiles = await Promise.all(
|
||||||
for (const emitter of cfg.plugins.emitters) {
|
cfg.plugins.emitters.map(async (emitter) => {
|
||||||
// Try to use partialEmit if available, otherwise assume the output is static
|
const emitFn = emitter.partialEmit ?? emitter.emit
|
||||||
const emitFn = emitter.partialEmit ?? emitter.emit
|
const emitted = emitFn(ctx, processedFiles, staticResources, changeEvents)
|
||||||
const emitted = await emitFn(ctx, processedFiles, staticResources, changeEvents)
|
if (emitted === null) {
|
||||||
if (emitted === null) {
|
return 0
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Symbol.asyncIterator in emitted) {
|
|
||||||
// Async generator case
|
|
||||||
for await (const file of emitted) {
|
|
||||||
emittedFiles++
|
|
||||||
if (ctx.argv.verbose) {
|
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if (Symbol.asyncIterator in emitted) {
|
||||||
// Array case
|
let emittedFiles = 0
|
||||||
emittedFiles += emitted.length
|
// Async generator case
|
||||||
if (ctx.argv.verbose) {
|
for await (const file of emitted) {
|
||||||
for (const file of emitted) {
|
emittedFiles++
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
if (ctx.argv.verbose) {
|
||||||
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return emittedFiles
|
||||||
|
} else {
|
||||||
|
// Array case
|
||||||
|
return await Promise.all(
|
||||||
|
(await emitted).map((file) => {
|
||||||
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
|
}),
|
||||||
|
).then((files) => files.length)
|
||||||
}
|
}
|
||||||
}
|
}),
|
||||||
}
|
)
|
||||||
|
const sumFiles = emittedFiles.reduce((a, b) => a + b)
|
||||||
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
console.log(`Emitted ${sumFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
||||||
console.log(styleText("green", `Done rebuilding in ${perf.timeSince()}`))
|
console.log(styleText("green", `Done rebuilding in ${perf.timeSince()}`))
|
||||||
changes.splice(0, numChangesInBuild)
|
changes.splice(0, numChangesInBuild)
|
||||||
clientRefresh()
|
clientRefresh()
|
||||||
|
|||||||
@ -13,14 +13,14 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
|
|||||||
|
|
||||||
log.start(`Emitting files`)
|
log.start(`Emitting files`)
|
||||||
|
|
||||||
let emittedFiles = 0
|
|
||||||
const staticResources = getStaticResourcesFromPlugins(ctx)
|
const staticResources = getStaticResourcesFromPlugins(ctx)
|
||||||
await Promise.all(
|
const emittedFiles = await Promise.all(
|
||||||
cfg.plugins.emitters.map(async (emitter) => {
|
cfg.plugins.emitters.map(async (emitter) => {
|
||||||
try {
|
try {
|
||||||
const emitted = await emitter.emit(ctx, content, staticResources)
|
const emitted = emitter.emit(ctx, content, staticResources)
|
||||||
if (Symbol.asyncIterator in emitted) {
|
if (Symbol.asyncIterator in emitted) {
|
||||||
// Async generator case
|
// Async generator case
|
||||||
|
let emittedFiles = 0
|
||||||
for await (const file of emitted) {
|
for await (const file of emitted) {
|
||||||
emittedFiles++
|
emittedFiles++
|
||||||
if (ctx.argv.verbose) {
|
if (ctx.argv.verbose) {
|
||||||
@ -29,22 +29,27 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
|
|||||||
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return emittedFiles
|
||||||
} else {
|
} else {
|
||||||
// Array case
|
// Array case
|
||||||
emittedFiles += emitted.length
|
return (
|
||||||
for (const file of emitted) {
|
await Promise.all(
|
||||||
if (ctx.argv.verbose) {
|
(await emitted).map((file) => {
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
if (ctx.argv.verbose) {
|
||||||
} else {
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
} else {
|
||||||
}
|
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
).length
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
|
trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
const sumFiles = emittedFiles.reduce((a, b) => a + b)
|
||||||
log.end(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
|
log.end(`Emitted ${sumFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user