2023-08-17 12:04:15 +07:00
|
|
|
import { PerfTimer } from "../util/perf"
|
2023-07-24 08:20:43 +07:00
|
|
|
import { getStaticResourcesFromPlugins } from "../plugins"
|
2023-06-01 04:01:23 +07:00
|
|
|
import { ProcessedContent } from "../plugins/vfile"
|
2023-08-17 12:04:15 +07:00
|
|
|
import { QuartzLogger } from "../util/log"
|
|
|
|
import { trace } from "../util/trace"
|
|
|
|
import { BuildCtx } from "../util/ctx"
|
2023-07-03 03:08:29 +07:00
|
|
|
|
2023-07-24 07:09:12 +07:00
|
|
|
export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
|
|
|
|
const { argv, cfg } = ctx
|
2023-06-01 04:01:23 +07:00
|
|
|
const perf = new PerfTimer()
|
2023-07-24 07:07:19 +07:00
|
|
|
const log = new QuartzLogger(ctx.argv.verbose)
|
2023-07-05 00:08:32 +07:00
|
|
|
|
|
|
|
log.start(`Emitting output files`)
|
2023-06-01 04:01:23 +07:00
|
|
|
|
2023-07-23 06:06:36 +07:00
|
|
|
let emittedFiles = 0
|
2023-07-24 14:04:01 +07:00
|
|
|
const staticResources = getStaticResourcesFromPlugins(ctx)
|
2023-06-01 04:01:23 +07:00
|
|
|
for (const emitter of cfg.plugins.emitters) {
|
2023-06-05 00:37:43 +07:00
|
|
|
try {
|
2024-01-19 01:56:14 +07:00
|
|
|
const emitted = await emitter.emit(ctx, content, staticResources)
|
2023-06-05 00:37:43 +07:00
|
|
|
emittedFiles += emitted.length
|
2023-06-01 04:01:23 +07:00
|
|
|
|
2023-07-24 07:07:19 +07:00
|
|
|
if (ctx.argv.verbose) {
|
2023-06-05 00:37:43 +07:00
|
|
|
for (const file of emitted) {
|
|
|
|
console.log(`[emit:${emitter.name}] ${file}`)
|
|
|
|
}
|
2023-06-01 04:01:23 +07:00
|
|
|
}
|
2023-06-05 00:37:43 +07:00
|
|
|
} catch (err) {
|
2023-07-16 13:02:12 +07:00
|
|
|
trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
|
2023-06-01 04:01:23 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-24 07:07:19 +07:00
|
|
|
log.end(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
|
2023-06-01 04:01:23 +07:00
|
|
|
}
|