doccupine 0.0.143 → 0.0.145

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 (66) 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 +22 -0
  5. package/dist/generator/api-reference-generator.js +96 -0
  6. package/dist/generator/app-scaffolder.d.ts +18 -0
  7. package/dist/generator/app-scaffolder.js +49 -0
  8. package/dist/generator/generated-route-manager.d.ts +18 -0
  9. package/dist/generator/generated-route-manager.js +114 -0
  10. package/dist/generator/page-catalog.d.ts +21 -0
  11. package/dist/generator/page-catalog.js +75 -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 +33 -0
  15. package/dist/generator/project-config-repository.js +191 -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 +31 -0
  21. package/dist/generator/secure-source-fs.js +470 -0
  22. package/dist/generator/site-artifacts.d.ts +23 -0
  23. package/dist/generator/site-artifacts.js +156 -0
  24. package/dist/generator/watch-coordinator.d.ts +58 -0
  25. package/dist/generator/watch-coordinator.js +456 -0
  26. package/dist/lib/config-manager.d.ts +1 -0
  27. package/dist/lib/config-manager.js +194 -12
  28. package/dist/lib/generated-artifacts.d.ts +11 -2
  29. package/dist/lib/generated-artifacts.js +52 -7
  30. package/dist/lib/layout.d.ts +1 -17
  31. package/dist/lib/layout.js +5 -4
  32. package/dist/lib/openapi.d.ts +4 -0
  33. package/dist/lib/openapi.js +36 -4
  34. package/dist/lib/project-config.d.ts +3 -0
  35. package/dist/lib/project-config.js +110 -0
  36. package/dist/lib/types.d.ts +14 -1
  37. package/dist/mdx-to-nextjs-generator.d.ts +50 -34
  38. package/dist/mdx-to-nextjs-generator.js +760 -1740
  39. package/dist/templates/app/api/rag/route.d.ts +1 -1
  40. package/dist/templates/app/api/rag/route.js +2 -1
  41. package/dist/templates/components/Chat.d.ts +1 -1
  42. package/dist/templates/components/Chat.js +2 -1
  43. package/dist/templates/components/layout/Accordion.d.ts +1 -1
  44. package/dist/templates/components/layout/Accordion.js +2 -3
  45. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
  46. package/dist/templates/mdx/api-playground.mdx.js +11 -2
  47. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  48. package/dist/templates/mdx/commands.mdx.js +26 -1
  49. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  50. package/dist/templates/mdx/media-and-assets.mdx.js +5 -0
  51. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  52. package/dist/templates/mdx/model-context-protocol.mdx.js +2 -1
  53. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
  54. package/dist/templates/mdx/platform/api-playground.mdx.js +2 -2
  55. package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
  56. package/dist/templates/mdx/platform/publishing.mdx.js +3 -3
  57. package/dist/templates/mdx/space.mdx.d.ts +1 -1
  58. package/dist/templates/mdx/space.mdx.js +1 -5
  59. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  60. package/dist/templates/mdx/what-is-doccupine.mdx.js +8 -3
  61. package/dist/templates/next.config.js +2 -2
  62. package/dist/templates/package.js +3 -3
  63. package/dist/templates/proxy.js +1 -1
  64. package/dist/templates/services/mcp/server.d.ts +1 -1
  65. package/dist/templates/services/mcp/server.js +2 -12
  66. package/package.json +3 -3
@@ -0,0 +1,58 @@
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
+ getOpenApiSourceFiles(): readonly string[];
30
+ callbacks: WatchCoordinatorCallbacks;
31
+ }
32
+ export declare class WatchCoordinator {
33
+ private readonly options;
34
+ private watcher;
35
+ private configWatcher;
36
+ private fontWatcher;
37
+ private publicWatcher;
38
+ private rootDirWatcher;
39
+ private analyticsWatcher;
40
+ private openApiWatcher;
41
+ private doccupineConfigWatcher;
42
+ private mutationQueue;
43
+ private stopping;
44
+ private readyCancellations;
45
+ private sourceSnapshot;
46
+ private publicWatcherStarting;
47
+ constructor(options: WatchCoordinatorOptions);
48
+ private enqueueMutation;
49
+ private waitForWatcherReady;
50
+ private captureSourceSnapshot;
51
+ establishSourceSnapshot(projectSourceStates?: Readonly<Record<string, string>>, openApiSourceState?: string, doccupineSourceState?: string): Promise<void>;
52
+ private reconcileWatchedSources;
53
+ startWatching(): Promise<void>;
54
+ private setupPublicWatcher;
55
+ syncOpenApiSpecWatcher(specs: readonly NormalizedOpenApiSpec[], sourceFiles?: readonly string[]): Promise<void>;
56
+ stop(): Promise<void>;
57
+ }
58
+ export {};
@@ -0,0 +1,456 @@
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, getOpenApiSourceFiles, 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 openApiSourceFiles = getOpenApiSourceFiles();
62
+ const openapi = (await Promise.all((openApiSourceFiles.length > 0
63
+ ? openApiSourceFiles
64
+ : getOpenApiSpecs().map((spec) => path.resolve(rootDir, spec.file))).map(async (sourcePath) => {
65
+ return `${sourcePath}:${await sourceFs.pathState(sourcePath, true)}`;
66
+ }))).join("\n");
67
+ return {
68
+ mdx: await sourceFs.treeState(watchDir, (relativePath) => relativePath.toLowerCase().endsWith(".mdx"), true),
69
+ configs,
70
+ font: await sourceFs.pathState(path.join(rootDir, fontConfigFile), true),
71
+ analytics: await sourceFs.pathState(path.join(rootDir, analyticsConfigFile), true),
72
+ doccupine: await sourceFs.pathState(path.join(rootDir, doccupineConfigFile), true),
73
+ public: await sourceFs.treeState(path.join(rootDir, "public"), () => true),
74
+ openapi,
75
+ };
76
+ }
77
+ async establishSourceSnapshot(projectSourceStates = {}, openApiSourceState, doccupineSourceState) {
78
+ const snapshot = await this.captureSourceSnapshot();
79
+ for (const fileName of this.options.configFiles) {
80
+ if (projectSourceStates[fileName] !== undefined) {
81
+ snapshot.configs[fileName] = projectSourceStates[fileName];
82
+ }
83
+ }
84
+ snapshot.font =
85
+ projectSourceStates[this.options.fontConfigFile] ?? snapshot.font;
86
+ snapshot.analytics =
87
+ projectSourceStates[this.options.analyticsConfigFile] ??
88
+ snapshot.analytics;
89
+ snapshot.openapi = openApiSourceState ?? snapshot.openapi;
90
+ snapshot.doccupine = doccupineSourceState ?? snapshot.doccupine;
91
+ this.sourceSnapshot = snapshot;
92
+ }
93
+ async reconcileWatchedSources(previous, current) {
94
+ const { analyticsConfigFile, callbacks, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, rootDir, } = this.options;
95
+ const doccupineConfigPath = path.join(rootDir, doccupineConfigFile);
96
+ const doccupineChanged = previous === null || previous.doccupine !== current.doccupine;
97
+ if (doccupineChanged && (await fs.pathExists(doccupineConfigPath))) {
98
+ await callbacks.handleDoccupineConfigChange();
99
+ }
100
+ let sectionsChanged = false;
101
+ for (const configFile of configFiles) {
102
+ if (previous !== null &&
103
+ previous.configs[configFile] === current.configs[configFile]) {
104
+ continue;
105
+ }
106
+ const sourcePath = path.join(rootDir, configFile);
107
+ if (await fs.pathExists(sourcePath)) {
108
+ await callbacks.handleConfigFileChange(sourcePath);
109
+ }
110
+ else {
111
+ await callbacks.handleConfigFileDelete(sourcePath);
112
+ }
113
+ if (configFile === "sections.json")
114
+ sectionsChanged = true;
115
+ }
116
+ const fontPath = path.join(rootDir, fontConfigFile);
117
+ if (previous === null || previous.font !== current.font) {
118
+ if (await fs.pathExists(fontPath)) {
119
+ await callbacks.handleFontConfigChange();
120
+ }
121
+ else {
122
+ await callbacks.handleFontConfigDelete();
123
+ }
124
+ }
125
+ const analyticsPath = path.join(rootDir, analyticsConfigFile);
126
+ if (previous === null || previous.analytics !== current.analytics) {
127
+ if (await fs.pathExists(analyticsPath)) {
128
+ await callbacks.handleAnalyticsConfigChange();
129
+ }
130
+ else {
131
+ await callbacks.handleAnalyticsConfigDelete();
132
+ }
133
+ }
134
+ const publicDir = path.join(rootDir, "public");
135
+ if (previous === null || previous.public !== current.public) {
136
+ if (!this.stopping &&
137
+ !this.publicWatcher &&
138
+ (await fs.pathExists(publicDir))) {
139
+ await this.waitForWatcherReady(this.setupPublicWatcher());
140
+ if (this.stopping)
141
+ return;
142
+ }
143
+ await callbacks.copyPublicFiles();
144
+ }
145
+ if (getOpenApiSpecs().length > 0 &&
146
+ (previous === null || previous.openapi !== current.openapi)) {
147
+ await callbacks.handleOpenApiChange();
148
+ }
149
+ if (!sectionsChanged &&
150
+ (previous === null || previous.mdx !== current.mdx)) {
151
+ await callbacks.processAllMDXFiles();
152
+ }
153
+ }
154
+ async startWatching() {
155
+ const { analyticsConfigFile, callbacks, configFiles, doccupineConfigFile, fontConfigFile, rootDir, watchDir, } = this.options;
156
+ this.stopping = false;
157
+ console.log(chalk.yellow(`👀 Watching for changes in: ${watchDir}`));
158
+ const ready = [];
159
+ this.watcher = chokidar.watch(watchDir, {
160
+ persistent: true,
161
+ ignoreInitial: true,
162
+ followSymlinks: false,
163
+ ignored: (filePath, stats) => {
164
+ const isFile = stats?.isFile() ?? path.extname(filePath) !== "";
165
+ const fileName = path.basename(filePath);
166
+ if (configFiles.includes(fileName)) {
167
+ return true;
168
+ }
169
+ if (isFile && !filePath.endsWith(".mdx")) {
170
+ return true;
171
+ }
172
+ return false;
173
+ },
174
+ });
175
+ ready.push(this.waitForWatcherReady(this.watcher));
176
+ this.watcher
177
+ .on("add", (filePath) => {
178
+ const relativePath = path.relative(watchDir, filePath);
179
+ this.enqueueMutation("Error processing added MDX file", () => callbacks.handleFileChange("added", relativePath));
180
+ })
181
+ .on("change", (filePath) => {
182
+ const relativePath = path.relative(watchDir, filePath);
183
+ this.enqueueMutation("Error processing changed MDX file", () => callbacks.handleFileChange("changed", relativePath));
184
+ })
185
+ .on("unlink", (filePath) => {
186
+ const relativePath = path.relative(watchDir, filePath);
187
+ this.enqueueMutation("Error processing deleted MDX file", () => callbacks.handleFileDelete(relativePath));
188
+ })
189
+ .on("ready", () => {
190
+ console.log(chalk.green("📁 Initial scan complete. Ready for changes..."));
191
+ })
192
+ .on("error", (error) => {
193
+ console.error(chalk.red("❌ Watcher error:"), error);
194
+ });
195
+ const configPaths = configFiles.map((file) => path.join(rootDir, file));
196
+ this.configWatcher = chokidar.watch(configPaths, {
197
+ persistent: true,
198
+ ignoreInitial: true,
199
+ });
200
+ ready.push(this.waitForWatcherReady(this.configWatcher));
201
+ this.configWatcher
202
+ .on("add", (filePath) => {
203
+ console.log(chalk.cyan(`📝 Config file added: ${path.basename(filePath)}`));
204
+ this.enqueueMutation("Error applying config file", () => callbacks.handleConfigFileChange(filePath));
205
+ })
206
+ .on("change", (filePath) => {
207
+ console.log(chalk.cyan(`📝 Config file changed: ${path.basename(filePath)}`));
208
+ this.enqueueMutation("Error applying config file", () => callbacks.handleConfigFileChange(filePath));
209
+ })
210
+ .on("unlink", (filePath) => {
211
+ console.log(chalk.red(`🗑️ Config file deleted: ${path.basename(filePath)}`));
212
+ this.enqueueMutation("Error deleting config file", () => callbacks.handleConfigFileDelete(filePath));
213
+ })
214
+ .on("error", (error) => {
215
+ console.error(chalk.red("❌ Config watcher error:"), error);
216
+ });
217
+ const fontPath = path.join(rootDir, fontConfigFile);
218
+ this.fontWatcher = chokidar.watch(fontPath, {
219
+ persistent: true,
220
+ ignoreInitial: true,
221
+ });
222
+ ready.push(this.waitForWatcherReady(this.fontWatcher));
223
+ this.fontWatcher
224
+ .on("add", () => {
225
+ console.log(chalk.cyan(`🔤 Font configuration added`));
226
+ this.enqueueMutation("Error applying font configuration", () => callbacks.handleFontConfigChange());
227
+ })
228
+ .on("change", () => {
229
+ this.enqueueMutation("Error applying font configuration", () => callbacks.handleFontConfigChange());
230
+ })
231
+ .on("unlink", () => {
232
+ this.enqueueMutation("Error deleting font configuration", () => callbacks.handleFontConfigDelete());
233
+ })
234
+ .on("error", (error) => {
235
+ console.error(chalk.red("❌ Font watcher error:"), error);
236
+ });
237
+ const analyticsPath = path.join(rootDir, analyticsConfigFile);
238
+ this.analyticsWatcher = chokidar.watch(analyticsPath, {
239
+ persistent: true,
240
+ ignoreInitial: true,
241
+ });
242
+ ready.push(this.waitForWatcherReady(this.analyticsWatcher));
243
+ this.analyticsWatcher
244
+ .on("add", () => {
245
+ console.log(chalk.cyan(`📊 Analytics configuration added`));
246
+ this.enqueueMutation("Error applying analytics configuration", () => callbacks.handleAnalyticsConfigChange());
247
+ })
248
+ .on("change", () => {
249
+ this.enqueueMutation("Error applying analytics configuration", () => callbacks.handleAnalyticsConfigChange());
250
+ })
251
+ .on("unlink", () => {
252
+ this.enqueueMutation("Error deleting analytics configuration", () => callbacks.handleAnalyticsConfigDelete());
253
+ })
254
+ .on("error", (error) => {
255
+ console.error(chalk.red("❌ Analytics watcher error:"), error);
256
+ });
257
+ await callbacks.syncOpenApiSpecWatcher();
258
+ if (this.stopping)
259
+ return;
260
+ const doccupineConfigPath = path.join(rootDir, doccupineConfigFile);
261
+ this.doccupineConfigWatcher = chokidar.watch(doccupineConfigPath, {
262
+ persistent: true,
263
+ ignoreInitial: true,
264
+ });
265
+ ready.push(this.waitForWatcherReady(this.doccupineConfigWatcher));
266
+ this.doccupineConfigWatcher
267
+ .on("add", () => this.enqueueMutation("Error applying doccupine.json", () => callbacks.handleDoccupineConfigChange()))
268
+ .on("change", () => this.enqueueMutation("Error applying doccupine.json", () => callbacks.handleDoccupineConfigChange()))
269
+ .on("error", (error) => {
270
+ console.error(chalk.red("❌ doccupine.json watcher error:"), error);
271
+ });
272
+ const publicDir = path.join(rootDir, "public");
273
+ if (await fs.pathExists(publicDir)) {
274
+ if (this.stopping)
275
+ return;
276
+ ready.push(this.waitForWatcherReady(this.setupPublicWatcher()));
277
+ }
278
+ if (this.stopping)
279
+ return;
280
+ this.rootDirWatcher = chokidar.watch(rootDir, {
281
+ persistent: true,
282
+ ignoreInitial: true,
283
+ depth: 1,
284
+ });
285
+ ready.push(this.waitForWatcherReady(this.rootDirWatcher));
286
+ const queuePublicWatcherStart = () => {
287
+ if (this.stopping || this.publicWatcher || this.publicWatcherStarting) {
288
+ return;
289
+ }
290
+ this.publicWatcherStarting = true;
291
+ this.enqueueMutation("Error initializing public directory", async () => {
292
+ try {
293
+ if (this.stopping)
294
+ return;
295
+ console.log(chalk.cyan("📁 Public directory created"));
296
+ await this.waitForWatcherReady(this.setupPublicWatcher());
297
+ if (this.stopping)
298
+ return;
299
+ await callbacks.copyPublicFiles();
300
+ }
301
+ finally {
302
+ this.publicWatcherStarting = false;
303
+ }
304
+ });
305
+ };
306
+ this.rootDirWatcher
307
+ .on("addDir", (dirPath) => {
308
+ if (path.basename(dirPath) === "public" &&
309
+ path.dirname(dirPath) === rootDir) {
310
+ queuePublicWatcherStart();
311
+ }
312
+ })
313
+ .on("add", (filePath) => {
314
+ if (isPathInside(publicDir, filePath))
315
+ queuePublicWatcherStart();
316
+ })
317
+ .on("unlinkDir", (dirPath) => {
318
+ if (path.basename(dirPath) !== "public" ||
319
+ path.dirname(dirPath) !== rootDir) {
320
+ return;
321
+ }
322
+ const watcher = this.publicWatcher;
323
+ this.publicWatcher = null;
324
+ void watcher?.close();
325
+ this.enqueueMutation("Error removing public directory", () => callbacks.copyPublicFiles());
326
+ })
327
+ .on("error", (error) => {
328
+ console.error(chalk.red("❌ Root dir watcher error:"), error);
329
+ });
330
+ await Promise.all(ready);
331
+ if (this.stopping)
332
+ return;
333
+ this.enqueueMutation("Error reconciling watched sources", async () => {
334
+ const current = await this.captureSourceSnapshot();
335
+ await this.reconcileWatchedSources(this.sourceSnapshot, current);
336
+ this.sourceSnapshot = current;
337
+ });
338
+ await this.mutationQueue;
339
+ }
340
+ setupPublicWatcher() {
341
+ if (this.publicWatcher) {
342
+ return this.publicWatcher;
343
+ }
344
+ if (this.stopping) {
345
+ throw new Error("Cannot start a public watcher while stopping");
346
+ }
347
+ const { callbacks, rootDir } = this.options;
348
+ const publicDir = path.join(rootDir, "public");
349
+ this.publicWatcher = chokidar.watch(publicDir, {
350
+ persistent: true,
351
+ ignoreInitial: true,
352
+ followSymlinks: false,
353
+ });
354
+ this.publicWatcher
355
+ .on("add", (filePath) => {
356
+ console.log(chalk.cyan(`📁 Public file added: ${path.relative(publicDir, filePath)}`));
357
+ this.enqueueMutation("Error copying public file", () => callbacks.handlePublicFileChange(filePath));
358
+ })
359
+ .on("change", (filePath) => {
360
+ console.log(chalk.cyan(`📁 Public file changed: ${path.relative(publicDir, filePath)}`));
361
+ this.enqueueMutation("Error copying public file", () => callbacks.handlePublicFileChange(filePath));
362
+ })
363
+ .on("unlink", (filePath) => {
364
+ console.log(chalk.red(`🗑️ Public file deleted: ${path.relative(publicDir, filePath)}`));
365
+ this.enqueueMutation("Error deleting public file", () => callbacks.handlePublicFileDelete(filePath));
366
+ })
367
+ .on("unlinkDir", (dirPath) => {
368
+ if (path.resolve(dirPath) !== path.resolve(publicDir))
369
+ return;
370
+ const watcher = this.publicWatcher;
371
+ this.publicWatcher = null;
372
+ void watcher?.close();
373
+ this.enqueueMutation("Error removing public directory", () => callbacks.copyPublicFiles());
374
+ })
375
+ .on("error", (error) => {
376
+ console.error(chalk.red("❌ Public watcher error:"), error);
377
+ });
378
+ return this.publicWatcher;
379
+ }
380
+ async syncOpenApiSpecWatcher(specs, sourceFiles = []) {
381
+ const previousWatcher = this.openApiWatcher;
382
+ this.openApiWatcher = null;
383
+ if (previousWatcher)
384
+ await previousWatcher.close();
385
+ if (this.stopping || specs.length === 0)
386
+ return;
387
+ const { callbacks, rootDir } = this.options;
388
+ const specPaths = [
389
+ ...new Set(sourceFiles.length > 0
390
+ ? sourceFiles
391
+ : specs.map((spec) => path.resolve(rootDir, spec.file))),
392
+ ];
393
+ const watcher = chokidar.watch(specPaths, {
394
+ persistent: true,
395
+ ignoreInitial: true,
396
+ });
397
+ this.openApiWatcher = watcher;
398
+ watcher
399
+ .on("add", () => this.enqueueMutation("Error rebuilding API reference", () => callbacks.handleOpenApiChange()))
400
+ .on("change", () => this.enqueueMutation("Error rebuilding API reference", () => callbacks.handleOpenApiChange()))
401
+ .on("unlink", () => this.enqueueMutation("Error rebuilding API reference", () => callbacks.handleOpenApiChange()))
402
+ .on("error", (error) => {
403
+ console.error(chalk.red("❌ OpenAPI watcher error:"), error);
404
+ });
405
+ await this.waitForWatcherReady(watcher);
406
+ if (this.stopping && this.openApiWatcher === watcher) {
407
+ await watcher.close();
408
+ this.openApiWatcher = null;
409
+ }
410
+ }
411
+ async stop() {
412
+ this.stopping = true;
413
+ for (const cancel of [...this.readyCancellations])
414
+ cancel();
415
+ if (this.watcher) {
416
+ await this.watcher.close();
417
+ console.log(chalk.yellow("👋 Stopped watching for MDX changes"));
418
+ }
419
+ if (this.configWatcher) {
420
+ await this.configWatcher.close();
421
+ console.log(chalk.yellow("👋 Stopped watching for config changes"));
422
+ }
423
+ if (this.fontWatcher) {
424
+ await this.fontWatcher.close();
425
+ console.log(chalk.yellow("👋 Stopped watching for font config changes"));
426
+ }
427
+ if (this.analyticsWatcher) {
428
+ await this.analyticsWatcher.close();
429
+ console.log(chalk.yellow("👋 Stopped watching for analytics config changes"));
430
+ }
431
+ if (this.openApiWatcher) {
432
+ await this.openApiWatcher.close();
433
+ console.log(chalk.yellow("👋 Stopped watching for OpenAPI spec changes"));
434
+ }
435
+ if (this.doccupineConfigWatcher) {
436
+ await this.doccupineConfigWatcher.close();
437
+ console.log(chalk.yellow("👋 Stopped watching for doccupine.json changes"));
438
+ }
439
+ if (this.publicWatcher) {
440
+ await this.publicWatcher.close();
441
+ console.log(chalk.yellow("👋 Stopped watching for public directory changes"));
442
+ }
443
+ if (this.rootDirWatcher) {
444
+ await this.rootDirWatcher.close();
445
+ }
446
+ await this.mutationQueue;
447
+ if (this.openApiWatcher) {
448
+ await this.openApiWatcher.close();
449
+ this.openApiWatcher = null;
450
+ }
451
+ if (this.publicWatcher) {
452
+ await this.publicWatcher.close();
453
+ this.publicWatcher = null;
454
+ }
455
+ }
456
+ }
@@ -27,6 +27,7 @@ export declare function normalizeConfigPaths(config: DoccupineConfig, rootDir?:
27
27
  };
28
28
  export declare class ConfigManager {
29
29
  private configPath;
30
+ private projectRoot;
30
31
  constructor(configPath?: string);
31
32
  loadConfig(): Promise<DoccupineConfig | null>;
32
33
  saveConfig(config: DoccupineConfig): Promise<void>;