doccupine 0.0.142 → 0.0.144

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.d.ts +6 -0
  3. package/dist/cli.js +130 -22
  4. package/dist/generator/api-reference-generator.d.ts +20 -0
  5. package/dist/generator/api-reference-generator.js +95 -0
  6. package/dist/generator/app-scaffolder.d.ts +19 -0
  7. package/dist/generator/app-scaffolder.js +54 -0
  8. package/dist/generator/generated-route-manager.d.ts +17 -0
  9. package/dist/generator/generated-route-manager.js +91 -0
  10. package/dist/generator/page-catalog.d.ts +17 -0
  11. package/dist/generator/page-catalog.js +68 -0
  12. package/dist/generator/page-renderer.d.ts +31 -0
  13. package/dist/generator/page-renderer.js +248 -0
  14. package/dist/generator/project-config-repository.d.ts +25 -0
  15. package/dist/generator/project-config-repository.js +133 -0
  16. package/dist/generator/public-asset-manager.d.ts +20 -0
  17. package/dist/generator/public-asset-manager.js +225 -0
  18. package/dist/generator/section-resolver.d.ts +13 -0
  19. package/dist/generator/section-resolver.js +150 -0
  20. package/dist/generator/secure-source-fs.d.ts +27 -0
  21. package/dist/generator/secure-source-fs.js +361 -0
  22. package/dist/generator/site-artifacts.d.ts +22 -0
  23. package/dist/generator/site-artifacts.js +159 -0
  24. package/dist/generator/watch-coordinator.d.ts +57 -0
  25. package/dist/generator/watch-coordinator.js +438 -0
  26. package/dist/lib/generated-artifacts.d.ts +3 -0
  27. package/dist/lib/generated-artifacts.js +27 -1
  28. package/dist/lib/layout.d.ts +1 -17
  29. package/dist/lib/layout.js +5 -4
  30. package/dist/lib/project-config.d.ts +3 -0
  31. package/dist/lib/project-config.js +110 -0
  32. package/dist/lib/structures.js +2 -0
  33. package/dist/lib/types.d.ts +14 -1
  34. package/dist/mdx-to-nextjs-generator.d.ts +7 -25
  35. package/dist/mdx-to-nextjs-generator.js +126 -1574
  36. package/dist/templates/app/api/rag/route.d.ts +1 -1
  37. package/dist/templates/app/api/rag/route.js +2 -1
  38. package/dist/templates/components/Chat.d.ts +1 -1
  39. package/dist/templates/components/Chat.js +2 -1
  40. package/dist/templates/components/MDXComponents.d.ts +1 -1
  41. package/dist/templates/components/MDXComponents.js +1 -1
  42. package/dist/templates/components/layout/Accordion.d.ts +1 -1
  43. package/dist/templates/components/layout/Accordion.js +2 -3
  44. package/dist/templates/components/layout/Space.d.ts +1 -0
  45. package/dist/templates/components/layout/Space.js +70 -0
  46. package/dist/templates/mdx/space.mdx.d.ts +1 -1
  47. package/dist/templates/mdx/space.mdx.js +27 -27
  48. package/dist/templates/next.config.js +2 -2
  49. package/dist/templates/package.js +2 -2
  50. package/dist/templates/proxy.js +1 -1
  51. package/dist/templates/services/mcp/server.d.ts +1 -1
  52. package/dist/templates/services/mcp/server.js +2 -12
  53. package/package.json +2 -2
@@ -0,0 +1,150 @@
1
+ import { generateSlug } from "../lib/utils.js";
2
+ import { slugifySegment } from "../lib/openapi.js";
3
+ export function validateSectionsConfig(parsed) {
4
+ if (!Array.isArray(parsed) || parsed.length === 0)
5
+ return null;
6
+ const seenLabels = new Set();
7
+ const seenSlugs = new Set();
8
+ return parsed.map((entry, index) => {
9
+ if (!entry || typeof entry !== "object") {
10
+ throw new Error(`sections.json entry ${index + 1} must be an object`);
11
+ }
12
+ const candidate = entry;
13
+ const label = typeof candidate.label === "string" ? candidate.label.trim() : "";
14
+ const slug = typeof candidate.slug === "string" ? candidate.slug.trim() : "";
15
+ if (!label) {
16
+ throw new Error(`sections.json entry ${index + 1} needs a non-empty label`);
17
+ }
18
+ if (slug !== "" &&
19
+ (slug !== slugifySegment(slug) ||
20
+ slug.includes("/") ||
21
+ slug === "." ||
22
+ slug === "..")) {
23
+ throw new Error(`Unsafe section slug "${slug}"; use a lowercase URL segment such as "${slugifySegment(slug)}"`);
24
+ }
25
+ if (seenLabels.has(label) || seenSlugs.has(slug)) {
26
+ throw new Error(`Duplicate section label or slug at entry ${index + 1}`);
27
+ }
28
+ seenLabels.add(label);
29
+ seenSlugs.add(slug);
30
+ let directory;
31
+ if (candidate.directory !== undefined) {
32
+ if (typeof candidate.directory !== "string") {
33
+ throw new Error(`sections.json directory at entry ${index + 1} must be a string`);
34
+ }
35
+ directory = candidate.directory
36
+ .replace(/\\/g, "/")
37
+ .replace(/^\/+|\/+$/g, "");
38
+ const parts = directory.split("/");
39
+ if (!directory ||
40
+ parts.some((part) => part === "." || part === ".." || part !== slugifySegment(part))) {
41
+ throw new Error(`Unsafe section directory "${candidate.directory}"`);
42
+ }
43
+ }
44
+ return { label, slug, ...(directory ? { directory } : {}) };
45
+ });
46
+ }
47
+ export function discoverSections(documents) {
48
+ const sectionMap = new Map();
49
+ let hasUnsectionedPages = false;
50
+ let defaultSectionLabel = "Docs";
51
+ for (const { filePath, frontmatter } of documents) {
52
+ if (typeof frontmatter.section === "string" && frontmatter.section.trim()) {
53
+ const label = frontmatter.section.trim();
54
+ const order = typeof frontmatter.sectionOrder === "number"
55
+ ? frontmatter.sectionOrder
56
+ : 0;
57
+ const existing = sectionMap.get(label);
58
+ if (!existing || order < existing.order) {
59
+ sectionMap.set(label, { label, order });
60
+ }
61
+ }
62
+ else {
63
+ hasUnsectionedPages = true;
64
+ }
65
+ if ((filePath === "index.mdx" || filePath === "./index.mdx") &&
66
+ typeof frontmatter.sectionLabel === "string" &&
67
+ frontmatter.sectionLabel.trim()) {
68
+ defaultSectionLabel = frontmatter.sectionLabel.trim();
69
+ }
70
+ }
71
+ if (sectionMap.size === 0)
72
+ return null;
73
+ const sorted = [...sectionMap.values()].sort((a, b) => a.order - b.order);
74
+ const sections = [];
75
+ if (hasUnsectionedPages) {
76
+ sections.push({ label: defaultSectionLabel, slug: "" });
77
+ }
78
+ const usedSlugs = new Set(sections.map((section) => section.slug));
79
+ for (const section of sorted) {
80
+ const slug = slugifySegment(section.label);
81
+ if (usedSlugs.has(slug)) {
82
+ throw new Error(`Section labels resolve to the same slug "${slug}". Rename one section or define sections.json explicitly.`);
83
+ }
84
+ usedSlugs.add(slug);
85
+ sections.push({ label: section.label, slug });
86
+ }
87
+ return sections;
88
+ }
89
+ export function addApiReferenceSection(sections, hasApiReference, apiBaseSlug) {
90
+ if (!hasApiReference)
91
+ return sections;
92
+ const apiSection = {
93
+ label: "API Reference",
94
+ slug: apiBaseSlug,
95
+ };
96
+ if (!sections || sections.length === 0) {
97
+ return [{ label: "Documentation", slug: "" }, apiSection];
98
+ }
99
+ if (sections.some((section) => section.slug === apiBaseSlug))
100
+ return sections;
101
+ return [...sections, apiSection];
102
+ }
103
+ export function determineSectionRoute(filePath, frontmatter, sections) {
104
+ if (!sections || sections.length === 0) {
105
+ return { sectionSlug: "", pageSlug: generateSlug(filePath) };
106
+ }
107
+ const normalizedPath = filePath.replace(/\\/g, "/");
108
+ const firstDir = normalizedPath.includes("/")
109
+ ? normalizedPath.split("/")[0]
110
+ : "";
111
+ for (const section of sections) {
112
+ if (!section.directory)
113
+ continue;
114
+ const dirPrefix = section.directory + "/";
115
+ if (normalizedPath.startsWith(dirPrefix)) {
116
+ return {
117
+ sectionSlug: section.slug,
118
+ pageSlug: generateSlug(normalizedPath.slice(dirPrefix.length)),
119
+ };
120
+ }
121
+ }
122
+ if (firstDir) {
123
+ const match = sections.find((section) => section.slug === firstDir);
124
+ if (match) {
125
+ const pathForSlug = normalizedPath.slice(firstDir.length + 1);
126
+ return {
127
+ sectionSlug: match.slug,
128
+ pageSlug: generateSlug(pathForSlug),
129
+ };
130
+ }
131
+ }
132
+ if (frontmatter.section) {
133
+ const label = frontmatter.section;
134
+ const match = sections.find((section) => section.label === label);
135
+ if (match) {
136
+ let pathForSlug = filePath;
137
+ if (firstDir && firstDir === match.slug) {
138
+ pathForSlug = normalizedPath.slice(firstDir.length + 1);
139
+ }
140
+ return {
141
+ sectionSlug: match.slug,
142
+ pageSlug: generateSlug(pathForSlug),
143
+ };
144
+ }
145
+ }
146
+ return {
147
+ sectionSlug: "",
148
+ pageSlug: generateSlug(filePath),
149
+ };
150
+ }
@@ -0,0 +1,27 @@
1
+ import fs from "fs-extra";
2
+ export declare class SecureSourceFs {
3
+ private documentationRoot;
4
+ private projectRoot;
5
+ constructor(documentationRoot: string, projectRoot: string);
6
+ private sourcePathError;
7
+ private realSourceRoot;
8
+ private readSafeSourceFile;
9
+ readMdxSourceFile(filePath: string): Promise<{
10
+ content: string;
11
+ stat: fs.Stats;
12
+ }>;
13
+ readProjectSourceFile(sourcePath: string, label: string): Promise<{
14
+ data: Buffer;
15
+ stat: fs.Stats;
16
+ }>;
17
+ readPublicSourceFile(sourcePath: string): Promise<{
18
+ data: Buffer;
19
+ stat: fs.Stats;
20
+ }>;
21
+ ensureSafeStarterPath(relativePath: string): Promise<string>;
22
+ pathState(filePath: string, hashContents?: boolean): Promise<string>;
23
+ treeState(root: string, includeFile: (relativePath: string) => boolean, hashContents?: boolean): Promise<string>;
24
+ scanPublicFiles(): Promise<string[] | null>;
25
+ getAllMdxFiles(): Promise<string[]>;
26
+ findPublicAsset(relativePath: string): Promise<string | null>;
27
+ }
@@ -0,0 +1,361 @@
1
+ import fs from "fs-extra";
2
+ import { createHash } from "node:crypto";
3
+ import { constants } from "node:fs";
4
+ import { open } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { isPathInside, resolveWithin } from "../lib/output-safety.js";
7
+ function errorCode(error) {
8
+ return error && typeof error === "object" && "code" in error
9
+ ? String(error.code)
10
+ : undefined;
11
+ }
12
+ function sameFileIdentity(left, right) {
13
+ return left.dev === right.dev && left.ino === right.ino;
14
+ }
15
+ export class SecureSourceFs {
16
+ documentationRoot;
17
+ projectRoot;
18
+ constructor(documentationRoot, projectRoot) {
19
+ this.documentationRoot = path.resolve(documentationRoot);
20
+ this.projectRoot = path.resolve(projectRoot);
21
+ }
22
+ sourcePathError(label, sourcePath, detail) {
23
+ return new Error(`Refusing to use ${label} at ${sourcePath}: ${detail}. Replace it with a real file or directory inside the source root.`);
24
+ }
25
+ async realSourceRoot(root, label, rejectRootSymlink) {
26
+ let rootStat;
27
+ try {
28
+ rootStat = await fs.lstat(root);
29
+ }
30
+ catch (error) {
31
+ if (errorCode(error) === "ENOENT") {
32
+ throw this.sourcePathError(label, root, "the source root does not exist");
33
+ }
34
+ throw error;
35
+ }
36
+ if (rootStat.isSymbolicLink() && rejectRootSymlink) {
37
+ throw this.sourcePathError(label, root, "the source root is a symbolic link");
38
+ }
39
+ const realRoot = await fs.realpath(root);
40
+ if (!(await fs.stat(realRoot)).isDirectory()) {
41
+ throw this.sourcePathError(label, root, "the source root is not a directory");
42
+ }
43
+ return realRoot;
44
+ }
45
+ async readSafeSourceFile(root, sourcePath, label, rejectRootSymlink) {
46
+ const resolvedRoot = path.resolve(root);
47
+ const resolvedSource = path.resolve(sourcePath);
48
+ if (!isPathInside(resolvedRoot, resolvedSource)) {
49
+ throw this.sourcePathError(label, resolvedSource, `the path is outside ${resolvedRoot}`);
50
+ }
51
+ const realRoot = await this.realSourceRoot(resolvedRoot, label, rejectRootSymlink);
52
+ const relativePath = path.relative(resolvedRoot, resolvedSource);
53
+ const components = relativePath.split(path.sep).filter(Boolean);
54
+ let currentPath = resolvedRoot;
55
+ for (const [index, component] of components.entries()) {
56
+ currentPath = path.join(currentPath, component);
57
+ let stat;
58
+ try {
59
+ stat = await fs.lstat(currentPath);
60
+ }
61
+ catch (error) {
62
+ if (errorCode(error) === "ENOENT") {
63
+ throw this.sourcePathError(label, currentPath, "the path does not exist");
64
+ }
65
+ throw error;
66
+ }
67
+ if (stat.isSymbolicLink()) {
68
+ throw this.sourcePathError(label, currentPath, "the path is a symbolic link");
69
+ }
70
+ if (index < components.length - 1 && !stat.isDirectory()) {
71
+ throw this.sourcePathError(label, currentPath, "a path component is not a directory");
72
+ }
73
+ }
74
+ const sourceStat = await fs.lstat(resolvedSource);
75
+ if (!sourceStat.isFile()) {
76
+ throw this.sourcePathError(label, resolvedSource, "expected a regular file");
77
+ }
78
+ const realSource = await fs.realpath(resolvedSource);
79
+ if (!isPathInside(realRoot, realSource)) {
80
+ throw this.sourcePathError(label, resolvedSource, `the real path ${realSource} is outside ${realRoot}`);
81
+ }
82
+ const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
83
+ let handle;
84
+ try {
85
+ handle = await open(resolvedSource, constants.O_RDONLY | noFollow);
86
+ }
87
+ catch (error) {
88
+ if (errorCode(error) === "ELOOP") {
89
+ throw this.sourcePathError(label, resolvedSource, "the final path became a symbolic link while it was being opened");
90
+ }
91
+ throw error;
92
+ }
93
+ try {
94
+ const openedStat = await handle.stat();
95
+ if (!openedStat.isFile()) {
96
+ throw this.sourcePathError(label, resolvedSource, "the opened source is not a regular file");
97
+ }
98
+ let currentStat;
99
+ let currentRealSource;
100
+ let currentRealStat;
101
+ try {
102
+ currentStat = await fs.lstat(resolvedSource);
103
+ currentRealSource = await fs.realpath(resolvedSource);
104
+ currentRealStat = await fs.lstat(currentRealSource);
105
+ }
106
+ catch {
107
+ throw this.sourcePathError(label, resolvedSource, "the path changed while it was being opened");
108
+ }
109
+ if (!isPathInside(realRoot, currentRealSource)) {
110
+ throw this.sourcePathError(label, resolvedSource, `the real path ${currentRealSource} is outside ${realRoot}`);
111
+ }
112
+ if (currentStat.isSymbolicLink() ||
113
+ !currentStat.isFile() ||
114
+ !currentRealStat.isFile() ||
115
+ !sameFileIdentity(sourceStat, openedStat) ||
116
+ !sameFileIdentity(openedStat, currentStat) ||
117
+ !sameFileIdentity(openedStat, currentRealStat)) {
118
+ throw this.sourcePathError(label, resolvedSource, "the source identity changed while it was being opened");
119
+ }
120
+ return { data: await handle.readFile(), stat: openedStat };
121
+ }
122
+ finally {
123
+ await handle.close();
124
+ }
125
+ }
126
+ async readMdxSourceFile(filePath) {
127
+ if (!filePath.toLowerCase().endsWith(".mdx")) {
128
+ throw this.sourcePathError("documentation source", filePath, "expected an .mdx file");
129
+ }
130
+ const { data, stat } = await this.readSafeSourceFile(this.documentationRoot, path.resolve(this.documentationRoot, filePath), "documentation source", false);
131
+ return { content: data.toString("utf8"), stat };
132
+ }
133
+ async readProjectSourceFile(sourcePath, label) {
134
+ return this.readSafeSourceFile(this.projectRoot, sourcePath, label, false);
135
+ }
136
+ async readPublicSourceFile(sourcePath) {
137
+ return this.readSafeSourceFile(path.join(this.projectRoot, "public"), sourcePath, "public source", true);
138
+ }
139
+ async ensureSafeStarterPath(relativePath) {
140
+ const resolvedRoot = path.resolve(this.documentationRoot);
141
+ const targetPath = path.resolve(resolvedRoot, relativePath);
142
+ if (!isPathInside(resolvedRoot, targetPath)) {
143
+ throw this.sourcePathError("documentation source", targetPath, `the starter path is outside ${resolvedRoot}`);
144
+ }
145
+ const realRoot = await this.realSourceRoot(resolvedRoot, "documentation source", false);
146
+ const parentRelativePath = path.relative(resolvedRoot, path.dirname(targetPath));
147
+ let currentPath = resolvedRoot;
148
+ for (const component of parentRelativePath
149
+ .split(path.sep)
150
+ .filter(Boolean)) {
151
+ currentPath = path.join(currentPath, component);
152
+ try {
153
+ await fs.mkdir(currentPath);
154
+ }
155
+ catch (error) {
156
+ if (errorCode(error) !== "EEXIST")
157
+ throw error;
158
+ }
159
+ const stat = await fs.lstat(currentPath);
160
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
161
+ throw this.sourcePathError("documentation source", currentPath, "a starter directory component is not a real directory");
162
+ }
163
+ const realPath = await fs.realpath(currentPath);
164
+ if (!isPathInside(realRoot, realPath)) {
165
+ throw this.sourcePathError("documentation source", currentPath, `the real path ${realPath} is outside ${realRoot}`);
166
+ }
167
+ }
168
+ try {
169
+ const stat = await fs.lstat(targetPath);
170
+ const detail = stat.isSymbolicLink()
171
+ ? "the starter file is a symbolic link"
172
+ : "the starter file appeared after the empty-source check";
173
+ throw this.sourcePathError("documentation source", targetPath, detail);
174
+ }
175
+ catch (error) {
176
+ if (errorCode(error) !== "ENOENT")
177
+ throw error;
178
+ }
179
+ return targetPath;
180
+ }
181
+ async pathState(filePath, hashContents = false) {
182
+ try {
183
+ const stat = await fs.lstat(filePath);
184
+ const kind = stat.isDirectory()
185
+ ? "directory"
186
+ : stat.isFile()
187
+ ? "file"
188
+ : stat.isSymbolicLink()
189
+ ? "symlink"
190
+ : "other";
191
+ const hash = hashContents && stat.isFile()
192
+ ? createHash("sha256")
193
+ .update(await fs.readFile(filePath))
194
+ .digest("hex")
195
+ : "";
196
+ return `${kind}:${stat.size}:${stat.mtimeMs}:${stat.dev}:${stat.ino}:${hash}`;
197
+ }
198
+ catch (error) {
199
+ if (errorCode(error) === "ENOENT")
200
+ return "missing";
201
+ throw error;
202
+ }
203
+ }
204
+ async treeState(root, includeFile, hashContents = false) {
205
+ if (!(await fs.pathExists(root)))
206
+ return "missing";
207
+ const entries = [];
208
+ const scan = async (directory, relativePath = "") => {
209
+ const children = await fs.readdir(directory, { withFileTypes: true });
210
+ children.sort((left, right) => left.name.localeCompare(right.name));
211
+ for (const child of children) {
212
+ const childRelativePath = path.join(relativePath, child.name);
213
+ const childPath = path.join(directory, child.name);
214
+ const state = await this.pathState(childPath, hashContents);
215
+ if (state === "missing")
216
+ continue;
217
+ if (child.isDirectory()) {
218
+ entries.push(`${childRelativePath.replace(/\\/g, "/")}:${state}`);
219
+ await scan(childPath, childRelativePath);
220
+ }
221
+ else if (includeFile(childRelativePath)) {
222
+ entries.push(`${childRelativePath.replace(/\\/g, "/")}:${state}`);
223
+ }
224
+ }
225
+ };
226
+ await scan(root);
227
+ return entries.join("\n");
228
+ }
229
+ async scanPublicFiles() {
230
+ const publicDir = path.join(this.projectRoot, "public");
231
+ let publicStat;
232
+ try {
233
+ publicStat = await fs.lstat(publicDir);
234
+ }
235
+ catch (error) {
236
+ if (errorCode(error) === "ENOENT")
237
+ return null;
238
+ throw error;
239
+ }
240
+ if (publicStat.isSymbolicLink() || !publicStat.isDirectory()) {
241
+ throw this.sourcePathError("public source", publicDir, "the public source root must be a real directory");
242
+ }
243
+ const realPublicDir = await this.realSourceRoot(publicDir, "public source", true);
244
+ const files = [];
245
+ const scanDir = async (directory, relativePath = "") => {
246
+ const entries = await fs.readdir(directory, { withFileTypes: true });
247
+ for (const entry of entries) {
248
+ const sourcePath = path.join(directory, entry.name);
249
+ const entryRelativePath = path.join(relativePath, entry.name);
250
+ const stat = await fs.lstat(sourcePath);
251
+ if (stat.isSymbolicLink()) {
252
+ throw this.sourcePathError("public source", sourcePath, "the path is a symbolic link");
253
+ }
254
+ const realPath = await fs.realpath(sourcePath);
255
+ if (!isPathInside(realPublicDir, realPath)) {
256
+ throw this.sourcePathError("public source", sourcePath, `the real path ${realPath} is outside ${realPublicDir}`);
257
+ }
258
+ if (stat.isDirectory()) {
259
+ await scanDir(sourcePath, entryRelativePath);
260
+ }
261
+ else if (stat.isFile()) {
262
+ files.push(entryRelativePath);
263
+ }
264
+ else {
265
+ throw this.sourcePathError("public source", sourcePath, "expected a regular file or directory");
266
+ }
267
+ }
268
+ };
269
+ await scanDir(publicDir);
270
+ return files;
271
+ }
272
+ async getAllMdxFiles() {
273
+ const files = [];
274
+ const realWatchDir = await this.realSourceRoot(this.documentationRoot, "documentation source", false);
275
+ const scanDir = async (dir, relativePath = "") => {
276
+ const entries = await fs.readdir(dir, { withFileTypes: true });
277
+ for (const entry of entries) {
278
+ const fullPath = path.join(dir, entry.name);
279
+ const relPath = path.join(relativePath, entry.name);
280
+ const stat = await fs.lstat(fullPath);
281
+ if (stat.isSymbolicLink()) {
282
+ let linksToDirectory = false;
283
+ try {
284
+ linksToDirectory = (await fs.stat(fullPath)).isDirectory();
285
+ }
286
+ catch (error) {
287
+ if (errorCode(error) !== "ENOENT")
288
+ throw error;
289
+ }
290
+ if (entry.name.endsWith(".mdx") || linksToDirectory) {
291
+ throw this.sourcePathError("documentation source", fullPath, "the path is a symbolic link");
292
+ }
293
+ continue;
294
+ }
295
+ const realPath = await fs.realpath(fullPath);
296
+ if (!isPathInside(realWatchDir, realPath)) {
297
+ throw this.sourcePathError("documentation source", fullPath, `the real path ${realPath} is outside ${realWatchDir}`);
298
+ }
299
+ if (stat.isDirectory()) {
300
+ await scanDir(fullPath, relPath);
301
+ }
302
+ else if (stat.isFile() && entry.name.endsWith(".mdx")) {
303
+ files.push(relPath);
304
+ }
305
+ else if (!stat.isFile() && entry.name.endsWith(".mdx")) {
306
+ throw this.sourcePathError("documentation source", fullPath, "expected a regular .mdx file");
307
+ }
308
+ }
309
+ };
310
+ await scanDir(this.documentationRoot);
311
+ return files;
312
+ }
313
+ async findPublicAsset(relativePath) {
314
+ const sourcePublicDir = path.join(this.projectRoot, "public");
315
+ const normalized = relativePath.replace(/\\/g, "/");
316
+ resolveWithin(sourcePublicDir, normalized);
317
+ let rootStat;
318
+ try {
319
+ rootStat = await fs.lstat(sourcePublicDir);
320
+ }
321
+ catch (error) {
322
+ if (errorCode(error) === "ENOENT")
323
+ return null;
324
+ throw error;
325
+ }
326
+ if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) {
327
+ throw this.sourcePathError("public source", sourcePublicDir, "the public source root must be a real directory");
328
+ }
329
+ const realPublicDir = await this.realSourceRoot(sourcePublicDir, "public source", true);
330
+ let currentPath = sourcePublicDir;
331
+ const parts = normalized.split("/").filter(Boolean);
332
+ for (const [index, part] of parts.entries()) {
333
+ let entries;
334
+ try {
335
+ entries = await fs.readdir(currentPath);
336
+ }
337
+ catch {
338
+ return null;
339
+ }
340
+ const actualName = entries.find((entry) => entry === part) ??
341
+ entries.find((entry) => entry.toLowerCase() === part.toLowerCase());
342
+ if (!actualName)
343
+ return null;
344
+ currentPath = path.join(currentPath, actualName);
345
+ const stat = await fs.lstat(currentPath);
346
+ if (stat.isSymbolicLink()) {
347
+ throw this.sourcePathError("public source", currentPath, "the path is a symbolic link");
348
+ }
349
+ if (index < parts.length - 1 && !stat.isDirectory())
350
+ return null;
351
+ }
352
+ const stat = await fs.lstat(currentPath);
353
+ if (!stat.isFile())
354
+ return null;
355
+ const realPath = await fs.realpath(currentPath);
356
+ if (!isPathInside(realPublicDir, realPath)) {
357
+ throw this.sourcePathError("public source", currentPath, `the real path ${realPath} is outside ${realPublicDir}`);
358
+ }
359
+ return currentPath;
360
+ }
361
+ }
@@ -0,0 +1,22 @@
1
+ import type { PageMeta, SectionConfig } from "../lib/types.js";
2
+ import { type SitemapEntry } from "../templates/app/sitemap.js";
3
+ import { type PageWithBody } from "../templates/llms/llmsFull.js";
4
+ import type { PublicAssetManager } from "./public-asset-manager.js";
5
+ export interface SiteMetadata {
6
+ url: string | null;
7
+ name: string;
8
+ description: string;
9
+ }
10
+ type ResolvePages = () => Promise<PageMeta[]>;
11
+ type ReadMdxSource = (filePath: string) => Promise<{
12
+ content: string;
13
+ }>;
14
+ type ReadOpenApiBody = (slug: string) => string | undefined;
15
+ export declare function loadSiteUrl(rootDir: string): Promise<string | null>;
16
+ export declare function loadSiteMetadata(rootDir: string): Promise<SiteMetadata>;
17
+ export declare function buildSitemapEntries(pages: PageMeta[], sectionsConfig: SectionConfig[] | null): SitemapEntry[];
18
+ export declare function writeSitemap(outputDir: string, sectionsConfig: SectionConfig[] | null, resolvePages: ResolvePages, resolveSiteUrl: () => Promise<string | null>): Promise<void>;
19
+ export declare function writeRobots(outputDir: string, resolveSiteUrl: () => Promise<string | null>): Promise<void>;
20
+ export declare function collectPageBodies(pages: PageMeta[], readMdxSource: ReadMdxSource, readOpenApiBody: ReadOpenApiBody): Promise<PageWithBody[]>;
21
+ export declare function writeLlmsFiles(outputDir: string, sectionsConfig: SectionConfig[] | null, resolvePages: ResolvePages, readMdxSource: ReadMdxSource, readOpenApiBody: ReadOpenApiBody, resolveSiteMetadata: () => Promise<SiteMetadata>, publicAssetManager: PublicAssetManager): Promise<void>;
22
+ export {};