2026-02-13 12:18:49 +00:00
|
|
|
import type {
|
|
|
|
|
BuildCtx,
|
2026-04-03 13:53:22 +00:00
|
|
|
FilePath,
|
|
|
|
|
FullSlug,
|
2026-02-13 12:18:49 +00:00
|
|
|
QuartzConfig,
|
|
|
|
|
ProcessedContent,
|
|
|
|
|
QuartzPluginData,
|
|
|
|
|
} from "@quartz-community/types";
|
2026-04-03 13:53:22 +00:00
|
|
|
import { isFilePath, isFullSlug } from "@quartz-community/utils";
|
2026-02-06 16:23:54 +00:00
|
|
|
import { VFile } from "vfile";
|
|
|
|
|
|
|
|
|
|
type BuildCtxOverrides = Omit<Partial<BuildCtx>, "argv"> & {
|
|
|
|
|
argv?: Partial<BuildCtx["argv"]>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const createCtx = (overrides: BuildCtxOverrides = {}): BuildCtx => {
|
|
|
|
|
const { argv: argvOverrides, ...rest } = overrides;
|
|
|
|
|
const argv: BuildCtx["argv"] = {
|
|
|
|
|
directory: "content",
|
|
|
|
|
verbose: false,
|
|
|
|
|
output: "dist",
|
|
|
|
|
serve: false,
|
|
|
|
|
watch: false,
|
|
|
|
|
port: 0,
|
|
|
|
|
wsPort: 0,
|
|
|
|
|
...argvOverrides,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
buildId: "test-build",
|
|
|
|
|
argv,
|
|
|
|
|
cfg: {} as QuartzConfig,
|
|
|
|
|
allSlugs: [],
|
|
|
|
|
allFiles: [],
|
|
|
|
|
incremental: false,
|
|
|
|
|
...rest,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const createProcessedContent = (data: Partial<QuartzPluginData> = {}): ProcessedContent => {
|
|
|
|
|
const vfile = new VFile("");
|
|
|
|
|
vfile.data = data;
|
|
|
|
|
return [{ type: "root", children: [] }, vfile];
|
|
|
|
|
};
|
2026-04-03 13:53:22 +00:00
|
|
|
|
|
|
|
|
export const assertFilePath = (value: string): FilePath => {
|
|
|
|
|
if (!isFilePath(value)) {
|
|
|
|
|
throw new Error(`Invalid FilePath: ${value}`);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const assertFullSlug = (value: string): FullSlug => {
|
|
|
|
|
if (!isFullSlug(value)) {
|
|
|
|
|
throw new Error(`Invalid FullSlug: ${value}`);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|