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.
- package/README.md +1 -1
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +130 -22
- package/dist/generator/api-reference-generator.d.ts +20 -0
- package/dist/generator/api-reference-generator.js +95 -0
- package/dist/generator/app-scaffolder.d.ts +19 -0
- package/dist/generator/app-scaffolder.js +54 -0
- package/dist/generator/generated-route-manager.d.ts +17 -0
- package/dist/generator/generated-route-manager.js +91 -0
- package/dist/generator/page-catalog.d.ts +17 -0
- package/dist/generator/page-catalog.js +68 -0
- package/dist/generator/page-renderer.d.ts +31 -0
- package/dist/generator/page-renderer.js +248 -0
- package/dist/generator/project-config-repository.d.ts +25 -0
- package/dist/generator/project-config-repository.js +133 -0
- package/dist/generator/public-asset-manager.d.ts +20 -0
- package/dist/generator/public-asset-manager.js +225 -0
- package/dist/generator/section-resolver.d.ts +13 -0
- package/dist/generator/section-resolver.js +150 -0
- package/dist/generator/secure-source-fs.d.ts +27 -0
- package/dist/generator/secure-source-fs.js +361 -0
- package/dist/generator/site-artifacts.d.ts +22 -0
- package/dist/generator/site-artifacts.js +159 -0
- package/dist/generator/watch-coordinator.d.ts +57 -0
- package/dist/generator/watch-coordinator.js +438 -0
- package/dist/lib/generated-artifacts.d.ts +3 -0
- package/dist/lib/generated-artifacts.js +27 -1
- package/dist/lib/layout.d.ts +1 -17
- package/dist/lib/layout.js +5 -4
- package/dist/lib/project-config.d.ts +3 -0
- package/dist/lib/project-config.js +110 -0
- package/dist/lib/structures.js +2 -0
- package/dist/lib/types.d.ts +14 -1
- package/dist/mdx-to-nextjs-generator.d.ts +7 -25
- package/dist/mdx-to-nextjs-generator.js +126 -1574
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +2 -1
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +2 -1
- package/dist/templates/components/MDXComponents.d.ts +1 -1
- package/dist/templates/components/MDXComponents.js +1 -1
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +2 -3
- package/dist/templates/components/layout/Space.d.ts +1 -0
- package/dist/templates/components/layout/Space.js +70 -0
- package/dist/templates/mdx/space.mdx.d.ts +1 -1
- package/dist/templates/mdx/space.mdx.js +27 -27
- package/dist/templates/next.config.js +2 -2
- package/dist/templates/package.js +2 -2
- package/dist/templates/proxy.js +1 -1
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +2 -12
- package/package.json +2 -2
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { resolveOutputPath } from "../lib/output-safety.js";
|
|
5
|
+
import { safeMatter, writeFileAtomic } from "../lib/utils.js";
|
|
6
|
+
import { robotsTemplate } from "../templates/app/robots.js";
|
|
7
|
+
import { sitemapTemplate, } from "../templates/app/sitemap.js";
|
|
8
|
+
import { llmsFullTemplate, } from "../templates/llms/llmsFull.js";
|
|
9
|
+
import { llmsIndexTemplate } from "../templates/llms/llmsIndex.js";
|
|
10
|
+
import { skillMdTemplate } from "../templates/llms/skillMd.js";
|
|
11
|
+
export async function loadSiteUrl(rootDir) {
|
|
12
|
+
const fromEnv = process.env.NEXT_PUBLIC_SITE_URL?.trim();
|
|
13
|
+
if (fromEnv)
|
|
14
|
+
return fromEnv.replace(/\/$/, "");
|
|
15
|
+
const configPath = path.join(rootDir, "config.json");
|
|
16
|
+
try {
|
|
17
|
+
if (await fs.pathExists(configPath)) {
|
|
18
|
+
const content = await fs.readFile(configPath, "utf8");
|
|
19
|
+
const parsed = JSON.parse(content);
|
|
20
|
+
if (typeof parsed.url === "string" && parsed.url.trim() !== "") {
|
|
21
|
+
return parsed.url.trim().replace(/\/$/, "");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.warn(chalk.yellow("⚠️ Error reading config.json"), error);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export async function loadSiteMetadata(rootDir) {
|
|
31
|
+
const configPath = path.join(rootDir, "config.json");
|
|
32
|
+
let url = null;
|
|
33
|
+
let name = "Documentation";
|
|
34
|
+
let description = "";
|
|
35
|
+
try {
|
|
36
|
+
const fromEnv = process.env.NEXT_PUBLIC_SITE_URL?.trim();
|
|
37
|
+
if (fromEnv)
|
|
38
|
+
url = fromEnv.replace(/\/$/, "");
|
|
39
|
+
if (await fs.pathExists(configPath)) {
|
|
40
|
+
const content = await fs.readFile(configPath, "utf8");
|
|
41
|
+
const parsed = JSON.parse(content);
|
|
42
|
+
if (!url && typeof parsed.url === "string" && parsed.url.trim() !== "") {
|
|
43
|
+
url = parsed.url.trim().replace(/\/$/, "");
|
|
44
|
+
}
|
|
45
|
+
if (typeof parsed.name === "string" && parsed.name.trim() !== "") {
|
|
46
|
+
name = parsed.name.trim();
|
|
47
|
+
}
|
|
48
|
+
else if (typeof parsed.title === "string" &&
|
|
49
|
+
parsed.title.trim() !== "") {
|
|
50
|
+
name = parsed.title.trim();
|
|
51
|
+
}
|
|
52
|
+
if (typeof parsed.description === "string" &&
|
|
53
|
+
parsed.description.trim() !== "") {
|
|
54
|
+
description = parsed.description.trim();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.warn(chalk.yellow("⚠️ Error reading config.json for llms metadata"), error);
|
|
60
|
+
}
|
|
61
|
+
return { url, name, description };
|
|
62
|
+
}
|
|
63
|
+
export function buildSitemapEntries(pages, sectionsConfig) {
|
|
64
|
+
const sectionSlugs = new Set((sectionsConfig || [])
|
|
65
|
+
.map((section) => section.slug)
|
|
66
|
+
.filter((slug) => typeof slug === "string" && slug !== ""));
|
|
67
|
+
const entries = pages.map((page) => {
|
|
68
|
+
let priority = 0.5;
|
|
69
|
+
if (page.slug === "") {
|
|
70
|
+
priority = 1.0;
|
|
71
|
+
}
|
|
72
|
+
else if (sectionSlugs.has(page.slug)) {
|
|
73
|
+
priority = 0.8;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
slug: page.slug,
|
|
77
|
+
lastModified: page.lastModified,
|
|
78
|
+
changeFrequency: "weekly",
|
|
79
|
+
priority,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
if (!entries.some((entry) => entry.slug === "")) {
|
|
83
|
+
entries.unshift({
|
|
84
|
+
slug: "",
|
|
85
|
+
changeFrequency: "weekly",
|
|
86
|
+
priority: 1.0,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return entries;
|
|
90
|
+
}
|
|
91
|
+
export async function writeSitemap(outputDir, sectionsConfig, resolvePages, resolveSiteUrl) {
|
|
92
|
+
const siteUrl = await resolveSiteUrl();
|
|
93
|
+
const entries = buildSitemapEntries(await resolvePages(), sectionsConfig);
|
|
94
|
+
await writeFileAtomic(resolveOutputPath(outputDir, "app", "sitemap.ts"), sitemapTemplate(entries));
|
|
95
|
+
console.log(chalk.green(`🗺️ Generated sitemap.ts with ${entries.length} page(s)${siteUrl ? ` using ${siteUrl}` : " (waiting for a deployment URL)"}`));
|
|
96
|
+
}
|
|
97
|
+
export async function writeRobots(outputDir, resolveSiteUrl) {
|
|
98
|
+
const siteUrl = await resolveSiteUrl();
|
|
99
|
+
await writeFileAtomic(resolveOutputPath(outputDir, "app", "robots.ts"), robotsTemplate);
|
|
100
|
+
console.log(chalk.green(siteUrl
|
|
101
|
+
? `🤖 Regenerated robots.ts with sitemap link`
|
|
102
|
+
: `🤖 Regenerated robots.ts (no sitemap link)`));
|
|
103
|
+
}
|
|
104
|
+
export async function collectPageBodies(pages, readMdxSource, readOpenApiBody) {
|
|
105
|
+
return Promise.all(pages.map(async (page) => {
|
|
106
|
+
if (!page.path.endsWith(".mdx")) {
|
|
107
|
+
return { ...page, body: readOpenApiBody(page.slug) ?? "" };
|
|
108
|
+
}
|
|
109
|
+
const { content: raw } = await readMdxSource(page.path);
|
|
110
|
+
const { content: body } = safeMatter(raw, page.path);
|
|
111
|
+
return { ...page, body };
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
export async function writeLlmsFiles(outputDir, sectionsConfig, resolvePages, readMdxSource, readOpenApiBody, resolveSiteMetadata, publicAssetManager) {
|
|
115
|
+
await fs.ensureDir(resolveOutputPath(outputDir, "public"));
|
|
116
|
+
const { url: baseUrl, name, description } = await resolveSiteMetadata();
|
|
117
|
+
const resolvedPages = await resolvePages();
|
|
118
|
+
const pagesWithBodies = await collectPageBodies(resolvedPages, readMdxSource, readOpenApiBody);
|
|
119
|
+
const docsContent = pagesWithBodies.map((page) => {
|
|
120
|
+
const route = page.slug.replace(/^\/+|\/+$/g, "");
|
|
121
|
+
const pagePath = route
|
|
122
|
+
? `app/(site)/${route}/page.tsx`
|
|
123
|
+
: "app/(site)/page.tsx";
|
|
124
|
+
return {
|
|
125
|
+
uri: `docs://${route || "/"}`,
|
|
126
|
+
name: page.title,
|
|
127
|
+
path: pagePath,
|
|
128
|
+
content: page.body,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
await writeFileAtomic(resolveOutputPath(outputDir, "services", "mcp", "docs-content.json"), JSON.stringify(docsContent, null, 2) + "\n");
|
|
132
|
+
const indexContent = llmsIndexTemplate({
|
|
133
|
+
siteName: name,
|
|
134
|
+
siteDescription: description,
|
|
135
|
+
baseUrl,
|
|
136
|
+
pages: resolvedPages,
|
|
137
|
+
sectionsConfig,
|
|
138
|
+
});
|
|
139
|
+
const fullContent = llmsFullTemplate({
|
|
140
|
+
siteName: name,
|
|
141
|
+
siteDescription: description,
|
|
142
|
+
baseUrl,
|
|
143
|
+
pages: pagesWithBodies,
|
|
144
|
+
sectionsConfig,
|
|
145
|
+
});
|
|
146
|
+
await publicAssetManager.writePublicAggregate("llms.txt", indexContent);
|
|
147
|
+
await publicAssetManager.writePublicAggregate("llms-full.txt", fullContent);
|
|
148
|
+
const skillContent = skillMdTemplate({
|
|
149
|
+
siteName: name,
|
|
150
|
+
siteDescription: description,
|
|
151
|
+
baseUrl,
|
|
152
|
+
pages: resolvedPages,
|
|
153
|
+
sectionsConfig,
|
|
154
|
+
});
|
|
155
|
+
await publicAssetManager.writePublicAggregate("skill.md", skillContent);
|
|
156
|
+
await publicAssetManager.syncMcpManifest(baseUrl, name);
|
|
157
|
+
await publicAssetManager.syncLlmsPageFiles(pagesWithBodies, baseUrl);
|
|
158
|
+
console.log(chalk.green(`🤖 Generated llms.txt and llms-full.txt with ${resolvedPages.length} page(s)${baseUrl ? ` using ${baseUrl}` : " (relative URLs)"}`));
|
|
159
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NormalizedOpenApiSpec } from "../lib/types.js";
|
|
2
|
+
import type { SecureSourceFs } from "./secure-source-fs.js";
|
|
3
|
+
interface WatchCoordinatorCallbacks {
|
|
4
|
+
syncOpenApiSpecWatcher(): Promise<void>;
|
|
5
|
+
handleFileChange(action: string, filePath: string): Promise<void>;
|
|
6
|
+
handleFileDelete(filePath: string): Promise<void>;
|
|
7
|
+
handleConfigFileChange(filePath: string): Promise<void>;
|
|
8
|
+
handleConfigFileDelete(filePath: string): Promise<void>;
|
|
9
|
+
handleFontConfigChange(): Promise<void>;
|
|
10
|
+
handleFontConfigDelete(): Promise<void>;
|
|
11
|
+
handleAnalyticsConfigChange(): Promise<void>;
|
|
12
|
+
handleAnalyticsConfigDelete(): Promise<void>;
|
|
13
|
+
handleDoccupineConfigChange(): Promise<void>;
|
|
14
|
+
handleOpenApiChange(): Promise<void>;
|
|
15
|
+
copyPublicFiles(): Promise<void>;
|
|
16
|
+
handlePublicFileChange(filePath: string): Promise<void>;
|
|
17
|
+
handlePublicFileDelete(filePath: string): Promise<void>;
|
|
18
|
+
processAllMDXFiles(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
interface WatchCoordinatorOptions {
|
|
21
|
+
watchDir: string;
|
|
22
|
+
rootDir: string;
|
|
23
|
+
configFiles: readonly string[];
|
|
24
|
+
fontConfigFile: string;
|
|
25
|
+
analyticsConfigFile: string;
|
|
26
|
+
doccupineConfigFile: string;
|
|
27
|
+
sourceFs: SecureSourceFs;
|
|
28
|
+
getOpenApiSpecs(): readonly NormalizedOpenApiSpec[];
|
|
29
|
+
callbacks: WatchCoordinatorCallbacks;
|
|
30
|
+
}
|
|
31
|
+
export declare class WatchCoordinator {
|
|
32
|
+
private readonly options;
|
|
33
|
+
private watcher;
|
|
34
|
+
private configWatcher;
|
|
35
|
+
private fontWatcher;
|
|
36
|
+
private publicWatcher;
|
|
37
|
+
private rootDirWatcher;
|
|
38
|
+
private analyticsWatcher;
|
|
39
|
+
private openApiWatcher;
|
|
40
|
+
private doccupineConfigWatcher;
|
|
41
|
+
private mutationQueue;
|
|
42
|
+
private stopping;
|
|
43
|
+
private readyCancellations;
|
|
44
|
+
private sourceSnapshot;
|
|
45
|
+
private publicWatcherStarting;
|
|
46
|
+
constructor(options: WatchCoordinatorOptions);
|
|
47
|
+
private enqueueMutation;
|
|
48
|
+
private waitForWatcherReady;
|
|
49
|
+
private captureSourceSnapshot;
|
|
50
|
+
establishSourceSnapshot(): Promise<void>;
|
|
51
|
+
private reconcileWatchedSources;
|
|
52
|
+
startWatching(): Promise<void>;
|
|
53
|
+
private setupPublicWatcher;
|
|
54
|
+
syncOpenApiSpecWatcher(specs: readonly NormalizedOpenApiSpec[]): Promise<void>;
|
|
55
|
+
stop(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import chokidar from "chokidar";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { isPathInside } from "../lib/output-safety.js";
|
|
6
|
+
export class WatchCoordinator {
|
|
7
|
+
options;
|
|
8
|
+
watcher = null;
|
|
9
|
+
configWatcher = null;
|
|
10
|
+
fontWatcher = null;
|
|
11
|
+
publicWatcher = null;
|
|
12
|
+
rootDirWatcher = null;
|
|
13
|
+
analyticsWatcher = null;
|
|
14
|
+
openApiWatcher = null;
|
|
15
|
+
doccupineConfigWatcher = null;
|
|
16
|
+
mutationQueue = Promise.resolve();
|
|
17
|
+
stopping = false;
|
|
18
|
+
readyCancellations = new Set();
|
|
19
|
+
sourceSnapshot = null;
|
|
20
|
+
publicWatcherStarting = false;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
enqueueMutation(label, task) {
|
|
25
|
+
this.mutationQueue = this.mutationQueue.then(task).catch((error) => {
|
|
26
|
+
console.error(chalk.red(`❌ ${label}:`), error);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
waitForWatcherReady(watcher) {
|
|
30
|
+
if (this.stopping)
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const cleanup = () => {
|
|
34
|
+
watcher.removeListener("ready", onReady);
|
|
35
|
+
watcher.removeListener("error", onError);
|
|
36
|
+
this.readyCancellations.delete(onStop);
|
|
37
|
+
};
|
|
38
|
+
const onReady = () => {
|
|
39
|
+
cleanup();
|
|
40
|
+
resolve();
|
|
41
|
+
};
|
|
42
|
+
const onError = (error) => {
|
|
43
|
+
cleanup();
|
|
44
|
+
reject(error);
|
|
45
|
+
};
|
|
46
|
+
const onStop = () => {
|
|
47
|
+
cleanup();
|
|
48
|
+
resolve();
|
|
49
|
+
};
|
|
50
|
+
this.readyCancellations.add(onStop);
|
|
51
|
+
watcher.once("ready", onReady);
|
|
52
|
+
watcher.once("error", onError);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async captureSourceSnapshot() {
|
|
56
|
+
const { analyticsConfigFile, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, rootDir, sourceFs, watchDir, } = this.options;
|
|
57
|
+
const configs = Object.fromEntries(await Promise.all(configFiles.map(async (fileName) => [
|
|
58
|
+
fileName,
|
|
59
|
+
await sourceFs.pathState(path.join(rootDir, fileName), true),
|
|
60
|
+
])));
|
|
61
|
+
const openapi = (await Promise.all(getOpenApiSpecs().map(async (spec) => {
|
|
62
|
+
const specPath = path.resolve(rootDir, spec.file);
|
|
63
|
+
return `${specPath}:${await sourceFs.pathState(specPath, true)}`;
|
|
64
|
+
}))).join("\n");
|
|
65
|
+
return {
|
|
66
|
+
mdx: await sourceFs.treeState(watchDir, (relativePath) => relativePath.toLowerCase().endsWith(".mdx"), true),
|
|
67
|
+
configs,
|
|
68
|
+
font: await sourceFs.pathState(path.join(rootDir, fontConfigFile), true),
|
|
69
|
+
analytics: await sourceFs.pathState(path.join(rootDir, analyticsConfigFile), true),
|
|
70
|
+
doccupine: await sourceFs.pathState(path.join(rootDir, doccupineConfigFile), true),
|
|
71
|
+
public: await sourceFs.treeState(path.join(rootDir, "public"), () => true),
|
|
72
|
+
openapi,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async establishSourceSnapshot() {
|
|
76
|
+
this.sourceSnapshot = await this.captureSourceSnapshot();
|
|
77
|
+
}
|
|
78
|
+
async reconcileWatchedSources(previous, current) {
|
|
79
|
+
const { analyticsConfigFile, callbacks, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, rootDir, } = this.options;
|
|
80
|
+
const doccupineConfigPath = path.join(rootDir, doccupineConfigFile);
|
|
81
|
+
const doccupineChanged = previous === null || previous.doccupine !== current.doccupine;
|
|
82
|
+
if (doccupineChanged && (await fs.pathExists(doccupineConfigPath))) {
|
|
83
|
+
await callbacks.handleDoccupineConfigChange();
|
|
84
|
+
}
|
|
85
|
+
let sectionsChanged = false;
|
|
86
|
+
for (const configFile of configFiles) {
|
|
87
|
+
if (previous !== null &&
|
|
88
|
+
previous.configs[configFile] === current.configs[configFile]) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const sourcePath = path.join(rootDir, configFile);
|
|
92
|
+
if (await fs.pathExists(sourcePath)) {
|
|
93
|
+
await callbacks.handleConfigFileChange(sourcePath);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
await callbacks.handleConfigFileDelete(sourcePath);
|
|
97
|
+
}
|
|
98
|
+
if (configFile === "sections.json")
|
|
99
|
+
sectionsChanged = true;
|
|
100
|
+
}
|
|
101
|
+
const fontPath = path.join(rootDir, fontConfigFile);
|
|
102
|
+
if (previous === null || previous.font !== current.font) {
|
|
103
|
+
if (await fs.pathExists(fontPath)) {
|
|
104
|
+
await callbacks.handleFontConfigChange();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
await callbacks.handleFontConfigDelete();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const analyticsPath = path.join(rootDir, analyticsConfigFile);
|
|
111
|
+
if (previous === null || previous.analytics !== current.analytics) {
|
|
112
|
+
if (await fs.pathExists(analyticsPath)) {
|
|
113
|
+
await callbacks.handleAnalyticsConfigChange();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
await callbacks.handleAnalyticsConfigDelete();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const publicDir = path.join(rootDir, "public");
|
|
120
|
+
if (previous === null || previous.public !== current.public) {
|
|
121
|
+
if (!this.stopping &&
|
|
122
|
+
!this.publicWatcher &&
|
|
123
|
+
(await fs.pathExists(publicDir))) {
|
|
124
|
+
await this.waitForWatcherReady(this.setupPublicWatcher());
|
|
125
|
+
if (this.stopping)
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
await callbacks.copyPublicFiles();
|
|
129
|
+
}
|
|
130
|
+
if (!doccupineChanged &&
|
|
131
|
+
getOpenApiSpecs().length > 0 &&
|
|
132
|
+
(previous === null || previous.openapi !== current.openapi)) {
|
|
133
|
+
await callbacks.handleOpenApiChange();
|
|
134
|
+
}
|
|
135
|
+
if (!sectionsChanged &&
|
|
136
|
+
(previous === null || previous.mdx !== current.mdx)) {
|
|
137
|
+
await callbacks.processAllMDXFiles();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async startWatching() {
|
|
141
|
+
const { analyticsConfigFile, callbacks, configFiles, doccupineConfigFile, fontConfigFile, rootDir, watchDir, } = this.options;
|
|
142
|
+
this.stopping = false;
|
|
143
|
+
console.log(chalk.yellow(`👀 Watching for changes in: ${watchDir}`));
|
|
144
|
+
const ready = [];
|
|
145
|
+
this.watcher = chokidar.watch(watchDir, {
|
|
146
|
+
persistent: true,
|
|
147
|
+
ignoreInitial: true,
|
|
148
|
+
followSymlinks: false,
|
|
149
|
+
ignored: (filePath, stats) => {
|
|
150
|
+
const isFile = stats?.isFile() ?? path.extname(filePath) !== "";
|
|
151
|
+
const fileName = path.basename(filePath);
|
|
152
|
+
if (configFiles.includes(fileName)) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
if (isFile && !filePath.endsWith(".mdx")) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
ready.push(this.waitForWatcherReady(this.watcher));
|
|
162
|
+
this.watcher
|
|
163
|
+
.on("add", (filePath) => {
|
|
164
|
+
const relativePath = path.relative(watchDir, filePath);
|
|
165
|
+
this.enqueueMutation("Error processing added MDX file", () => callbacks.handleFileChange("added", relativePath));
|
|
166
|
+
})
|
|
167
|
+
.on("change", (filePath) => {
|
|
168
|
+
const relativePath = path.relative(watchDir, filePath);
|
|
169
|
+
this.enqueueMutation("Error processing changed MDX file", () => callbacks.handleFileChange("changed", relativePath));
|
|
170
|
+
})
|
|
171
|
+
.on("unlink", (filePath) => {
|
|
172
|
+
const relativePath = path.relative(watchDir, filePath);
|
|
173
|
+
this.enqueueMutation("Error processing deleted MDX file", () => callbacks.handleFileDelete(relativePath));
|
|
174
|
+
})
|
|
175
|
+
.on("ready", () => {
|
|
176
|
+
console.log(chalk.green("📁 Initial scan complete. Ready for changes..."));
|
|
177
|
+
})
|
|
178
|
+
.on("error", (error) => {
|
|
179
|
+
console.error(chalk.red("❌ Watcher error:"), error);
|
|
180
|
+
});
|
|
181
|
+
const configPaths = configFiles.map((file) => path.join(rootDir, file));
|
|
182
|
+
this.configWatcher = chokidar.watch(configPaths, {
|
|
183
|
+
persistent: true,
|
|
184
|
+
ignoreInitial: true,
|
|
185
|
+
});
|
|
186
|
+
ready.push(this.waitForWatcherReady(this.configWatcher));
|
|
187
|
+
this.configWatcher
|
|
188
|
+
.on("add", (filePath) => {
|
|
189
|
+
console.log(chalk.cyan(`📝 Config file added: ${path.basename(filePath)}`));
|
|
190
|
+
this.enqueueMutation("Error applying config file", () => callbacks.handleConfigFileChange(filePath));
|
|
191
|
+
})
|
|
192
|
+
.on("change", (filePath) => {
|
|
193
|
+
console.log(chalk.cyan(`📝 Config file changed: ${path.basename(filePath)}`));
|
|
194
|
+
this.enqueueMutation("Error applying config file", () => callbacks.handleConfigFileChange(filePath));
|
|
195
|
+
})
|
|
196
|
+
.on("unlink", (filePath) => {
|
|
197
|
+
console.log(chalk.red(`🗑️ Config file deleted: ${path.basename(filePath)}`));
|
|
198
|
+
this.enqueueMutation("Error deleting config file", () => callbacks.handleConfigFileDelete(filePath));
|
|
199
|
+
})
|
|
200
|
+
.on("error", (error) => {
|
|
201
|
+
console.error(chalk.red("❌ Config watcher error:"), error);
|
|
202
|
+
});
|
|
203
|
+
const fontPath = path.join(rootDir, fontConfigFile);
|
|
204
|
+
this.fontWatcher = chokidar.watch(fontPath, {
|
|
205
|
+
persistent: true,
|
|
206
|
+
ignoreInitial: true,
|
|
207
|
+
});
|
|
208
|
+
ready.push(this.waitForWatcherReady(this.fontWatcher));
|
|
209
|
+
this.fontWatcher
|
|
210
|
+
.on("add", () => {
|
|
211
|
+
console.log(chalk.cyan(`🔤 Font configuration added`));
|
|
212
|
+
this.enqueueMutation("Error applying font configuration", () => callbacks.handleFontConfigChange());
|
|
213
|
+
})
|
|
214
|
+
.on("change", () => {
|
|
215
|
+
this.enqueueMutation("Error applying font configuration", () => callbacks.handleFontConfigChange());
|
|
216
|
+
})
|
|
217
|
+
.on("unlink", () => {
|
|
218
|
+
this.enqueueMutation("Error deleting font configuration", () => callbacks.handleFontConfigDelete());
|
|
219
|
+
})
|
|
220
|
+
.on("error", (error) => {
|
|
221
|
+
console.error(chalk.red("❌ Font watcher error:"), error);
|
|
222
|
+
});
|
|
223
|
+
const analyticsPath = path.join(rootDir, analyticsConfigFile);
|
|
224
|
+
this.analyticsWatcher = chokidar.watch(analyticsPath, {
|
|
225
|
+
persistent: true,
|
|
226
|
+
ignoreInitial: true,
|
|
227
|
+
});
|
|
228
|
+
ready.push(this.waitForWatcherReady(this.analyticsWatcher));
|
|
229
|
+
this.analyticsWatcher
|
|
230
|
+
.on("add", () => {
|
|
231
|
+
console.log(chalk.cyan(`📊 Analytics configuration added`));
|
|
232
|
+
this.enqueueMutation("Error applying analytics configuration", () => callbacks.handleAnalyticsConfigChange());
|
|
233
|
+
})
|
|
234
|
+
.on("change", () => {
|
|
235
|
+
this.enqueueMutation("Error applying analytics configuration", () => callbacks.handleAnalyticsConfigChange());
|
|
236
|
+
})
|
|
237
|
+
.on("unlink", () => {
|
|
238
|
+
this.enqueueMutation("Error deleting analytics configuration", () => callbacks.handleAnalyticsConfigDelete());
|
|
239
|
+
})
|
|
240
|
+
.on("error", (error) => {
|
|
241
|
+
console.error(chalk.red("❌ Analytics watcher error:"), error);
|
|
242
|
+
});
|
|
243
|
+
await callbacks.syncOpenApiSpecWatcher();
|
|
244
|
+
if (this.stopping)
|
|
245
|
+
return;
|
|
246
|
+
const doccupineConfigPath = path.join(rootDir, doccupineConfigFile);
|
|
247
|
+
this.doccupineConfigWatcher = chokidar.watch(doccupineConfigPath, {
|
|
248
|
+
persistent: true,
|
|
249
|
+
ignoreInitial: true,
|
|
250
|
+
});
|
|
251
|
+
ready.push(this.waitForWatcherReady(this.doccupineConfigWatcher));
|
|
252
|
+
this.doccupineConfigWatcher
|
|
253
|
+
.on("add", () => this.enqueueMutation("Error applying doccupine.json", () => callbacks.handleDoccupineConfigChange()))
|
|
254
|
+
.on("change", () => this.enqueueMutation("Error applying doccupine.json", () => callbacks.handleDoccupineConfigChange()))
|
|
255
|
+
.on("error", (error) => {
|
|
256
|
+
console.error(chalk.red("❌ doccupine.json watcher error:"), error);
|
|
257
|
+
});
|
|
258
|
+
const publicDir = path.join(rootDir, "public");
|
|
259
|
+
if (await fs.pathExists(publicDir)) {
|
|
260
|
+
if (this.stopping)
|
|
261
|
+
return;
|
|
262
|
+
ready.push(this.waitForWatcherReady(this.setupPublicWatcher()));
|
|
263
|
+
}
|
|
264
|
+
if (this.stopping)
|
|
265
|
+
return;
|
|
266
|
+
this.rootDirWatcher = chokidar.watch(rootDir, {
|
|
267
|
+
persistent: true,
|
|
268
|
+
ignoreInitial: true,
|
|
269
|
+
depth: 1,
|
|
270
|
+
});
|
|
271
|
+
ready.push(this.waitForWatcherReady(this.rootDirWatcher));
|
|
272
|
+
const queuePublicWatcherStart = () => {
|
|
273
|
+
if (this.stopping || this.publicWatcher || this.publicWatcherStarting) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.publicWatcherStarting = true;
|
|
277
|
+
this.enqueueMutation("Error initializing public directory", async () => {
|
|
278
|
+
try {
|
|
279
|
+
if (this.stopping)
|
|
280
|
+
return;
|
|
281
|
+
console.log(chalk.cyan("📁 Public directory created"));
|
|
282
|
+
await this.waitForWatcherReady(this.setupPublicWatcher());
|
|
283
|
+
if (this.stopping)
|
|
284
|
+
return;
|
|
285
|
+
await callbacks.copyPublicFiles();
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
this.publicWatcherStarting = false;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
this.rootDirWatcher
|
|
293
|
+
.on("addDir", (dirPath) => {
|
|
294
|
+
if (path.basename(dirPath) === "public" &&
|
|
295
|
+
path.dirname(dirPath) === rootDir) {
|
|
296
|
+
queuePublicWatcherStart();
|
|
297
|
+
}
|
|
298
|
+
})
|
|
299
|
+
.on("add", (filePath) => {
|
|
300
|
+
if (isPathInside(publicDir, filePath))
|
|
301
|
+
queuePublicWatcherStart();
|
|
302
|
+
})
|
|
303
|
+
.on("unlinkDir", (dirPath) => {
|
|
304
|
+
if (path.basename(dirPath) !== "public" ||
|
|
305
|
+
path.dirname(dirPath) !== rootDir) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const watcher = this.publicWatcher;
|
|
309
|
+
this.publicWatcher = null;
|
|
310
|
+
void watcher?.close();
|
|
311
|
+
this.enqueueMutation("Error removing public directory", () => callbacks.copyPublicFiles());
|
|
312
|
+
})
|
|
313
|
+
.on("error", (error) => {
|
|
314
|
+
console.error(chalk.red("❌ Root dir watcher error:"), error);
|
|
315
|
+
});
|
|
316
|
+
await Promise.all(ready);
|
|
317
|
+
if (this.stopping)
|
|
318
|
+
return;
|
|
319
|
+
this.enqueueMutation("Error reconciling watched sources", async () => {
|
|
320
|
+
const current = await this.captureSourceSnapshot();
|
|
321
|
+
await this.reconcileWatchedSources(this.sourceSnapshot, current);
|
|
322
|
+
this.sourceSnapshot = await this.captureSourceSnapshot();
|
|
323
|
+
});
|
|
324
|
+
await this.mutationQueue;
|
|
325
|
+
}
|
|
326
|
+
setupPublicWatcher() {
|
|
327
|
+
if (this.publicWatcher) {
|
|
328
|
+
return this.publicWatcher;
|
|
329
|
+
}
|
|
330
|
+
if (this.stopping) {
|
|
331
|
+
throw new Error("Cannot start a public watcher while stopping");
|
|
332
|
+
}
|
|
333
|
+
const { callbacks, rootDir } = this.options;
|
|
334
|
+
const publicDir = path.join(rootDir, "public");
|
|
335
|
+
this.publicWatcher = chokidar.watch(publicDir, {
|
|
336
|
+
persistent: true,
|
|
337
|
+
ignoreInitial: true,
|
|
338
|
+
followSymlinks: false,
|
|
339
|
+
});
|
|
340
|
+
this.publicWatcher
|
|
341
|
+
.on("add", (filePath) => {
|
|
342
|
+
console.log(chalk.cyan(`📁 Public file added: ${path.relative(publicDir, filePath)}`));
|
|
343
|
+
this.enqueueMutation("Error copying public file", () => callbacks.handlePublicFileChange(filePath));
|
|
344
|
+
})
|
|
345
|
+
.on("change", (filePath) => {
|
|
346
|
+
console.log(chalk.cyan(`📁 Public file changed: ${path.relative(publicDir, filePath)}`));
|
|
347
|
+
this.enqueueMutation("Error copying public file", () => callbacks.handlePublicFileChange(filePath));
|
|
348
|
+
})
|
|
349
|
+
.on("unlink", (filePath) => {
|
|
350
|
+
console.log(chalk.red(`🗑️ Public file deleted: ${path.relative(publicDir, filePath)}`));
|
|
351
|
+
this.enqueueMutation("Error deleting public file", () => callbacks.handlePublicFileDelete(filePath));
|
|
352
|
+
})
|
|
353
|
+
.on("unlinkDir", (dirPath) => {
|
|
354
|
+
if (path.resolve(dirPath) !== path.resolve(publicDir))
|
|
355
|
+
return;
|
|
356
|
+
const watcher = this.publicWatcher;
|
|
357
|
+
this.publicWatcher = null;
|
|
358
|
+
void watcher?.close();
|
|
359
|
+
this.enqueueMutation("Error removing public directory", () => callbacks.copyPublicFiles());
|
|
360
|
+
})
|
|
361
|
+
.on("error", (error) => {
|
|
362
|
+
console.error(chalk.red("❌ Public watcher error:"), error);
|
|
363
|
+
});
|
|
364
|
+
return this.publicWatcher;
|
|
365
|
+
}
|
|
366
|
+
async syncOpenApiSpecWatcher(specs) {
|
|
367
|
+
const previousWatcher = this.openApiWatcher;
|
|
368
|
+
this.openApiWatcher = null;
|
|
369
|
+
if (previousWatcher)
|
|
370
|
+
await previousWatcher.close();
|
|
371
|
+
if (this.stopping || specs.length === 0)
|
|
372
|
+
return;
|
|
373
|
+
const { callbacks, rootDir } = this.options;
|
|
374
|
+
const specPaths = specs.map((spec) => path.resolve(rootDir, spec.file));
|
|
375
|
+
const watcher = chokidar.watch(specPaths, {
|
|
376
|
+
persistent: true,
|
|
377
|
+
ignoreInitial: true,
|
|
378
|
+
});
|
|
379
|
+
this.openApiWatcher = watcher;
|
|
380
|
+
watcher
|
|
381
|
+
.on("add", () => this.enqueueMutation("Error rebuilding API reference", () => callbacks.handleOpenApiChange()))
|
|
382
|
+
.on("change", () => this.enqueueMutation("Error rebuilding API reference", () => callbacks.handleOpenApiChange()))
|
|
383
|
+
.on("unlink", () => this.enqueueMutation("Error rebuilding API reference", () => callbacks.handleOpenApiChange()))
|
|
384
|
+
.on("error", (error) => {
|
|
385
|
+
console.error(chalk.red("❌ OpenAPI watcher error:"), error);
|
|
386
|
+
});
|
|
387
|
+
await this.waitForWatcherReady(watcher);
|
|
388
|
+
if (this.stopping && this.openApiWatcher === watcher) {
|
|
389
|
+
await watcher.close();
|
|
390
|
+
this.openApiWatcher = null;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async stop() {
|
|
394
|
+
this.stopping = true;
|
|
395
|
+
for (const cancel of [...this.readyCancellations])
|
|
396
|
+
cancel();
|
|
397
|
+
if (this.watcher) {
|
|
398
|
+
await this.watcher.close();
|
|
399
|
+
console.log(chalk.yellow("👋 Stopped watching for MDX changes"));
|
|
400
|
+
}
|
|
401
|
+
if (this.configWatcher) {
|
|
402
|
+
await this.configWatcher.close();
|
|
403
|
+
console.log(chalk.yellow("👋 Stopped watching for config changes"));
|
|
404
|
+
}
|
|
405
|
+
if (this.fontWatcher) {
|
|
406
|
+
await this.fontWatcher.close();
|
|
407
|
+
console.log(chalk.yellow("👋 Stopped watching for font config changes"));
|
|
408
|
+
}
|
|
409
|
+
if (this.analyticsWatcher) {
|
|
410
|
+
await this.analyticsWatcher.close();
|
|
411
|
+
console.log(chalk.yellow("👋 Stopped watching for analytics config changes"));
|
|
412
|
+
}
|
|
413
|
+
if (this.openApiWatcher) {
|
|
414
|
+
await this.openApiWatcher.close();
|
|
415
|
+
console.log(chalk.yellow("👋 Stopped watching for OpenAPI spec changes"));
|
|
416
|
+
}
|
|
417
|
+
if (this.doccupineConfigWatcher) {
|
|
418
|
+
await this.doccupineConfigWatcher.close();
|
|
419
|
+
console.log(chalk.yellow("👋 Stopped watching for doccupine.json changes"));
|
|
420
|
+
}
|
|
421
|
+
if (this.publicWatcher) {
|
|
422
|
+
await this.publicWatcher.close();
|
|
423
|
+
console.log(chalk.yellow("👋 Stopped watching for public directory changes"));
|
|
424
|
+
}
|
|
425
|
+
if (this.rootDirWatcher) {
|
|
426
|
+
await this.rootDirWatcher.close();
|
|
427
|
+
}
|
|
428
|
+
await this.mutationQueue;
|
|
429
|
+
if (this.openApiWatcher) {
|
|
430
|
+
await this.openApiWatcher.close();
|
|
431
|
+
this.openApiWatcher = null;
|
|
432
|
+
}
|
|
433
|
+
if (this.publicWatcher) {
|
|
434
|
+
await this.publicWatcher.close();
|
|
435
|
+
this.publicWatcher = null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
@@ -8,6 +8,7 @@ export declare class GeneratedArtifacts {
|
|
|
8
8
|
private readonly outputDir;
|
|
9
9
|
private routes;
|
|
10
10
|
private llmsFiles;
|
|
11
|
+
private publicFilePaths;
|
|
11
12
|
constructor(outputDir: string);
|
|
12
13
|
private manifestPath;
|
|
13
14
|
private routeKey;
|
|
@@ -21,6 +22,8 @@ export declare class GeneratedArtifacts {
|
|
|
21
22
|
removeRoute(kind: RouteOwnerKind, source: string): void;
|
|
22
23
|
llmsPageFiles(): Set<string>;
|
|
23
24
|
replaceLlmsPageFiles(files: Iterable<string>): void;
|
|
25
|
+
publicFiles(): Set<string>;
|
|
26
|
+
replacePublicFiles(files: Iterable<string>): void;
|
|
24
27
|
save(): Promise<void>;
|
|
25
28
|
}
|
|
26
29
|
export {};
|