Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions packages/cli/src/commands/build/build.schema.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import z from "zod";

export const buildConfigSchema = z.object({
manifest: z.object({
prefix: z
.string()
.describe("Default prefix for documentation links")
.default("docs/references"),
enabled: z
.boolean()
.describe("Whether to generate manifest.json file")
.default(true),
path: z
.string()
.describe(
"Path to save manifest file (relative to project root or absolute path). If not specified, uses outputDir/manifest.json",
)
.optional(),
}),
manifest: z
.object({
prefix: z
.string()
.describe("Default prefix for documentation links")
.default("docs/references"),
enabled: z
.boolean()
.describe("Whether to generate manifest.json file")
.default(true),
path: z
.string()
.describe(
"Path to save manifest file (relative to project root or absolute path). If not specified, uses outputDir/manifest.json",
)
.optional(),
})
.default({}),
outputDir: z
.string()
.describe("Directory where build output will be saved")
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/check/check.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { z } from "zod";

export const checkConfigSchema = z.object({
entryPoints: z.array(z.string()).optional().describe("Entry points to check"),
});
export const checkConfigSchema = z
.object({
entryPoints: z.array(z.string()).optional().describe("Entry points to check"),
})
.default({});
7 changes: 5 additions & 2 deletions packages/cli/src/config/config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const configSchema = z.object({
.describe("Package patterns to include in build"),
exclude: z
.array(z.string())
.describe("Package patterns to exclude from build"),
.describe("Package patterns to exclude from build")
.default([]),
}),
}),
commands: z.object({
Expand Down Expand Up @@ -58,4 +59,6 @@ export const configSchema = z.object({
* @param {function} plugins.plugin Factory function that returns plugin instance
* @param {object} [plugins.options] Plugin options
*/
export type Config = z.infer<typeof configSchema>;
export type Config = z.input<typeof configSchema>;

export type ResolvedConfig = z.output<typeof configSchema>;
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/load-plugins.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from "./types/plugin.types.js";
import { Config } from "../config/config.schema.js";
import { ResolvedConfig } from "../config/config.schema.js";

export async function loadPlugins(config: Config): Promise<Plugin[]> {
export async function loadPlugins(config: ResolvedConfig): Promise<Plugin[]> {
const plugins: Plugin[] = [];

for (const pluginConfig of config.plugins) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MarkdownGenerator } from "../core/types/generator.types.js";
import { createVitePressPlugin } from "./builtin/vitepress-plugin.js";
import path from "path";

import { Config } from "../config/config.schema.js";
import { ResolvedConfig } from "../config/config.schema.js";

export class PluginManager {
private plugins: Plugin[] = [];
Expand Down Expand Up @@ -32,7 +32,7 @@ export class PluginManager {
}, manifest);
}

getGenerator(config: Config): MarkdownGenerator {
getGenerator(config: ResolvedConfig): MarkdownGenerator {
const generatorConfig = config.commands.build.generator;

if (generatorConfig.name === "vitepress") {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/types/plugin.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SidebarItem } from "../../commands/build/manifest/manifest.js";
import { Config } from "../../config/config.schema.js";
import { ResolvedConfig } from "../../config/config.schema.js";
import { MarkdownGenerator } from "../../core/types/generator.types.js";

/**
Expand All @@ -15,7 +15,7 @@ import { MarkdownGenerator } from "../../core/types/generator.types.js";
*/
export interface PluginContext {
workspacePath?: string;
config?: Config;
config?: ResolvedConfig;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions packages/cli/src/tests/plugin/plugin-loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { loadPlugins } from "../../plugins/load-plugins.js";
import { createE2EWorkspace, E2EWorkspace } from "../utils/create-e2e-workspace.js";
import { Config } from "../../config/config.schema.js";
import { configSchema } from "../../config/config.schema.js";
import { SidebarItem } from "../../commands/build/manifest/manifest.js";
import { MOCK_CONFIG } from "../__mock__/config.mock.js";

Expand Down Expand Up @@ -31,7 +31,7 @@ export default {
`
);

const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
Expand All @@ -44,7 +44,7 @@ export default {
(await import(`${workspace.root}/my-plugin.js`)).default,
},
],
};
});

const plugins = await loadPlugins(config);

Expand All @@ -70,7 +70,7 @@ export const myNamedPlugin = {
`
);

const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
Expand All @@ -83,7 +83,7 @@ export const myNamedPlugin = {
(await import(`${workspace.root}/named-plugin.js`)).myNamedPlugin,
},
],
};
});

const plugins = await loadPlugins(config);

Expand All @@ -94,7 +94,7 @@ export const myNamedPlugin = {

it("should load inline plugin", async () => {
const workspace = await createE2EWorkspace();
const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
Expand All @@ -113,7 +113,7 @@ export const myNamedPlugin = {
}),
},
],
};
});

const plugins = await loadPlugins(config);

Expand All @@ -124,14 +124,14 @@ export const myNamedPlugin = {

it("should handle empty plugin list", async () => {
const workspace = await createE2EWorkspace();
const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
root: workspace.root,
},
plugins: [],
};
});

const plugins = await loadPlugins(config);

Expand All @@ -140,7 +140,7 @@ export const myNamedPlugin = {

it("should throw error for missing plugin file", async () => {
const workspace = await createE2EWorkspace();
const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
Expand All @@ -153,7 +153,7 @@ export const myNamedPlugin = {
(await import(`${workspace.root}/nonexistent.js`)).default,
},
],
};
});

await expect(loadPlugins(config)).rejects.toThrow(
"Failed to load plugin 'missing-plugin'"
Expand All @@ -162,7 +162,7 @@ export const myNamedPlugin = {

it("should throw error for plugin without path or hooks", async () => {
const workspace = await createE2EWorkspace();
const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
Expand All @@ -174,7 +174,7 @@ export const myNamedPlugin = {
plugin: null as unknown as () => Promise<unknown>,
},
],
};
});

await expect(loadPlugins(config)).rejects.toThrow(
"pluginConfig.plugin is not a function"
Expand All @@ -190,7 +190,7 @@ export default "not a plugin object";
`
);

const config: Config = {
const config = configSchema.parse({
...MOCK_CONFIG,
project: {
...MOCK_CONFIG.project,
Expand All @@ -203,7 +203,7 @@ export default "not a plugin object";
(await import(`${workspace.root}/invalid-plugin.js`)).default,
},
],
};
});

await expect(loadPlugins(config)).rejects.toThrow(
"did not return a valid plugin object"
Expand Down