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.
- 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 +22 -0
- package/dist/generator/api-reference-generator.js +96 -0
- package/dist/generator/app-scaffolder.d.ts +18 -0
- package/dist/generator/app-scaffolder.js +49 -0
- package/dist/generator/generated-route-manager.d.ts +18 -0
- package/dist/generator/generated-route-manager.js +114 -0
- package/dist/generator/page-catalog.d.ts +21 -0
- package/dist/generator/page-catalog.js +75 -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 +33 -0
- package/dist/generator/project-config-repository.js +191 -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 +31 -0
- package/dist/generator/secure-source-fs.js +470 -0
- package/dist/generator/site-artifacts.d.ts +23 -0
- package/dist/generator/site-artifacts.js +156 -0
- package/dist/generator/watch-coordinator.d.ts +58 -0
- package/dist/generator/watch-coordinator.js +456 -0
- package/dist/lib/config-manager.d.ts +1 -0
- package/dist/lib/config-manager.js +194 -12
- package/dist/lib/generated-artifacts.d.ts +11 -2
- package/dist/lib/generated-artifacts.js +52 -7
- package/dist/lib/layout.d.ts +1 -17
- package/dist/lib/layout.js +5 -4
- package/dist/lib/openapi.d.ts +4 -0
- package/dist/lib/openapi.js +36 -4
- package/dist/lib/project-config.d.ts +3 -0
- package/dist/lib/project-config.js +110 -0
- package/dist/lib/types.d.ts +14 -1
- package/dist/mdx-to-nextjs-generator.d.ts +50 -34
- package/dist/mdx-to-nextjs-generator.js +760 -1740
- 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/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +2 -3
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +11 -2
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +26 -1
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +5 -0
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +2 -1
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +2 -2
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +3 -3
- package/dist/templates/mdx/space.mdx.d.ts +1 -1
- package/dist/templates/mdx/space.mdx.js +1 -5
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +8 -3
- package/dist/templates/next.config.js +2 -2
- package/dist/templates/package.js +3 -3
- 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 +3 -3
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function nonEmptyString(value) {
|
|
5
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
6
|
+
}
|
|
7
|
+
export function validateFontConfig(value) {
|
|
8
|
+
if (!isRecord(value)) {
|
|
9
|
+
throw new Error("fonts.json must contain a JSON object.");
|
|
10
|
+
}
|
|
11
|
+
const hasGoogleFont = value.googleFont !== undefined;
|
|
12
|
+
const hasLocalFonts = value.localFonts !== undefined;
|
|
13
|
+
if (hasGoogleFont === hasLocalFonts) {
|
|
14
|
+
throw new Error("fonts.json must define exactly one of googleFont or localFonts.");
|
|
15
|
+
}
|
|
16
|
+
if (hasGoogleFont) {
|
|
17
|
+
if (!isRecord(value.googleFont)) {
|
|
18
|
+
throw new Error("fonts.json googleFont must be an object.");
|
|
19
|
+
}
|
|
20
|
+
const fontName = value.googleFont.fontName;
|
|
21
|
+
if (!nonEmptyString(fontName) ||
|
|
22
|
+
!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(fontName)) {
|
|
23
|
+
throw new Error("fonts.json googleFont.fontName must be a valid exported font identifier.");
|
|
24
|
+
}
|
|
25
|
+
const subsets = value.googleFont.subsets;
|
|
26
|
+
if (subsets !== undefined &&
|
|
27
|
+
(!Array.isArray(subsets) || !subsets.every(nonEmptyString))) {
|
|
28
|
+
throw new Error("fonts.json googleFont.subsets must be an array of non-empty strings.");
|
|
29
|
+
}
|
|
30
|
+
const weight = value.googleFont.weight;
|
|
31
|
+
if (weight !== undefined &&
|
|
32
|
+
!nonEmptyString(weight) &&
|
|
33
|
+
(!Array.isArray(weight) ||
|
|
34
|
+
weight.length === 0 ||
|
|
35
|
+
!weight.every(nonEmptyString))) {
|
|
36
|
+
throw new Error("fonts.json googleFont.weight must be a non-empty string or string array.");
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
googleFont: {
|
|
40
|
+
fontName,
|
|
41
|
+
...(subsets !== undefined ? { subsets: [...subsets] } : {}),
|
|
42
|
+
...(weight !== undefined
|
|
43
|
+
? { weight: Array.isArray(weight) ? [...weight] : weight }
|
|
44
|
+
: {}),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (nonEmptyString(value.localFonts)) {
|
|
49
|
+
return { localFonts: value.localFonts };
|
|
50
|
+
}
|
|
51
|
+
if (!isRecord(value.localFonts) || !Array.isArray(value.localFonts.src)) {
|
|
52
|
+
throw new Error("fonts.json localFonts must be a non-empty path or an object with a src array.");
|
|
53
|
+
}
|
|
54
|
+
if (value.localFonts.src.length === 0) {
|
|
55
|
+
throw new Error("fonts.json localFonts.src must not be empty.");
|
|
56
|
+
}
|
|
57
|
+
const src = value.localFonts.src.map((entry, index) => {
|
|
58
|
+
if (!isRecord(entry) ||
|
|
59
|
+
!nonEmptyString(entry.path) ||
|
|
60
|
+
(entry.weight !== undefined && !nonEmptyString(entry.weight)) ||
|
|
61
|
+
(entry.style !== undefined && !nonEmptyString(entry.style))) {
|
|
62
|
+
throw new Error(`fonts.json localFonts.src entry ${index + 1} needs a string path and optional string weight/style values.`);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
path: entry.path,
|
|
66
|
+
...(entry.weight !== undefined ? { weight: entry.weight } : {}),
|
|
67
|
+
...(entry.style !== undefined ? { style: entry.style } : {}),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
return { localFonts: { src } };
|
|
71
|
+
}
|
|
72
|
+
export function validateAnalyticsConfig(value) {
|
|
73
|
+
if (!isRecord(value) || value.provider !== "posthog") {
|
|
74
|
+
throw new Error('analytics.json provider must be "posthog".');
|
|
75
|
+
}
|
|
76
|
+
if (!isRecord(value.posthog)) {
|
|
77
|
+
throw new Error("analytics.json posthog must be an object.");
|
|
78
|
+
}
|
|
79
|
+
const key = value.posthog.key;
|
|
80
|
+
if (!nonEmptyString(key) || !/^[A-Za-z0-9_-]+$/.test(key)) {
|
|
81
|
+
throw new Error("analytics.json posthog.key must contain only letters, numbers, underscores, and hyphens.");
|
|
82
|
+
}
|
|
83
|
+
const configuredHost = value.posthog.host;
|
|
84
|
+
let host;
|
|
85
|
+
if (configuredHost !== undefined) {
|
|
86
|
+
if (!nonEmptyString(configuredHost)) {
|
|
87
|
+
throw new Error("analytics.json posthog.host must be a non-empty URL.");
|
|
88
|
+
}
|
|
89
|
+
const trimmedHost = configuredHost.trim();
|
|
90
|
+
let parsed;
|
|
91
|
+
try {
|
|
92
|
+
parsed = new URL(trimmedHost);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new Error("analytics.json posthog.host must be a valid URL.");
|
|
96
|
+
}
|
|
97
|
+
if ((parsed.protocol !== "https:" && parsed.protocol !== "http:") ||
|
|
98
|
+
parsed.username ||
|
|
99
|
+
parsed.password ||
|
|
100
|
+
parsed.search ||
|
|
101
|
+
parsed.hash) {
|
|
102
|
+
throw new Error("analytics.json posthog.host must be an HTTP(S) URL without credentials, query, or fragment.");
|
|
103
|
+
}
|
|
104
|
+
host = trimmedHost.replace(/\/+$/, "");
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
provider: "posthog",
|
|
108
|
+
posthog: { key, ...(host ? { host } : {}) },
|
|
109
|
+
};
|
|
110
|
+
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -54,8 +54,21 @@ export interface NormalizedOpenApiSpec {
|
|
|
54
54
|
name: string;
|
|
55
55
|
file: string;
|
|
56
56
|
}
|
|
57
|
+
export interface GoogleFontConfig {
|
|
58
|
+
fontName: string;
|
|
59
|
+
subsets?: string[];
|
|
60
|
+
weight?: string | string[];
|
|
61
|
+
}
|
|
62
|
+
export interface LocalFontSource {
|
|
63
|
+
path: string;
|
|
64
|
+
weight?: string;
|
|
65
|
+
style?: string;
|
|
66
|
+
}
|
|
57
67
|
export interface FontConfig {
|
|
58
|
-
|
|
68
|
+
googleFont?: GoogleFontConfig;
|
|
69
|
+
localFonts?: string | {
|
|
70
|
+
src: LocalFontSource[];
|
|
71
|
+
};
|
|
59
72
|
}
|
|
60
73
|
export interface PostHogConfig {
|
|
61
74
|
key: string;
|
|
@@ -1,17 +1,12 @@
|
|
|
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
6
|
export declare class MDXToNextJSGenerator {
|
|
4
7
|
private watchDir;
|
|
5
8
|
private outputDir;
|
|
6
9
|
private rootDir;
|
|
7
|
-
private watcher;
|
|
8
|
-
private configWatcher;
|
|
9
|
-
private fontWatcher;
|
|
10
|
-
private publicWatcher;
|
|
11
|
-
private rootDirWatcher;
|
|
12
|
-
private analyticsWatcher;
|
|
13
|
-
private openApiWatcher;
|
|
14
|
-
private doccupineConfigWatcher;
|
|
15
10
|
private doccupineConfigFile;
|
|
16
11
|
private configFiles;
|
|
17
12
|
private fontConfigFile;
|
|
@@ -25,21 +20,24 @@ export declare class MDXToNextJSGenerator {
|
|
|
25
20
|
private apiBaseSlug;
|
|
26
21
|
private apiRegistry;
|
|
27
22
|
private artifacts;
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
private
|
|
23
|
+
private sourceFs;
|
|
24
|
+
private appScaffolder;
|
|
25
|
+
private apiReferenceGenerator;
|
|
26
|
+
private generatedRouteManager;
|
|
27
|
+
private projectConfigRepository;
|
|
28
|
+
private publicAssetManager;
|
|
29
|
+
private watchCoordinator;
|
|
30
|
+
private retainExistingMdxOutput;
|
|
31
|
+
private mdxSnapshotInitialized;
|
|
32
|
+
private successfulMdxPages;
|
|
33
|
+
private successfulMdxContent;
|
|
34
|
+
private successfulMdxSourcesBySlug;
|
|
35
|
+
private collisionBlockedMdxSources;
|
|
32
36
|
constructor(watchDir: string, outputDir: string, openApiSpecs?: NormalizedOpenApiSpec[], rootDir?: string);
|
|
33
37
|
private outputPath;
|
|
34
|
-
private publicOutputFilePath;
|
|
35
|
-
private sourcePathError;
|
|
36
|
-
private realSourceRoot;
|
|
37
|
-
private readSafeSourceFile;
|
|
38
38
|
private readMdxSourceFile;
|
|
39
|
-
private
|
|
40
|
-
private
|
|
41
|
-
private copyRootSourceFile;
|
|
42
|
-
private enqueueMutation;
|
|
39
|
+
private writeStarterFilesIfEmpty;
|
|
40
|
+
private refreshInitialDoccupineConfig;
|
|
43
41
|
init(): Promise<void>;
|
|
44
42
|
createNextJSStructure(): Promise<void>;
|
|
45
43
|
createStartingDocs(): Promise<void>;
|
|
@@ -60,6 +58,7 @@ export declare class MDXToNextJSGenerator {
|
|
|
60
58
|
private withApiReferenceSection;
|
|
61
59
|
private reloadSections;
|
|
62
60
|
private maybeUpdateSections;
|
|
61
|
+
private reconcileMdxSources;
|
|
63
62
|
private determineSectionForFile;
|
|
64
63
|
handleConfigFileChange(filePath: string): Promise<void>;
|
|
65
64
|
handleConfigFileDelete(filePath: string): Promise<void>;
|
|
@@ -71,10 +70,24 @@ export declare class MDXToNextJSGenerator {
|
|
|
71
70
|
handlePublicFileChange(filePath: string): Promise<void>;
|
|
72
71
|
handlePublicFileDelete(filePath: string): Promise<void>;
|
|
73
72
|
startWatching(): Promise<void>;
|
|
74
|
-
private setupPublicWatcher;
|
|
75
73
|
private parseMDXFile;
|
|
74
|
+
private captureMdxPass;
|
|
76
75
|
private buildRealPagesMeta;
|
|
77
76
|
private buildAllPagesMeta;
|
|
77
|
+
private mergeAllPagesMeta;
|
|
78
|
+
private successfulPagesInSourceOrder;
|
|
79
|
+
private recordSuccessfulMdxPage;
|
|
80
|
+
private removeSuccessfulMdxPage;
|
|
81
|
+
private captureSuccessfulMdxState;
|
|
82
|
+
private restoreSuccessfulMdxState;
|
|
83
|
+
private rollbackPageCommits;
|
|
84
|
+
private rollbackFailedMdxCommit;
|
|
85
|
+
private rollbackCommittedMdxChange;
|
|
86
|
+
private dropMissingMdxSnapshots;
|
|
87
|
+
private commitMdxSnapshot;
|
|
88
|
+
private refreshMdxDerivedOutput;
|
|
89
|
+
private readAggregateMdxSource;
|
|
90
|
+
private homepageSource;
|
|
78
91
|
private removeOwnedRoute;
|
|
79
92
|
private removeStaleMdxRoutes;
|
|
80
93
|
/**
|
|
@@ -85,6 +98,7 @@ export declare class MDXToNextJSGenerator {
|
|
|
85
98
|
* end instead of once per file (which is what made large builds O(n²)).
|
|
86
99
|
*/
|
|
87
100
|
private writePageForFile;
|
|
101
|
+
private retryMdxPages;
|
|
88
102
|
/**
|
|
89
103
|
* Regenerates every file that depends on the full set of pages (pages index,
|
|
90
104
|
* root/site layout, sitemap, llms files, section redirects). Parses all MDX
|
|
@@ -98,21 +112,24 @@ export declare class MDXToNextJSGenerator {
|
|
|
98
112
|
getAllMDXFiles(): Promise<string[]>;
|
|
99
113
|
generateRootLayout(): Promise<string>;
|
|
100
114
|
generateSiteLayout(pages?: PageMeta[]): Promise<string>;
|
|
101
|
-
generateSectionIndexPages(pages?: PageMeta[]): Promise<void>;
|
|
115
|
+
generateSectionIndexPages(pages?: PageMeta[], declaredSlugs?: Set<string>): Promise<void>;
|
|
102
116
|
/**
|
|
103
117
|
* Removes section index redirects written earlier in this session whose
|
|
104
118
|
* section has since disappeared (e.g. the API Reference section after the
|
|
105
|
-
* `openapi` config is removed mid-watch).
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* init() wipes app/ - so in-session tracking is enough.
|
|
119
|
+
* `openapi` config is removed mid-watch). Slugs now occupied by real pages
|
|
120
|
+
* are preserved. Fresh processes start clean anyway - init() wipes app/ -
|
|
121
|
+
* so in-session tracking is enough.
|
|
109
122
|
*/
|
|
110
123
|
private cleanupStaleSectionIndexPages;
|
|
111
124
|
/** Best-effort removal of now-empty directories up to (not incl.) stopDir. */
|
|
112
125
|
private removeEmptyDirsUpTo;
|
|
126
|
+
private generatedFileSegments;
|
|
127
|
+
private readGeneratedFile;
|
|
128
|
+
private restoreGeneratedFile;
|
|
129
|
+
private commitRenderedPage;
|
|
113
130
|
generatePageFromMDX(mdxFile: MDXFile, options?: {
|
|
114
131
|
apiOperation?: OperationDescriptor;
|
|
115
|
-
}): Promise<
|
|
132
|
+
}): Promise<GeneratedPageCommit>;
|
|
116
133
|
/** Parses the configured OpenAPI spec(s) into the shared registry. */
|
|
117
134
|
private loadOpenApiRegistry;
|
|
118
135
|
/**
|
|
@@ -133,12 +150,15 @@ export declare class MDXToNextJSGenerator {
|
|
|
133
150
|
* so specs added mid-session are watched without a restart.
|
|
134
151
|
*/
|
|
135
152
|
private syncOpenApiSpecWatcher;
|
|
153
|
+
private openApiSourceState;
|
|
154
|
+
private loadStableOpenApiRegistry;
|
|
155
|
+
private applyStableOpenApiRefresh;
|
|
136
156
|
/**
|
|
137
157
|
* Reparses the spec(s) and rewrites everything derived from them: the
|
|
138
158
|
* endpoint pages and allowlist, the sections (the "API Reference" section
|
|
139
159
|
* appears and disappears with the registry), and the site aggregates.
|
|
140
160
|
*/
|
|
141
|
-
private
|
|
161
|
+
private applyOpenApiRefresh;
|
|
142
162
|
/** Reparses the spec(s) and regenerates the API reference on a watch event. */
|
|
143
163
|
handleOpenApiChange(): Promise<void>;
|
|
144
164
|
/**
|
|
@@ -151,16 +171,12 @@ export declare class MDXToNextJSGenerator {
|
|
|
151
171
|
*/
|
|
152
172
|
handleDoccupineConfigChange(): Promise<void>;
|
|
153
173
|
updatePagesIndex(): Promise<void>;
|
|
154
|
-
updateSectionIndex(sectionSlug: string, frontmatter: Record<string, any>, mdxContent: string, sourcePath?: string): Promise<
|
|
174
|
+
updateSectionIndex(sectionSlug: string, frontmatter: Record<string, any>, mdxContent: string, sourcePath?: string): Promise<GeneratedPageCommit>;
|
|
155
175
|
updateRootLayout(pages?: PageMeta[]): Promise<void>;
|
|
156
176
|
loadSiteUrl(): Promise<string | null>;
|
|
157
|
-
private buildSitemapEntries;
|
|
158
177
|
updateSitemap(pages?: PageMeta[]): Promise<void>;
|
|
159
178
|
updateRobots(): Promise<void>;
|
|
160
|
-
private loadSiteMetadata;
|
|
161
|
-
private readPageWithBody;
|
|
162
|
-
private findSourcePublicAsset;
|
|
163
|
-
private writePublicAggregate;
|
|
164
179
|
updateLlmsFiles(pages?: PageMeta[]): Promise<void>;
|
|
165
180
|
stop(): Promise<void>;
|
|
166
181
|
}
|
|
182
|
+
export {};
|