@takazudo/zudo-doc 13.0.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/bin/zudo-doc.mjs +32 -0
- package/dist/config.d.ts +10 -27
- package/dist/doc-content-header/index.js +1 -1
- package/dist/doc-page-renderer/index.js +3 -1
- package/dist/doc-sources/types.d.ts +65 -0
- package/dist/doc-sources/types.js +0 -0
- package/dist/docs-schema/index.d.ts +3 -0
- package/dist/docs-schema/index.js +4 -0
- package/dist/frontmatter-preview-defaults/index.js +3 -0
- package/dist/i18n-defaults/index.js +36 -50
- package/dist/plugins/{codex-resources.d.ts → doc-sources.d.ts} +0 -1
- package/dist/plugins/doc-sources.js +40 -0
- package/dist/plugins/internal/doc-sources/discover.d.ts +33 -0
- package/dist/plugins/internal/doc-sources/discover.js +176 -0
- package/dist/plugins/internal/doc-sources/glob.d.ts +8 -0
- package/dist/plugins/internal/doc-sources/glob.js +80 -0
- package/dist/plugins/internal/doc-sources/labels.d.ts +8 -0
- package/dist/plugins/internal/doc-sources/labels.js +7 -0
- package/dist/plugins/internal/doc-sources/locale-routes.d.ts +6 -0
- package/dist/plugins/internal/doc-sources/locale-routes.js +8 -0
- package/dist/plugins/internal/doc-sources/model.d.ts +64 -0
- package/dist/plugins/internal/doc-sources/model.js +0 -0
- package/dist/plugins/internal/doc-sources/normalize.d.ts +20 -0
- package/dist/plugins/internal/doc-sources/normalize.js +192 -0
- package/dist/plugins/internal/doc-sources/plan.d.ts +28 -0
- package/dist/plugins/internal/doc-sources/plan.js +350 -0
- package/dist/plugins/internal/doc-sources/presets.d.ts +12 -0
- package/dist/plugins/internal/doc-sources/presets.js +182 -0
- package/dist/plugins/internal/doc-sources/reconcile.d.ts +20 -0
- package/dist/plugins/internal/doc-sources/reconcile.js +182 -0
- package/dist/plugins/internal/doc-sources/render/codex-agent.d.ts +2 -0
- package/dist/plugins/internal/doc-sources/render/codex-agent.js +45 -0
- package/dist/plugins/internal/doc-sources/render/codex-config.d.ts +2 -0
- package/dist/plugins/internal/doc-sources/render/codex-config.js +45 -0
- package/dist/plugins/internal/doc-sources/render/codex-hooks.d.ts +2 -0
- package/dist/plugins/internal/doc-sources/render/codex-hooks.js +66 -0
- package/dist/plugins/internal/doc-sources/render/codex-rules.d.ts +2 -0
- package/dist/plugins/internal/{codex-resources/rules.js → doc-sources/render/codex-rules.js} +16 -89
- package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/escape-for-mdx.js +1 -1
- package/dist/plugins/internal/doc-sources/render/frontmatter.d.ts +9 -0
- package/dist/plugins/internal/doc-sources/render/frontmatter.js +38 -0
- package/dist/plugins/internal/doc-sources/render/links.d.ts +25 -0
- package/dist/plugins/internal/doc-sources/render/links.js +109 -0
- package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.d.ts +4 -0
- package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.js +37 -1
- package/dist/plugins/internal/doc-sources/render/skill.d.ts +10 -0
- package/dist/plugins/internal/doc-sources/render/skill.js +97 -0
- package/dist/plugins/internal/doc-sources/render/types.d.ts +7 -0
- package/dist/plugins/internal/doc-sources/render/types.js +6 -0
- package/dist/plugins/internal/doc-sources/run.d.ts +53 -0
- package/dist/plugins/internal/doc-sources/run.js +110 -0
- package/dist/plugins/internal/doc-sources/watch.d.ts +33 -0
- package/dist/plugins/internal/doc-sources/watch.js +187 -0
- package/dist/plugins/routes.js +1 -1
- package/dist/preset.d.ts +3 -19
- package/dist/preset.js +23 -30
- package/dist/route-context-payload/index.js +4 -1
- package/dist/settings-defaults.js +1 -2
- package/dist/settings.d.ts +4 -10
- package/package.json +15 -19
- package/dist/plugins/claude-resources.d.ts +0 -4
- package/dist/plugins/claude-resources.js +0 -45
- package/dist/plugins/codex-resources.js +0 -45
- package/dist/plugins/internal/claude-resources/generate.d.ts +0 -31
- package/dist/plugins/internal/claude-resources/generate.js +0 -375
- package/dist/plugins/internal/claude-resources/index.d.ts +0 -54
- package/dist/plugins/internal/claude-resources/index.js +0 -33
- package/dist/plugins/internal/codex-resources/agents-md.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/agents-md.js +0 -83
- package/dist/plugins/internal/codex-resources/agents.d.ts +0 -7
- package/dist/plugins/internal/codex-resources/agents.js +0 -117
- package/dist/plugins/internal/codex-resources/config.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/config.js +0 -124
- package/dist/plugins/internal/codex-resources/generate.d.ts +0 -29
- package/dist/plugins/internal/codex-resources/generate.js +0 -46
- package/dist/plugins/internal/codex-resources/hooks.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/hooks.js +0 -187
- package/dist/plugins/internal/codex-resources/index.d.ts +0 -33
- package/dist/plugins/internal/codex-resources/index.js +0 -33
- package/dist/plugins/internal/codex-resources/overview.d.ts +0 -10
- package/dist/plugins/internal/codex-resources/overview.js +0 -163
- package/dist/plugins/internal/codex-resources/rules.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/skills.d.ts +0 -2
- package/dist/plugins/internal/codex-resources/skills.js +0 -97
- package/dist/plugins/internal/codex-resources/utils.d.ts +0 -14
- package/dist/plugins/internal/codex-resources/utils.js +0 -80
- package/dist/plugins/internal/resource-docs-shared/fs.d.ts +0 -36
- package/dist/plugins/internal/resource-docs-shared/fs.js +0 -101
- package/dist/plugins/internal/resource-docs-shared/index.d.ts +0 -9
- package/dist/plugins/internal/resource-docs-shared/index.js +0 -69
- package/dist/plugins/internal/resource-docs-shared/labels.d.ts +0 -24
- package/dist/plugins/internal/resource-docs-shared/labels.js +0 -14
- package/dist/plugins/internal/resource-docs-shared/links.d.ts +0 -27
- package/dist/plugins/internal/resource-docs-shared/links.js +0 -62
- package/dist/plugins/internal/resource-docs-shared/locale-routes.d.ts +0 -16
- package/dist/plugins/internal/resource-docs-shared/locale-routes.js +0 -14
- package/dist/plugins/internal/resource-docs-shared/mdx.d.ts +0 -28
- package/dist/plugins/internal/resource-docs-shared/mdx.js +0 -64
- package/dist/plugins/internal/resource-docs-shared/skills.d.ts +0 -37
- package/dist/plugins/internal/resource-docs-shared/skills.js +0 -340
- package/dist/plugins/internal/resource-docs-shared/walk.d.ts +0 -20
- package/dist/plugins/internal/resource-docs-shared/walk.js +0 -41
- /package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/escape-for-mdx.d.ts +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function globToRegExp(pattern: string): RegExp;
|
|
2
|
+
export declare function matchesAny(relPath: string, patterns: readonly string[]): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Whether an excluded pattern removes a whole directory, so a walk can prune
|
|
5
|
+
* it. A directory is pruned when the pattern matches the directory itself or
|
|
6
|
+
* every possible descendant (probed with a synthetic child name).
|
|
7
|
+
*/
|
|
8
|
+
export declare function excludesDirectory(dirRel: string, patterns: readonly string[]): boolean;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2
|
+
function escapeRegExp(char) {
|
|
3
|
+
return /[\\^$.*+?()[\]{}|/]/.test(char) ? `\\${char}` : char;
|
|
4
|
+
}
|
|
5
|
+
function translate(pattern) {
|
|
6
|
+
let out = "";
|
|
7
|
+
let i = 0;
|
|
8
|
+
while (i < pattern.length) {
|
|
9
|
+
const char = pattern[i];
|
|
10
|
+
if (char === "*") {
|
|
11
|
+
if (pattern[i + 1] === "*") {
|
|
12
|
+
const atSegmentStart = i === 0 || pattern[i - 1] === "/";
|
|
13
|
+
const atSegmentEnd = i + 2 === pattern.length || pattern[i + 2] === "/";
|
|
14
|
+
if (atSegmentStart && atSegmentEnd) {
|
|
15
|
+
if (i + 2 === pattern.length) {
|
|
16
|
+
out += ".*";
|
|
17
|
+
i += 2;
|
|
18
|
+
} else {
|
|
19
|
+
out += "(?:.*/)?";
|
|
20
|
+
i += 3;
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
out += "[^/]*";
|
|
26
|
+
i++;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (char === "?") {
|
|
30
|
+
out += "[^/]";
|
|
31
|
+
i++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (char === "[") {
|
|
35
|
+
const close = pattern.indexOf("]", i + 1);
|
|
36
|
+
if (close > i + 1) {
|
|
37
|
+
let body = pattern.slice(i + 1, close);
|
|
38
|
+
if (body.startsWith("!")) body = `^${body.slice(1)}`;
|
|
39
|
+
out += `[${body.replace(/\\/g, "\\\\")}]`;
|
|
40
|
+
i = close + 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (char === "{") {
|
|
45
|
+
const close = pattern.indexOf("}", i + 1);
|
|
46
|
+
if (close > i) {
|
|
47
|
+
const alternatives = pattern.slice(i + 1, close).split(",");
|
|
48
|
+
out += `(?:${alternatives.map(translate).join("|")})`;
|
|
49
|
+
i = close + 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
out += escapeRegExp(char);
|
|
54
|
+
i++;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
function globToRegExp(pattern) {
|
|
59
|
+
const normalized = pattern.replace(/^\.\//, "");
|
|
60
|
+
let regex = cache.get(normalized);
|
|
61
|
+
if (regex === void 0) {
|
|
62
|
+
regex = new RegExp(`^${translate(normalized)}$`);
|
|
63
|
+
cache.set(normalized, regex);
|
|
64
|
+
}
|
|
65
|
+
return regex;
|
|
66
|
+
}
|
|
67
|
+
function matchesAny(relPath, patterns) {
|
|
68
|
+
return patterns.some((pattern) => globToRegExp(pattern).test(relPath));
|
|
69
|
+
}
|
|
70
|
+
function excludesDirectory(dirRel, patterns) {
|
|
71
|
+
return patterns.some((pattern) => {
|
|
72
|
+
const regex = globToRegExp(pattern);
|
|
73
|
+
return regex.test(dirRel) || regex.test(`${dirRel}/\0probe`) && regex.test(`${dirRel}/\0a/\0b`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
excludesDirectory,
|
|
78
|
+
globToRegExp,
|
|
79
|
+
matchesAny
|
|
80
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LabelRef } from "./model.js";
|
|
2
|
+
export type Translations = Record<string, Record<string, string>>;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a generated-section label with the same fallback order as `t()`:
|
|
5
|
+
* requested locale → configured default locale → English → literal fallback.
|
|
6
|
+
* The literal keeps a missing translation from leaking a key into output.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveLabel(label: LabelRef, locale: string, defaultLocale: string, translations: Translations): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function resolveLabel(label, locale, defaultLocale, translations) {
|
|
2
|
+
if (label.key === void 0) return label.fallback;
|
|
3
|
+
return translations[locale]?.[label.key] ?? translations[defaultLocale]?.[label.key] ?? translations.en?.[label.key] ?? label.fallback;
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
resolveLabel
|
|
7
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a generated index has a route in the requested locale. Matching
|
|
3
|
+
* mirrors `url-helpers.isDefaultLocaleOnlyPath`: the default-locale-shaped
|
|
4
|
+
* route gets a trailing slash and uses prefix matching.
|
|
5
|
+
*/
|
|
6
|
+
export declare function shouldEmitLocaleRoute(routeDir: string, locale: string, defaultLocale: string, defaultLocaleOnlyPrefixes: readonly string[]): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function shouldEmitLocaleRoute(routeDir, locale, defaultLocale, defaultLocaleOnlyPrefixes) {
|
|
2
|
+
if (locale === defaultLocale) return true;
|
|
3
|
+
const routePath = `/docs/${routeDir.replace(/^\/+|\/+$/g, "")}/`;
|
|
4
|
+
return !defaultLocaleOnlyPrefixes.some((prefix) => routePath.startsWith(prefix));
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
shouldEmitLocaleRoute
|
|
8
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Renderers. Public mappings use the first three; presets may use the rest. */
|
|
2
|
+
export type DocSourceRenderer = "markdown" | "code" | "skill" | "codex-config" | "codex-agent" | "codex-hooks" | "codex-rules";
|
|
3
|
+
/** A translatable label: a translation key with a literal fallback. */
|
|
4
|
+
export interface LabelRef {
|
|
5
|
+
key?: string;
|
|
6
|
+
fallback: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NormalizedMapping {
|
|
9
|
+
sourceId: string;
|
|
10
|
+
id: string;
|
|
11
|
+
/** Absolute, lexically resolved mapping root. */
|
|
12
|
+
root: string;
|
|
13
|
+
include: string[];
|
|
14
|
+
exclude: string[];
|
|
15
|
+
/** POSIX route subtree below the mount ("" for the mount itself). */
|
|
16
|
+
to: string;
|
|
17
|
+
renderer: DocSourceRenderer;
|
|
18
|
+
missing: "error" | "skip";
|
|
19
|
+
assets?: {
|
|
20
|
+
include: string[];
|
|
21
|
+
exclude: string[];
|
|
22
|
+
};
|
|
23
|
+
/** Lower-cased basenames that become their directory's landing page. */
|
|
24
|
+
landingNames: string[];
|
|
25
|
+
/** Lower-cased extensions removed from a document's route segment. */
|
|
26
|
+
stripExtensions: string[];
|
|
27
|
+
/** Use the source-relative path as the page title. */
|
|
28
|
+
titleFromPath: boolean;
|
|
29
|
+
/** Label of the synthesized section index at `to` (when `to` is set). */
|
|
30
|
+
sectionLabel?: LabelRef;
|
|
31
|
+
sectionDescription?: LabelRef;
|
|
32
|
+
}
|
|
33
|
+
export interface NormalizedSource {
|
|
34
|
+
id: string;
|
|
35
|
+
mount: string;
|
|
36
|
+
title: LabelRef;
|
|
37
|
+
description?: LabelRef;
|
|
38
|
+
preset?: string;
|
|
39
|
+
/** Directories that must exist (a preset's configuration root). */
|
|
40
|
+
requiredRoots: string[];
|
|
41
|
+
mappings: NormalizedMapping[];
|
|
42
|
+
}
|
|
43
|
+
/** Everything the pipeline needs, already resolved to absolute paths. */
|
|
44
|
+
export interface DocSourcesRunOptions {
|
|
45
|
+
projectRoot: string;
|
|
46
|
+
sources: NormalizedSource[];
|
|
47
|
+
/** Default-locale content directory (absolute). */
|
|
48
|
+
docsDir: string;
|
|
49
|
+
/** Non-default locale content directories (absolute), keyed by locale. */
|
|
50
|
+
locales: Record<string, string>;
|
|
51
|
+
defaultLocale: string;
|
|
52
|
+
defaultLocaleOnlyPrefixes: string[];
|
|
53
|
+
translations: Record<string, Record<string, string>>;
|
|
54
|
+
/** Public directory (absolute); managed assets go below `<publicDir>/doc-sources/`. */
|
|
55
|
+
publicDir: string;
|
|
56
|
+
/** Additional directories excluded from every scan (version roots, outDir, …). */
|
|
57
|
+
excludedRoots: string[];
|
|
58
|
+
/** Build-local state directory holding the ownership manifest. */
|
|
59
|
+
stateDir: string;
|
|
60
|
+
}
|
|
61
|
+
export interface DocSourcesDiagnostic {
|
|
62
|
+
level: "warn" | "info";
|
|
63
|
+
message: string;
|
|
64
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NormalizedSource } from "./model.js";
|
|
2
|
+
export declare class DocSourcesConfigError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export interface NormalizeOptions {
|
|
6
|
+
projectRoot: string;
|
|
7
|
+
/** Injected home-directory resolver used for explicit `~/` paths. */
|
|
8
|
+
homeDir: () => string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve one configured path. Relative paths resolve from the documentation
|
|
12
|
+
* project root; absolute paths pass through; `~` and `~/…` expand against the
|
|
13
|
+
* injected home directory. `~user` forms are rejected rather than guessed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveConfiguredPath(input: string, { projectRoot, homeDir }: NormalizeOptions, label: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Normalize the `docSources` setting. Returns an empty list for `undefined`
|
|
18
|
+
* or `[]`; the caller still runs reconciliation so stale output is removed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeDocSources(raw: unknown, options: NormalizeOptions): NormalizedSource[];
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { PRESETS } from "./presets.js";
|
|
3
|
+
const SEGMENT = /^[a-z0-9][a-z0-9._-]*$/;
|
|
4
|
+
const ID = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
5
|
+
const FORMATS = /* @__PURE__ */ new Set(["markdown", "code", "skill"]);
|
|
6
|
+
const MISSING = /* @__PURE__ */ new Set(["error", "skip"]);
|
|
7
|
+
const MARKDOWN_LANDINGS = ["index.md", "index.mdx", "readme.md"];
|
|
8
|
+
class DocSourcesConfigError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(`docSources: ${message}`);
|
|
11
|
+
this.name = "DocSourcesConfigError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function resolveConfiguredPath(input, { projectRoot, homeDir }, label) {
|
|
15
|
+
if (input === "~" || input.startsWith("~/")) {
|
|
16
|
+
return path.resolve(homeDir(), input.slice(2));
|
|
17
|
+
}
|
|
18
|
+
if (input.startsWith("~")) {
|
|
19
|
+
throw new DocSourcesConfigError(
|
|
20
|
+
`${label}: "${input}" uses an unsupported home-directory form; use "~/\u2026" or an absolute path`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return path.isAbsolute(input) ? path.normalize(input) : path.resolve(projectRoot, input);
|
|
24
|
+
}
|
|
25
|
+
function isRecord(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
function assertKeys(value, allowed, label) {
|
|
29
|
+
for (const key of Object.keys(value)) {
|
|
30
|
+
if (!allowed.includes(key)) {
|
|
31
|
+
throw new DocSourcesConfigError(
|
|
32
|
+
`${label}: unknown field "${key}" (allowed: ${allowed.join(", ")})`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function requireString(value, label) {
|
|
38
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
39
|
+
throw new DocSourcesConfigError(`${label} must be a non-empty string`);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function optionalString(value, label) {
|
|
44
|
+
return value === void 0 ? void 0 : requireString(value, label);
|
|
45
|
+
}
|
|
46
|
+
function stringList(value, label, required) {
|
|
47
|
+
if (value === void 0 && !required) return [];
|
|
48
|
+
if (!Array.isArray(value) || required && value.length === 0 || !value.every((item) => typeof item === "string" && item.length > 0)) {
|
|
49
|
+
throw new DocSourcesConfigError(
|
|
50
|
+
`${label} must be ${required ? "a non-empty" : "an"} array of glob strings`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
for (const pattern of value) {
|
|
54
|
+
if (pattern.startsWith("/") || pattern.split("/").includes("..")) {
|
|
55
|
+
throw new DocSourcesConfigError(
|
|
56
|
+
`${label}: pattern "${pattern}" must stay relative to the mapping root`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function validateId(value, label) {
|
|
63
|
+
const id = requireString(value, label);
|
|
64
|
+
if (!ID.test(id)) {
|
|
65
|
+
throw new DocSourcesConfigError(
|
|
66
|
+
`${label} "${id}" must contain only letters, digits, "-" and "_"`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return id;
|
|
70
|
+
}
|
|
71
|
+
function validateMount(value, label) {
|
|
72
|
+
if (!SEGMENT.test(value)) {
|
|
73
|
+
throw new DocSourcesConfigError(
|
|
74
|
+
`${label} "${value}" must be one lower-case route segment (a-z, 0-9, ".", "_", "-")`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function validateTo(value, label) {
|
|
80
|
+
if (value === void 0 || value === "") return "";
|
|
81
|
+
const to = requireString(value, label).replace(/^\/+|\/+$/g, "");
|
|
82
|
+
for (const segment of to.split("/")) {
|
|
83
|
+
if (!SEGMENT.test(segment)) {
|
|
84
|
+
throw new DocSourcesConfigError(
|
|
85
|
+
`${label} "${String(value)}" must be a relative route path of lower-case segments`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return to;
|
|
90
|
+
}
|
|
91
|
+
function normalizeMapping(sourceId, raw, index, options) {
|
|
92
|
+
const label = `source "${sourceId}" mappings[${index}]`;
|
|
93
|
+
if (!isRecord(raw)) throw new DocSourcesConfigError(`${label} must be an object`);
|
|
94
|
+
assertKeys(raw, ["id", "root", "include", "exclude", "to", "format", "missing", "assets"], label);
|
|
95
|
+
const id = validateId(raw.id, `${label}.id`);
|
|
96
|
+
const format = requireString(raw.format, `${label}.format`);
|
|
97
|
+
if (!FORMATS.has(format)) {
|
|
98
|
+
throw new DocSourcesConfigError(`${label}.format must be "markdown", "code" or "skill"`);
|
|
99
|
+
}
|
|
100
|
+
const missing = raw.missing === void 0 ? "error" : requireString(raw.missing, `${label}.missing`);
|
|
101
|
+
if (!MISSING.has(missing)) {
|
|
102
|
+
throw new DocSourcesConfigError(`${label}.missing must be "error" or "skip"`);
|
|
103
|
+
}
|
|
104
|
+
let assets;
|
|
105
|
+
if (raw.assets !== void 0) {
|
|
106
|
+
if (!isRecord(raw.assets)) throw new DocSourcesConfigError(`${label}.assets must be an object`);
|
|
107
|
+
assertKeys(raw.assets, ["include", "exclude"], `${label}.assets`);
|
|
108
|
+
assets = {
|
|
109
|
+
include: stringList(raw.assets.include, `${label}.assets.include`, true),
|
|
110
|
+
exclude: stringList(raw.assets.exclude, `${label}.assets.exclude`, false)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const to = validateTo(raw.to, `${label}.to`);
|
|
114
|
+
const lastSegment = to.split("/").at(-1) ?? "";
|
|
115
|
+
return {
|
|
116
|
+
sourceId,
|
|
117
|
+
id,
|
|
118
|
+
root: resolveConfiguredPath(requireString(raw.root, `${label}.root`), options, `${label}.root`),
|
|
119
|
+
include: stringList(raw.include, `${label}.include`, true),
|
|
120
|
+
exclude: stringList(raw.exclude, `${label}.exclude`, false),
|
|
121
|
+
to,
|
|
122
|
+
renderer: format,
|
|
123
|
+
missing,
|
|
124
|
+
assets,
|
|
125
|
+
landingNames: format === "code" ? [] : MARKDOWN_LANDINGS,
|
|
126
|
+
stripExtensions: format === "code" ? [] : [".md", ".mdx"],
|
|
127
|
+
titleFromPath: false,
|
|
128
|
+
sectionLabel: to === "" ? void 0 : { fallback: lastSegment }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function normalizeDocSources(raw, options) {
|
|
132
|
+
if (raw === void 0 || raw === null) return [];
|
|
133
|
+
if (!Array.isArray(raw)) throw new DocSourcesConfigError("the setting must be an array");
|
|
134
|
+
const sources = [];
|
|
135
|
+
const ids = /* @__PURE__ */ new Set();
|
|
136
|
+
const mounts = /* @__PURE__ */ new Map();
|
|
137
|
+
raw.forEach((entry, index) => {
|
|
138
|
+
const label = `docSources[${index}]`;
|
|
139
|
+
if (!isRecord(entry)) throw new DocSourcesConfigError(`${label} must be an object`);
|
|
140
|
+
const id = validateId(entry.id, `${label}.id`);
|
|
141
|
+
if (ids.has(id)) throw new DocSourcesConfigError(`duplicate source id "${id}"`);
|
|
142
|
+
ids.add(id);
|
|
143
|
+
const mount = validateMount(
|
|
144
|
+
optionalString(entry.mount, `${label}.mount`) ?? id,
|
|
145
|
+
entry.mount === void 0 ? `${label}.id (default mount)` : `${label}.mount`
|
|
146
|
+
);
|
|
147
|
+
const previous = mounts.get(mount);
|
|
148
|
+
if (previous !== void 0) {
|
|
149
|
+
throw new DocSourcesConfigError(
|
|
150
|
+
`sources "${previous}" and "${id}" both mount at "/docs/${mount}/"; give one a distinct mount`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
mounts.set(mount, id);
|
|
154
|
+
if ("preset" in entry) {
|
|
155
|
+
assertKeys(entry, ["id", "preset", "root", "scanRoot", "mount"], label);
|
|
156
|
+
const presetName = requireString(entry.preset, `${label}.preset`);
|
|
157
|
+
const expand = PRESETS[presetName];
|
|
158
|
+
if (expand === void 0) {
|
|
159
|
+
throw new DocSourcesConfigError(
|
|
160
|
+
`${label}.preset "${presetName}" is unknown (available: ${Object.keys(PRESETS).join(", ")}); use custom mappings for other layouts`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const root = resolveConfiguredPath(requireString(entry.root, `${label}.root`), options, `${label}.root`);
|
|
164
|
+
const scanRootInput = optionalString(entry.scanRoot, `${label}.scanRoot`);
|
|
165
|
+
const scanRoot = scanRootInput === void 0 ? path.resolve(options.projectRoot) : resolveConfiguredPath(scanRootInput, options, `${label}.scanRoot`);
|
|
166
|
+
sources.push(expand({ id, mount, root, scanRoot }));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
assertKeys(entry, ["id", "title", "mount", "mappings"], label);
|
|
170
|
+
const title = requireString(entry.title, `${label}.title`);
|
|
171
|
+
if (!Array.isArray(entry.mappings) || entry.mappings.length === 0) {
|
|
172
|
+
throw new DocSourcesConfigError(`${label}.mappings must be a non-empty array`);
|
|
173
|
+
}
|
|
174
|
+
const mappings = entry.mappings.map(
|
|
175
|
+
(mappingRaw, mappingIndex) => normalizeMapping(id, mappingRaw, mappingIndex, options)
|
|
176
|
+
);
|
|
177
|
+
const mappingIds = /* @__PURE__ */ new Set();
|
|
178
|
+
for (const m of mappings) {
|
|
179
|
+
if (mappingIds.has(m.id)) {
|
|
180
|
+
throw new DocSourcesConfigError(`source "${id}" has duplicate mapping id "${m.id}"`);
|
|
181
|
+
}
|
|
182
|
+
mappingIds.add(m.id);
|
|
183
|
+
}
|
|
184
|
+
sources.push({ id, mount, title: { fallback: title }, requiredRoots: [], mappings });
|
|
185
|
+
});
|
|
186
|
+
return sources;
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
DocSourcesConfigError,
|
|
190
|
+
normalizeDocSources,
|
|
191
|
+
resolveConfiguredPath
|
|
192
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DiscoveryResult } from "./discover.js";
|
|
2
|
+
import type { DocSourcesDiagnostic, DocSourcesRunOptions } from "./model.js";
|
|
3
|
+
import { escapeMarkdownTableCell } from "./render/markdown-structure.js";
|
|
4
|
+
/** Directory below `publicDir` that holds managed doc-source assets. */
|
|
5
|
+
export declare const ASSET_DIR = "doc-sources";
|
|
6
|
+
export declare class DocSourcesPlanError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/** Route segment for a file or directory name. */
|
|
10
|
+
export declare function routeSegment(name: string): string;
|
|
11
|
+
/** One file the reconciliation stage must own after this run. */
|
|
12
|
+
export interface PlannedOutput {
|
|
13
|
+
abs: string;
|
|
14
|
+
content: string | Buffer;
|
|
15
|
+
}
|
|
16
|
+
export interface Plan {
|
|
17
|
+
outputs: PlannedOutput[];
|
|
18
|
+
/** Absolute roots every planned or owned output must stay inside. */
|
|
19
|
+
outputRoots: string[];
|
|
20
|
+
diagnostics: DocSourcesDiagnostic[];
|
|
21
|
+
counts: {
|
|
22
|
+
documents: number;
|
|
23
|
+
assets: number;
|
|
24
|
+
indexes: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare function buildPlan(options: DocSourcesRunOptions, discovery: DiscoveryResult): Plan;
|
|
28
|
+
export { escapeMarkdownTableCell };
|