doccupine 0.0.146 → 0.0.148

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 (55) hide show
  1. package/README.md +11 -2
  2. package/dist/cli.d.ts +7 -0
  3. package/dist/cli.js +41 -0
  4. package/dist/generator/mdx-reconciliation-coordinator.d.ts +83 -0
  5. package/dist/generator/mdx-reconciliation-coordinator.js +471 -0
  6. package/dist/generator/page-renderer.js +18 -13
  7. package/dist/generator/secure-source-fs.js +5 -4
  8. package/dist/generator/site-artifacts.js +2 -2
  9. package/dist/generator/watch-coordinator.js +3 -2
  10. package/dist/index.js +8 -2
  11. package/dist/lib/layout.js +18 -10
  12. package/dist/lib/openapi-rendering.d.ts +17 -0
  13. package/dist/lib/openapi-rendering.js +193 -0
  14. package/dist/lib/openapi.d.ts +1 -7
  15. package/dist/lib/openapi.js +2 -192
  16. package/dist/lib/structures.js +2 -0
  17. package/dist/lib/utils.d.ts +14 -0
  18. package/dist/lib/utils.js +30 -8
  19. package/dist/mdx-to-nextjs-generator.d.ts +2 -41
  20. package/dist/mdx-to-nextjs-generator.js +37 -469
  21. package/dist/templates/components/Chat.d.ts +1 -1
  22. package/dist/templates/components/Chat.js +226 -1457
  23. package/dist/templates/components/SearchDocs.d.ts +1 -1
  24. package/dist/templates/components/SearchDocs.js +20 -15
  25. package/dist/templates/components/SearchModalContent.d.ts +1 -1
  26. package/dist/templates/components/SearchModalContent.js +7 -1
  27. package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
  28. package/dist/templates/components/layout/ApiPlayground.js +14 -148
  29. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  30. package/dist/templates/components/layout/DocsComponents.js +3 -3
  31. package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
  32. package/dist/templates/components/layout/DocsNavigation.js +2 -3
  33. package/dist/templates/components/layout/Footer.d.ts +1 -1
  34. package/dist/templates/components/layout/Footer.js +2 -4
  35. package/dist/templates/components/layout/Header.d.ts +1 -1
  36. package/dist/templates/components/layout/Header.js +3 -3
  37. package/dist/templates/components/layout/StaticLinks.d.ts +1 -1
  38. package/dist/templates/components/layout/StaticLinks.js +2 -3
  39. package/dist/templates/env.example.d.ts +1 -1
  40. package/dist/templates/env.example.js +8 -0
  41. package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
  42. package/dist/templates/mdx/platform/analytics.mdx.js +13 -0
  43. package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
  44. package/dist/templates/mdx/platform/fonts-settings.mdx.js +16 -0
  45. package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
  46. package/dist/templates/mdx/platform/publishing.mdx.js +16 -1
  47. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
  48. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +17 -5
  49. package/dist/templates/next.config.js +40 -0
  50. package/dist/templates/package.js +11 -10
  51. package/dist/templates/prettierignore.d.ts +1 -1
  52. package/dist/templates/prettierignore.js +11 -0
  53. package/dist/templates/utils/apiPlayground.d.ts +1 -0
  54. package/dist/templates/utils/apiPlayground.js +149 -0
  55. package/package.json +3 -3
@@ -19,7 +19,21 @@ export declare function writeFileAtomic(filePath: string, content: string | Uint
19
19
  * the CLI.
20
20
  */
21
21
  export declare function resolvePackageManager(override?: string): ResolvedPackageManager;
22
+ /**
23
+ * Finds the first free port at or above `startPort`. Scanning stops at the
24
+ * last valid TCP port rather than recursing past it: `listen(65536)` is a
25
+ * RangeError, and surfacing that instead of an explanation tells the user
26
+ * nothing about what to do next.
27
+ */
22
28
  export declare function findAvailablePort(startPort: number): Promise<number>;
29
+ /**
30
+ * Whether a path names an MDX source document. Case-insensitive so a file
31
+ * saved as "Guide.MDX" is treated the same everywhere - source discovery, the
32
+ * watcher's filter, the restart fingerprint, and the llms body reader all
33
+ * route through here, and a split between them makes a file invisible to
34
+ * generation while still triggering work.
35
+ */
36
+ export declare function isMdxPath(filePath: string): boolean;
23
37
  export declare function generateSlug(filePath: string): string;
24
38
  export declare function getFullSlug(pageSlug: string, sectionSlug: string): string;
25
39
  export declare function escapeTemplateContent(content: string): string;
package/dist/lib/utils.js CHANGED
@@ -2,6 +2,7 @@ import fs from "fs-extra";
2
2
  import { randomBytes } from "node:crypto";
3
3
  import { constants } from "node:fs";
4
4
  import { open, unlink } from "node:fs/promises";
5
+ import net from "node:net";
5
6
  import path from "path";
6
7
  import { execSync } from "child_process";
7
8
  import chalk from "chalk";
@@ -149,24 +150,45 @@ export function resolvePackageManager(override) {
149
150
  return { name: "pnpm", bin };
150
151
  return { name: "npm", bin: "npm" };
151
152
  }
152
- export async function findAvailablePort(startPort) {
153
- const net = await import("net");
153
+ const MAX_PORT = 65535;
154
+ function isPortAvailable(port) {
154
155
  return new Promise((resolve) => {
155
156
  const server = net.createServer();
156
- server.listen(startPort, () => {
157
- server.close(() => resolve(startPort));
158
- });
159
- server.on("error", () => {
160
- resolve(findAvailablePort(startPort + 1));
157
+ server.listen(port, () => {
158
+ server.close(() => resolve(true));
161
159
  });
160
+ server.on("error", () => resolve(false));
162
161
  });
163
162
  }
163
+ /**
164
+ * Finds the first free port at or above `startPort`. Scanning stops at the
165
+ * last valid TCP port rather than recursing past it: `listen(65536)` is a
166
+ * RangeError, and surfacing that instead of an explanation tells the user
167
+ * nothing about what to do next.
168
+ */
169
+ export async function findAvailablePort(startPort) {
170
+ for (let port = startPort; port <= MAX_PORT; port += 1) {
171
+ if (await isPortAvailable(port))
172
+ return port;
173
+ }
174
+ throw new Error(`No free port available from ${startPort} to ${MAX_PORT}. Free a port or set a lower "port" in doccupine.json.`);
175
+ }
176
+ /**
177
+ * Whether a path names an MDX source document. Case-insensitive so a file
178
+ * saved as "Guide.MDX" is treated the same everywhere - source discovery, the
179
+ * watcher's filter, the restart fingerprint, and the llms body reader all
180
+ * route through here, and a split between them makes a file invisible to
181
+ * generation while still triggering work.
182
+ */
183
+ export function isMdxPath(filePath) {
184
+ return filePath.toLowerCase().endsWith(".mdx");
185
+ }
164
186
  export function generateSlug(filePath) {
165
187
  if (filePath === "index.mdx" || filePath === "./index.mdx") {
166
188
  return "";
167
189
  }
168
190
  const normalized = filePath
169
- .replace(/\.mdx$/, "")
191
+ .replace(/\.mdx$/i, "")
170
192
  .replace(/\\/g, "/")
171
193
  .replace(/[^a-zA-Z0-9\/\-_]/g, "-")
172
194
  .toLowerCase();
@@ -1,8 +1,6 @@
1
1
  import type { MDXFile, PageMeta, SectionConfig, FontConfig, AnalyticsConfig, NormalizedOpenApiSpec } from "./lib/types.js";
2
2
  import type { OperationDescriptor } from "./lib/openapi-types.js";
3
- interface GeneratedPageCommit {
4
- rollback(): Promise<void>;
5
- }
3
+ import { type GeneratedPageCommit } from "./generator/generated-page-publisher.js";
6
4
  export declare class MDXToNextJSGenerator {
7
5
  private watchDir;
8
6
  private outputDir;
@@ -25,18 +23,12 @@ export declare class MDXToNextJSGenerator {
25
23
  private apiReferenceGenerator;
26
24
  private generatedPagePublisher;
27
25
  private generatedRouteManager;
28
- private mdxPassBuilder;
26
+ private mdxReconciliationCoordinator;
29
27
  private openApiRefreshCoordinator;
30
28
  private sectionIndexGenerator;
31
29
  private projectConfigRepository;
32
30
  private publicAssetManager;
33
31
  private watchCoordinator;
34
- private retainExistingMdxOutput;
35
- private mdxSnapshotInitialized;
36
- private successfulMdxPages;
37
- private successfulMdxContent;
38
- private successfulMdxSourcesBySlug;
39
- private collisionBlockedMdxSources;
40
32
  constructor(watchDir: string, outputDir: string, openApiSpecs?: NormalizedOpenApiSpec[], rootDir?: string);
41
33
  private outputPath;
42
34
  private readMdxSourceFile;
@@ -74,40 +66,10 @@ export declare class MDXToNextJSGenerator {
74
66
  handlePublicFileChange(filePath: string): Promise<void>;
75
67
  handlePublicFileDelete(filePath: string): Promise<void>;
76
68
  startWatching(): Promise<void>;
77
- private captureMdxPass;
78
69
  private buildRealPagesMeta;
79
70
  private buildAllPagesMeta;
80
- private mergeAllPagesMeta;
81
- private successfulPagesInSourceOrder;
82
- private recordSuccessfulMdxPage;
83
- private removeSuccessfulMdxPage;
84
- private captureSuccessfulMdxState;
85
- private restoreSuccessfulMdxState;
86
- private rollbackPageCommits;
87
- private rollbackFailedMdxCommit;
88
- private rollbackCommittedMdxChange;
89
- private dropMissingMdxSnapshots;
90
- private commitMdxSnapshot;
91
- private refreshMdxDerivedOutput;
92
71
  private readAggregateMdxSource;
93
- private homepageSource;
94
72
  private removeOwnedRoute;
95
- private removeStaleMdxRoutes;
96
- /**
97
- * Writes the generated page(s) for a single MDX file: the doc page and, for a
98
- * section-index file, the section landing page. Deliberately does NOT run the
99
- * site-wide aggregations (pages index, layout, sitemap, llms, section
100
- * redirects) - the caller batches those so a bulk build runs them once at the
101
- * end instead of once per file (which is what made large builds O(n²)).
102
- */
103
- private writePageForFile;
104
- private retryMdxPages;
105
- /**
106
- * Regenerates every file that depends on the full set of pages (pages index,
107
- * root/site layout, sitemap, llms files, section redirects). Parses all MDX
108
- * exactly once and threads the result through each generator, so one refresh
109
- * is a single scan rather than one scan per generator.
110
- */
111
73
  private refreshSiteAggregates;
112
74
  handleFileChange(action: string, filePath: string): Promise<void>;
113
75
  handleFileDelete(filePath: string): Promise<void>;
@@ -160,4 +122,3 @@ export declare class MDXToNextJSGenerator {
160
122
  updateLlmsFiles(pages?: PageMeta[]): Promise<void>;
161
123
  stop(): Promise<void>;
162
124
  }
163
- export {};