feat(emitter): BuildOnly

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-11-11 19:57:49 -05:00
parent 1ab9c91df1
commit 8df53a8542
No known key found for this signature in database
GPG Key ID: 18974753009D2BFA
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import { QuartzComponent } from "../../components/types"
import DepGraph from "../../depgraph"
import { BuildCtx } from "../../util/ctx"
import { FilePath } from "../../util/path"
import { StaticResources } from "../../util/resources"
import { QuartzEmitterPlugin, QuartzEmitterPluginInstance } from "../types"
import { ProcessedContent } from "../vfile"
interface Options {
emitter: QuartzEmitterPluginInstance
}
export const BuildOnly: QuartzEmitterPlugin<Options> = (opts) => {
const emitter = opts?.emitter as QuartzEmitterPluginInstance
return {
name: `BuildOnly<${emitter.name}>`,
getQuartzComponents(ctx: BuildCtx): QuartzComponent[] {
if (ctx.argv.serve) return []
return emitter.getQuartzComponents(ctx)
},
async getDependencyGraph(
ctx: BuildCtx,
content: ProcessedContent[],
resources: StaticResources,
) {
if (ctx.argv.serve) return new DepGraph<FilePath>()
return await emitter.getDependencyGraph!(ctx, content, resources)
},
async emit(ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources) {
if (ctx.argv.serve) return []
return emitter.emit(ctx, content, resources)
},
}
}

View File

@ -8,3 +8,4 @@ export { Static } from "./static"
export { ComponentResources } from "./componentResources"
export { NotFoundPage } from "./404"
export { CNAME } from "./cname"
export { BuildOnly } from "./build"