doccupine 0.0.145 → 0.0.147
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 +11 -2
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +41 -0
- package/dist/generator/generated-page-publisher.d.ts +21 -0
- package/dist/generator/generated-page-publisher.js +124 -0
- package/dist/generator/generated-route-manager.d.ts +3 -0
- package/dist/generator/generated-route-manager.js +21 -8
- package/dist/generator/mdx-pass-builder.d.ts +31 -0
- package/dist/generator/mdx-pass-builder.js +45 -0
- package/dist/generator/mdx-reconciliation-coordinator.d.ts +83 -0
- package/dist/generator/mdx-reconciliation-coordinator.js +471 -0
- package/dist/generator/openapi-refresh-coordinator.d.ts +42 -0
- package/dist/generator/openapi-refresh-coordinator.js +211 -0
- package/dist/generator/page-renderer.js +18 -13
- package/dist/generator/section-index-generator.d.ts +10 -0
- package/dist/generator/section-index-generator.js +68 -0
- package/dist/generator/secure-source-fs.js +5 -4
- package/dist/generator/site-artifacts.js +2 -2
- package/dist/generator/watch-coordinator.d.ts +8 -0
- package/dist/generator/watch-coordinator.js +131 -53
- package/dist/index.js +8 -2
- package/dist/lib/layout.js +18 -10
- package/dist/lib/openapi-rendering.d.ts +17 -0
- package/dist/lib/openapi-rendering.js +193 -0
- package/dist/lib/openapi.d.ts +1 -7
- package/dist/lib/openapi.js +2 -192
- package/dist/lib/output-safety.js +10 -3
- package/dist/lib/structures.js +4 -0
- package/dist/lib/utils.d.ts +14 -0
- package/dist/lib/utils.js +30 -8
- package/dist/mdx-to-nextjs-generator.d.ts +7 -65
- package/dist/mdx-to-nextjs-generator.js +94 -783
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +20 -691
- package/dist/templates/components/ChatStyles.d.ts +1 -0
- package/dist/templates/components/ChatStyles.js +695 -0
- package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
- package/dist/templates/components/layout/ApiPlayground.js +14 -148
- package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/analytics.mdx.js +13 -0
- package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/fonts-settings.mdx.js +16 -0
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +16 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +17 -5
- package/dist/templates/package.js +3 -2
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +11 -0
- package/dist/templates/utils/apiPlayground.d.ts +1 -0
- package/dist/templates/utils/apiPlayground.js +149 -0
- package/dist/templates/utils/orderNavItems.d.ts +1 -1
- package/dist/templates/utils/orderNavItems.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { getFullSlug, safeMatter } from "../lib/utils.js";
|
|
3
|
+
import { MdxPassBuilder, } from "./mdx-pass-builder.js";
|
|
4
|
+
import { mergePages, RouteCollisionError } from "./page-catalog.js";
|
|
5
|
+
export class MdxReconciliationCoordinator {
|
|
6
|
+
options;
|
|
7
|
+
mdxPassBuilder;
|
|
8
|
+
retainExistingMdxOutput = true;
|
|
9
|
+
mdxSnapshotInitialized = false;
|
|
10
|
+
successfulMdxPages = new Map();
|
|
11
|
+
successfulMdxContent = new Map();
|
|
12
|
+
successfulMdxSourcesBySlug = new Map();
|
|
13
|
+
collisionBlockedMdxSources = new Set();
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.mdxPassBuilder = new MdxPassBuilder({
|
|
17
|
+
sourceFs: options.sourceFs,
|
|
18
|
+
getAllMdxFiles: () => options.getAllMdxFiles(),
|
|
19
|
+
getSections: () => options.getSections(),
|
|
20
|
+
loadSectionsConfig: () => options.loadSectionsConfig(),
|
|
21
|
+
withApiReferenceSection: (sections) => options.withApiReferenceSection(sections),
|
|
22
|
+
determineSectionForFile: (filePath, frontmatter, sections) => options.determineSectionForFile(filePath, frontmatter, sections),
|
|
23
|
+
resolveHttpMethod: (reference) => options.lookupOpenApi(reference)?.method,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
resetForInitialPublication() {
|
|
27
|
+
this.retainExistingMdxOutput = false;
|
|
28
|
+
}
|
|
29
|
+
successfulPages() {
|
|
30
|
+
return [...this.successfulMdxPages.values()];
|
|
31
|
+
}
|
|
32
|
+
occupiedSlugs() {
|
|
33
|
+
return new Set(this.successfulPages().map((page) => page.slug));
|
|
34
|
+
}
|
|
35
|
+
blockOpenApiPages(realPages) {
|
|
36
|
+
const blockedRealPages = [...realPages];
|
|
37
|
+
const blockedSlugs = new Set(blockedRealPages.map((page) => page.slug));
|
|
38
|
+
for (const page of this.successfulMdxPages.values()) {
|
|
39
|
+
if (blockedSlugs.has(page.slug))
|
|
40
|
+
continue;
|
|
41
|
+
blockedSlugs.add(page.slug);
|
|
42
|
+
blockedRealPages.push(page);
|
|
43
|
+
}
|
|
44
|
+
return blockedRealPages;
|
|
45
|
+
}
|
|
46
|
+
async captureMdxPass(files, seededSources = new Map(), refreshSections = false) {
|
|
47
|
+
return this.mdxPassBuilder.capture(files, seededSources, refreshSections);
|
|
48
|
+
}
|
|
49
|
+
async buildRealPagesMeta() {
|
|
50
|
+
return (await this.captureMdxPass()).pages;
|
|
51
|
+
}
|
|
52
|
+
async buildAllPagesMeta() {
|
|
53
|
+
const real = await this.buildRealPagesMeta();
|
|
54
|
+
const successful = this.mdxSnapshotInitialized
|
|
55
|
+
? this.successfulPagesInSourceOrder(real)
|
|
56
|
+
: real;
|
|
57
|
+
return this.mergeAllPagesMeta(successful, new Set([...real, ...successful].map((page) => page.slug)));
|
|
58
|
+
}
|
|
59
|
+
mergeAllPagesMeta(real, declaredRealSlugs = new Set(real.map((page) => page.slug))) {
|
|
60
|
+
return mergePages(real, this.options.isOpenApiRegistryEmpty()
|
|
61
|
+
? []
|
|
62
|
+
: this.options
|
|
63
|
+
.syntheticOpenApiPages()
|
|
64
|
+
.filter((page) => !declaredRealSlugs.has(page.slug)));
|
|
65
|
+
}
|
|
66
|
+
successfulPagesInSourceOrder(realPages) {
|
|
67
|
+
const currentSources = new Set(realPages.map((page) => page.path.replace(/\\/g, "/")));
|
|
68
|
+
const ordered = realPages.flatMap((page) => {
|
|
69
|
+
const successful = this.successfulMdxPages.get(page.path.replace(/\\/g, "/"));
|
|
70
|
+
return successful ? [successful] : [];
|
|
71
|
+
});
|
|
72
|
+
for (const [source, page] of this.successfulMdxPages) {
|
|
73
|
+
if (!currentSources.has(source))
|
|
74
|
+
ordered.push(page);
|
|
75
|
+
}
|
|
76
|
+
return ordered;
|
|
77
|
+
}
|
|
78
|
+
recordSuccessfulMdxPage(page, sourceContent) {
|
|
79
|
+
const source = page.path.replace(/\\/g, "/");
|
|
80
|
+
const previous = this.successfulMdxPages.get(source);
|
|
81
|
+
if (previous &&
|
|
82
|
+
previous.slug !== page.slug &&
|
|
83
|
+
this.successfulMdxSourcesBySlug.get(previous.slug) === source) {
|
|
84
|
+
this.successfulMdxSourcesBySlug.delete(previous.slug);
|
|
85
|
+
}
|
|
86
|
+
const otherSource = this.successfulMdxSourcesBySlug.get(page.slug);
|
|
87
|
+
if (otherSource && otherSource !== source) {
|
|
88
|
+
this.removeSuccessfulMdxPage(otherSource);
|
|
89
|
+
}
|
|
90
|
+
this.successfulMdxPages.set(source, page);
|
|
91
|
+
this.successfulMdxContent.set(source, sourceContent);
|
|
92
|
+
this.successfulMdxSourcesBySlug.set(page.slug, source);
|
|
93
|
+
this.collisionBlockedMdxSources.delete(source);
|
|
94
|
+
}
|
|
95
|
+
removeSuccessfulMdxPage(source) {
|
|
96
|
+
const successful = this.successfulMdxPages.get(source);
|
|
97
|
+
if (successful &&
|
|
98
|
+
this.successfulMdxSourcesBySlug.get(successful.slug) === source) {
|
|
99
|
+
this.successfulMdxSourcesBySlug.delete(successful.slug);
|
|
100
|
+
}
|
|
101
|
+
this.successfulMdxPages.delete(source);
|
|
102
|
+
this.successfulMdxContent.delete(source);
|
|
103
|
+
}
|
|
104
|
+
captureSuccessfulMdxState() {
|
|
105
|
+
return {
|
|
106
|
+
pages: new Map(this.successfulMdxPages),
|
|
107
|
+
content: new Map(this.successfulMdxContent),
|
|
108
|
+
sourcesBySlug: new Map(this.successfulMdxSourcesBySlug),
|
|
109
|
+
collisionBlockedSources: new Set(this.collisionBlockedMdxSources),
|
|
110
|
+
sections: this.options.getSections()?.map((section) => ({ ...section })) ?? null,
|
|
111
|
+
routes: this.options.getMdxRoutes(),
|
|
112
|
+
snapshotInitialized: this.mdxSnapshotInitialized,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
restoreSuccessfulMdxState(state) {
|
|
116
|
+
this.successfulMdxPages = state.pages;
|
|
117
|
+
this.successfulMdxContent = state.content;
|
|
118
|
+
this.successfulMdxSourcesBySlug = state.sourcesBySlug;
|
|
119
|
+
this.collisionBlockedMdxSources = state.collisionBlockedSources;
|
|
120
|
+
this.options.setSections(state.sections);
|
|
121
|
+
this.mdxSnapshotInitialized = state.snapshotInitialized;
|
|
122
|
+
}
|
|
123
|
+
async rollbackPageCommits(commits) {
|
|
124
|
+
const errors = [];
|
|
125
|
+
for (const commit of [...commits].reverse()) {
|
|
126
|
+
try {
|
|
127
|
+
await commit.rollback();
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
errors.push(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return errors;
|
|
134
|
+
}
|
|
135
|
+
async rollbackFailedMdxCommit(error, state, commits) {
|
|
136
|
+
this.restoreSuccessfulMdxState(state);
|
|
137
|
+
const rollbackErrors = await this.rollbackPageCommits(commits);
|
|
138
|
+
if (rollbackErrors.length > 0) {
|
|
139
|
+
throw new AggregateError([error, ...rollbackErrors], "Unable to commit or restore generated MDX pages");
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
async rollbackCommittedMdxChange(error, state, commits) {
|
|
144
|
+
this.restoreSuccessfulMdxState(state);
|
|
145
|
+
const rollbackErrors = await this.rollbackPageCommits(commits);
|
|
146
|
+
const previousPages = [...state.pages.values()];
|
|
147
|
+
for (const page of previousPages) {
|
|
148
|
+
if (page.slug === "")
|
|
149
|
+
continue;
|
|
150
|
+
const content = state.content.get(page.path.replace(/\\/g, "/"));
|
|
151
|
+
if (content === undefined)
|
|
152
|
+
continue;
|
|
153
|
+
try {
|
|
154
|
+
await this.writePageForFile(page.path, content);
|
|
155
|
+
}
|
|
156
|
+
catch (rollbackError) {
|
|
157
|
+
rollbackErrors.push(rollbackError);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
await this.options.replaceMdxRoutes(state.routes.map(({ source, slug }) => ({ source, slug })));
|
|
162
|
+
}
|
|
163
|
+
catch (rollbackError) {
|
|
164
|
+
rollbackErrors.push(rollbackError);
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
await this.refreshMdxDerivedOutput(previousPages, previousPages);
|
|
168
|
+
}
|
|
169
|
+
catch (rollbackError) {
|
|
170
|
+
rollbackErrors.push(rollbackError);
|
|
171
|
+
}
|
|
172
|
+
if (rollbackErrors.length > 0) {
|
|
173
|
+
throw new AggregateError([error, ...rollbackErrors], "Unable to refresh or restore generated MDX output");
|
|
174
|
+
}
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
dropMissingMdxSnapshots(realPages) {
|
|
178
|
+
const currentSources = new Set(realPages.map((page) => page.path.replace(/\\/g, "/")));
|
|
179
|
+
for (const source of this.successfulMdxPages.keys()) {
|
|
180
|
+
if (currentSources.has(source))
|
|
181
|
+
continue;
|
|
182
|
+
this.removeSuccessfulMdxPage(source);
|
|
183
|
+
this.collisionBlockedMdxSources.delete(source);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async commitMdxSnapshot(realPages) {
|
|
187
|
+
this.dropMissingMdxSnapshots(realPages);
|
|
188
|
+
const successfulPages = this.successfulPagesInSourceOrder(realPages);
|
|
189
|
+
const previousRoutes = this.options.getMdxRoutes();
|
|
190
|
+
await this.options.generatedRouteManager.replaceMdxRoutes(successfulPages);
|
|
191
|
+
try {
|
|
192
|
+
await this.options.generatedRouteManager.removeStaleMdxRoutes(successfulPages, (slug) => this.options.removeOwnedRoute(slug), previousRoutes);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
console.error(chalk.red("❌ Error removing stale MDX routes; cleanup will retry:"), error);
|
|
196
|
+
}
|
|
197
|
+
this.mdxSnapshotInitialized = true;
|
|
198
|
+
return successfulPages;
|
|
199
|
+
}
|
|
200
|
+
async refreshMdxDerivedOutput(realPages, successfulPages) {
|
|
201
|
+
if (!this.options.isOpenApiRegistryEmpty() ||
|
|
202
|
+
this.options.getOpenApiRoutes().length > 0) {
|
|
203
|
+
await this.options.writeApiPages(realPages);
|
|
204
|
+
}
|
|
205
|
+
const declaredSlugs = new Set(realPages.map((page) => page.slug));
|
|
206
|
+
const pages = this.mergeAllPagesMeta(successfulPages, declaredSlugs);
|
|
207
|
+
await this.refreshSiteAggregates(pages, declaredSlugs);
|
|
208
|
+
}
|
|
209
|
+
async readAggregateMdxSource(filePath) {
|
|
210
|
+
const cached = this.successfulMdxContent.get(filePath.replace(/\\/g, "/"));
|
|
211
|
+
if (this.mdxSnapshotInitialized && cached !== undefined) {
|
|
212
|
+
return { content: cached };
|
|
213
|
+
}
|
|
214
|
+
return this.options.sourceFs.readMdxSourceFile(filePath);
|
|
215
|
+
}
|
|
216
|
+
homepageSource(frontmatter, mdxContent) {
|
|
217
|
+
return {
|
|
218
|
+
content: mdxContent,
|
|
219
|
+
title: frontmatter.title || "Welcome",
|
|
220
|
+
description: frontmatter.description || "",
|
|
221
|
+
icon: frontmatter.icon,
|
|
222
|
+
image: frontmatter.image,
|
|
223
|
+
name: frontmatter.name,
|
|
224
|
+
date: typeof frontmatter.date === "string" ? frontmatter.date : undefined,
|
|
225
|
+
updated: typeof frontmatter.updated === "string"
|
|
226
|
+
? frontmatter.updated
|
|
227
|
+
: undefined,
|
|
228
|
+
openapi: typeof frontmatter.openapi === "string"
|
|
229
|
+
? frontmatter.openapi
|
|
230
|
+
: undefined,
|
|
231
|
+
rss: frontmatter.rss === true,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
async readHomepageSource(pages) {
|
|
235
|
+
const files = pages
|
|
236
|
+
? pages
|
|
237
|
+
.map((page) => page.path)
|
|
238
|
+
.filter((file) => file === "index.mdx" || file === "./index.mdx")
|
|
239
|
+
: await this.options.getAllMdxFiles();
|
|
240
|
+
for (const file of files) {
|
|
241
|
+
if (file !== "index.mdx" && file !== "./index.mdx")
|
|
242
|
+
continue;
|
|
243
|
+
const cached = this.successfulMdxContent.get(file.replace(/\\/g, "/"));
|
|
244
|
+
if (this.mdxSnapshotInitialized && cached === undefined)
|
|
245
|
+
break;
|
|
246
|
+
const content = cached ?? (await this.options.sourceFs.readMdxSourceFile(file)).content;
|
|
247
|
+
const { data: frontmatter, content: mdxContent } = safeMatter(content, file);
|
|
248
|
+
return this.homepageSource(frontmatter, mdxContent);
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
async writePageForFile(filePath, content) {
|
|
253
|
+
const commits = [];
|
|
254
|
+
const { data: frontmatter, content: mdxContent } = safeMatter(content, filePath);
|
|
255
|
+
const { sectionSlug, pageSlug } = this.options.determineSectionForFile(filePath, frontmatter);
|
|
256
|
+
const fullSlug = getFullSlug(pageSlug, sectionSlug);
|
|
257
|
+
const isIndex = filePath === "index.mdx" || filePath === "./index.mdx";
|
|
258
|
+
const isSectionIndex = this.options.getSections() && pageSlug === "" && sectionSlug !== "";
|
|
259
|
+
try {
|
|
260
|
+
if (isIndex) {
|
|
261
|
+
// The homepage is emitted by updatePagesIndex() in the aggregate pass,
|
|
262
|
+
// so there is no per-file page to write here.
|
|
263
|
+
console.log(chalk.blue("🏠 Updating homepage with index.mdx content"));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const mdxFile = {
|
|
267
|
+
path: filePath,
|
|
268
|
+
content: mdxContent,
|
|
269
|
+
frontmatter,
|
|
270
|
+
slug: fullSlug,
|
|
271
|
+
};
|
|
272
|
+
let apiOperation;
|
|
273
|
+
if (frontmatter.openapi) {
|
|
274
|
+
apiOperation = this.options.lookupOpenApi(String(frontmatter.openapi));
|
|
275
|
+
if (!apiOperation) {
|
|
276
|
+
console.error(chalk.red(`❌ openapi frontmatter "${frontmatter.openapi}" in ${filePath} not found in any spec`));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
commits.push(await this.options.generatePageFromMdx(mdxFile, apiOperation ? { apiOperation } : undefined));
|
|
280
|
+
}
|
|
281
|
+
if (isSectionIndex) {
|
|
282
|
+
commits.push(await this.options.updateSectionIndex(sectionSlug, frontmatter, mdxContent, filePath));
|
|
283
|
+
}
|
|
284
|
+
return commits;
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const rollbackErrors = await this.rollbackPageCommits(commits);
|
|
288
|
+
if (rollbackErrors.length > 0) {
|
|
289
|
+
throw new AggregateError([error, ...rollbackErrors], `Unable to generate or restore ${filePath}`);
|
|
290
|
+
}
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async retryMdxPages(snapshot, shouldRetry, commits) {
|
|
295
|
+
for (const page of snapshot.pages) {
|
|
296
|
+
const source = page.path.replace(/\\/g, "/");
|
|
297
|
+
if (!shouldRetry(source, page))
|
|
298
|
+
continue;
|
|
299
|
+
const currentOwner = this.successfulMdxSourcesBySlug.get(page.slug);
|
|
300
|
+
if (currentOwner && currentOwner !== source)
|
|
301
|
+
continue;
|
|
302
|
+
const captured = snapshot.sources.get(source);
|
|
303
|
+
if (!captured)
|
|
304
|
+
continue;
|
|
305
|
+
try {
|
|
306
|
+
commits.push(...(await this.writePageForFile(page.path, captured.content)));
|
|
307
|
+
this.recordSuccessfulMdxPage(page, captured.content);
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
console.error(chalk.red(`❌ Error processing ${page.path}:`), error);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async refreshSiteAggregates(resolvedPages, declaredSlugs) {
|
|
315
|
+
const pages = resolvedPages ?? (await this.buildAllPagesMeta());
|
|
316
|
+
await this.options.updatePagesIndex(pages);
|
|
317
|
+
await this.options.updateRootLayout(pages);
|
|
318
|
+
await this.options.updateSitemap(pages);
|
|
319
|
+
await this.options.updateLlmsFiles(pages);
|
|
320
|
+
await this.options.generateSectionIndexPages(pages, declaredSlugs);
|
|
321
|
+
}
|
|
322
|
+
async handleFileChange(action, filePath) {
|
|
323
|
+
console.log(chalk.cyan(`📝 File ${action}: ${filePath}`));
|
|
324
|
+
const normalizedSource = filePath.replace(/\\/g, "/");
|
|
325
|
+
const changedSource = await this.options.sourceFs.readMdxSourceFile(filePath);
|
|
326
|
+
const previousState = this.captureSuccessfulMdxState();
|
|
327
|
+
const pageCommits = [];
|
|
328
|
+
let pageRendered = false;
|
|
329
|
+
try {
|
|
330
|
+
const snapshot = await this.captureMdxPass(undefined, new Map([[normalizedSource, changedSource]]), true);
|
|
331
|
+
const realPages = snapshot.pages;
|
|
332
|
+
const currentPage = realPages.find((page) => page.path.replace(/\\/g, "/") === normalizedSource);
|
|
333
|
+
if (!currentPage)
|
|
334
|
+
throw new Error(`Unable to resolve ${filePath}`);
|
|
335
|
+
this.options.setSections(snapshot.sections);
|
|
336
|
+
try {
|
|
337
|
+
pageCommits.push(...(await this.writePageForFile(filePath, changedSource.content)));
|
|
338
|
+
this.recordSuccessfulMdxPage(currentPage, changedSource.content);
|
|
339
|
+
pageRendered = true;
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (this.retainExistingMdxOutput) {
|
|
343
|
+
this.restoreSuccessfulMdxState(previousState);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
this.removeSuccessfulMdxPage(normalizedSource);
|
|
347
|
+
}
|
|
348
|
+
const successfulPages = await this.commitMdxSnapshot(realPages);
|
|
349
|
+
await this.refreshMdxDerivedOutput(realPages, successfulPages);
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
await this.retryMdxPages(snapshot, (source) => source !== normalizedSource &&
|
|
353
|
+
this.collisionBlockedMdxSources.has(source), pageCommits);
|
|
354
|
+
let successfulPages = [];
|
|
355
|
+
try {
|
|
356
|
+
successfulPages = await this.commitMdxSnapshot(realPages);
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
await this.rollbackFailedMdxCommit(error, previousState, pageCommits);
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
await this.refreshMdxDerivedOutput(realPages, successfulPages);
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
await this.rollbackCommittedMdxChange(error, previousState, pageCommits);
|
|
366
|
+
}
|
|
367
|
+
console.log(chalk.green(`✅ Generated page for: ${filePath}`));
|
|
368
|
+
await this.options.maybeUpdateSections();
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
if (!pageRendered && error instanceof RouteCollisionError) {
|
|
372
|
+
this.collisionBlockedMdxSources.add(normalizedSource);
|
|
373
|
+
for (const source of error.sources) {
|
|
374
|
+
this.collisionBlockedMdxSources.add(source.replace(/\\/g, "/"));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
console.error(chalk.red(`❌ Error processing ${filePath}:`), error);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async handleFileDelete(filePath) {
|
|
381
|
+
console.log(chalk.red(`🗑️ File deleted: ${filePath}`));
|
|
382
|
+
const previousState = this.captureSuccessfulMdxState();
|
|
383
|
+
const pageCommits = [];
|
|
384
|
+
try {
|
|
385
|
+
const normalizedSource = filePath.replace(/\\/g, "/");
|
|
386
|
+
if (filePath === "index.mdx" || filePath === "./index.mdx") {
|
|
387
|
+
console.log(chalk.blue("🏠 Updating homepage - index.mdx deleted"));
|
|
388
|
+
}
|
|
389
|
+
const snapshot = await this.captureMdxPass(undefined, undefined, true);
|
|
390
|
+
this.removeSuccessfulMdxPage(normalizedSource);
|
|
391
|
+
this.collisionBlockedMdxSources.delete(normalizedSource);
|
|
392
|
+
this.options.setSections(snapshot.sections);
|
|
393
|
+
const realPages = snapshot.pages;
|
|
394
|
+
await this.retryMdxPages(snapshot, (source, page) => this.collisionBlockedMdxSources.has(source) ||
|
|
395
|
+
this.successfulMdxPages.get(source)?.slug !== page.slug, pageCommits);
|
|
396
|
+
let successfulPages = [];
|
|
397
|
+
try {
|
|
398
|
+
successfulPages = await this.commitMdxSnapshot(realPages);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
await this.rollbackFailedMdxCommit(error, previousState, pageCommits);
|
|
402
|
+
}
|
|
403
|
+
try {
|
|
404
|
+
await this.refreshMdxDerivedOutput(realPages, successfulPages);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
await this.rollbackCommittedMdxChange(error, previousState, pageCommits);
|
|
408
|
+
}
|
|
409
|
+
console.log(chalk.green(`✅ Removed page for: ${filePath}`));
|
|
410
|
+
await this.options.maybeUpdateSections();
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
console.error(chalk.red(`❌ Error removing page for ${filePath}:`), error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async processAllMdxFiles() {
|
|
417
|
+
const previousState = this.captureSuccessfulMdxState();
|
|
418
|
+
const pageCommits = [];
|
|
419
|
+
const files = await this.options.getAllMdxFiles();
|
|
420
|
+
let snapshot;
|
|
421
|
+
try {
|
|
422
|
+
snapshot = await this.captureMdxPass(files, undefined, true);
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
if (error instanceof RouteCollisionError) {
|
|
426
|
+
for (const source of files) {
|
|
427
|
+
this.collisionBlockedMdxSources.add(source.replace(/\\/g, "/"));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
432
|
+
this.options.setSections(snapshot.sections);
|
|
433
|
+
const realPages = snapshot.pages;
|
|
434
|
+
const pagesBySource = new Map(realPages.map((page) => [page.path.replace(/\\/g, "/"), page]));
|
|
435
|
+
for (const file of files) {
|
|
436
|
+
console.log(chalk.cyan(`📝 Processing: ${file}`));
|
|
437
|
+
const normalizedSource = file.replace(/\\/g, "/");
|
|
438
|
+
try {
|
|
439
|
+
const sourceContent = snapshot.sources.get(normalizedSource)?.content;
|
|
440
|
+
if (sourceContent === undefined) {
|
|
441
|
+
throw new Error(`Unable to snapshot ${file}`);
|
|
442
|
+
}
|
|
443
|
+
pageCommits.push(...(await this.writePageForFile(file, sourceContent)));
|
|
444
|
+
const page = pagesBySource.get(normalizedSource);
|
|
445
|
+
if (!page)
|
|
446
|
+
throw new Error(`Unable to resolve ${file}`);
|
|
447
|
+
this.recordSuccessfulMdxPage(page, sourceContent);
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
if (!this.retainExistingMdxOutput) {
|
|
451
|
+
this.removeSuccessfulMdxPage(normalizedSource);
|
|
452
|
+
}
|
|
453
|
+
console.error(chalk.red(`❌ Error processing ${file}:`), error);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
let successfulPages = [];
|
|
457
|
+
try {
|
|
458
|
+
successfulPages = await this.commitMdxSnapshot(realPages);
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
await this.rollbackFailedMdxCommit(error, previousState, pageCommits);
|
|
462
|
+
}
|
|
463
|
+
this.retainExistingMdxOutput = true;
|
|
464
|
+
try {
|
|
465
|
+
await this.refreshMdxDerivedOutput(realPages, successfulPages);
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
await this.rollbackCommittedMdxChange(error, previousState, pageCommits);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RouteArtifact } from "../lib/generated-artifacts.js";
|
|
2
|
+
import { OpenApiRegistry } from "../lib/openapi.js";
|
|
3
|
+
import type { NormalizedOpenApiSpec, PageMeta, SectionConfig } from "../lib/types.js";
|
|
4
|
+
import { SecureSourceFs } from "./secure-source-fs.js";
|
|
5
|
+
export interface ApiPageWriteOptions {
|
|
6
|
+
writtenRoutes?: Map<string, string>;
|
|
7
|
+
additionalPreviousRoutes?: Iterable<RouteArtifact>;
|
|
8
|
+
}
|
|
9
|
+
interface OpenApiRefreshCoordinatorOptions {
|
|
10
|
+
rootDir: string;
|
|
11
|
+
watchDir: string;
|
|
12
|
+
outputDir: string;
|
|
13
|
+
configFile: string;
|
|
14
|
+
apiBaseSlug: string;
|
|
15
|
+
sourceFs: SecureSourceFs;
|
|
16
|
+
getRegistry(): OpenApiRegistry;
|
|
17
|
+
setRegistry(registry: OpenApiRegistry): void;
|
|
18
|
+
getSpecs(): NormalizedOpenApiSpec[];
|
|
19
|
+
setSpecs(specs: NormalizedOpenApiSpec[]): void;
|
|
20
|
+
getSections(): SectionConfig[] | null;
|
|
21
|
+
setSections(sections: SectionConfig[] | null): void;
|
|
22
|
+
getOpenApiRoutes(): RouteArtifact[];
|
|
23
|
+
getSuccessfulMdxPages(): PageMeta[];
|
|
24
|
+
resolveSections(): Promise<SectionConfig[] | null>;
|
|
25
|
+
writeApiPages(realPages?: PageMeta[], options?: ApiPageWriteOptions): Promise<Map<string, string>>;
|
|
26
|
+
refreshSiteAggregates(): Promise<void>;
|
|
27
|
+
syncWatcher(): Promise<void>;
|
|
28
|
+
removeOwnedRoute(slug: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare class OpenApiRefreshCoordinator {
|
|
31
|
+
private readonly options;
|
|
32
|
+
constructor(options: OpenApiRefreshCoordinatorOptions);
|
|
33
|
+
loadInitialRegistry(): Promise<void>;
|
|
34
|
+
private sourceState;
|
|
35
|
+
private loadStableRegistry;
|
|
36
|
+
private applyStableRefresh;
|
|
37
|
+
private restorePreviousRefresh;
|
|
38
|
+
private applyRefresh;
|
|
39
|
+
handleOpenApiChange(): Promise<void>;
|
|
40
|
+
handleConfigChange(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|