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