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
package/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://docs.doccupine.com/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/header/graph.svg?subtitle=Documentation+made+simple.+Open+source.+AI-ready.&logo=https%3A%2F%2Ffiles.riangle.com%2Fdoccupine%2Fpictogram.png&size=wide&mode=dark&font=geist&image=http%3A%2F%2Ffiles.riangle.com%2Fdoccupine%2Fcover.png&overlay=0" /><img alt="Doccupine" src="https://shieldcn.dev/header/graph.svg?subtitle=Documentation+made+simple.+Open+source.+AI-ready.&logo=https%3A%2F%2Ffiles.riangle.com%2Fdoccupine%2Fpictogram.png&size=wide&mode=light&font=geist&image=http%3A%2F%2Ffiles.riangle.com%2Fdoccupine%2Fcover.png&overlay=0" /></picture></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/doccupine"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/npm/doccupine.svg" /><img alt="badge" src="https://shieldcn.dev/npm/doccupine.svg?mode=light" /></picture></a>
|
|
7
|
+
<a href="https://github.com/doccupine/cli"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/github/doccupine/cli/stars.svg" /><img alt="badge" src="https://shieldcn.dev/github/doccupine/cli/stars.svg?mode=light" /></picture></a>
|
|
8
|
+
<a href="https://docs.doccupine.com/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/badge/Docs.svg" /><img alt="badge" src="https://shieldcn.dev/badge/Docs.svg?mode=light" /></picture></a>
|
|
9
|
+
<a href="https://doccupine.com/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/badge/Website.svg" /><img alt="badge" src="https://shieldcn.dev/badge/Website.svg?mode=light" /></picture></a>
|
|
10
|
+
</p>
|
|
2
11
|
|
|
3
|
-
|
|
12
|
+
# Doccupine
|
|
4
13
|
|
|
5
14
|
[Doccupine](https://doccupine.com) is an open-source CLI that turns a directory of MDX files into a full-featured Next.js documentation website. Write your docs in Markdown, and Doccupine watches for changes, generates pages, and starts a live dev server automatically.
|
|
6
15
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -3,5 +3,12 @@ import type { EventEmitter } from "events";
|
|
|
3
3
|
export type WatchSignal = "SIGINT" | "SIGTERM";
|
|
4
4
|
type WatchChildProcess = EventEmitter & Pick<ChildProcess, "exitCode" | "signalCode" | "kill" | "pid">;
|
|
5
5
|
export declare function superviseWatchLifecycle(devServer: WatchChildProcess, stopGenerator: () => Promise<void>, signalSource?: EventEmitter): Promise<WatchSignal>;
|
|
6
|
+
/**
|
|
7
|
+
* Prints a command failure the way a CLI should: the actionable message first,
|
|
8
|
+
* nested causes indented under it, and the stack only when `--verbose` asked
|
|
9
|
+
* for it. Errors raised here are written for the person running the command,
|
|
10
|
+
* so a bare stack trace would bury the part that tells them what to do.
|
|
11
|
+
*/
|
|
12
|
+
export declare function reportCliError(error: unknown, argv?: readonly string[]): void;
|
|
6
13
|
export declare function runCli(argv?: string[]): Promise<void>;
|
|
7
14
|
export {};
|
package/dist/cli.js
CHANGED
|
@@ -122,6 +122,43 @@ export function superviseWatchLifecycle(devServer, stopGenerator, signalSource =
|
|
|
122
122
|
signalSource.once("SIGTERM", onSigterm);
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
+
function errorMessages(error, seen = new Set()) {
|
|
126
|
+
if (error === null || error === undefined || seen.has(error))
|
|
127
|
+
return [];
|
|
128
|
+
seen.add(error);
|
|
129
|
+
if (error instanceof AggregateError) {
|
|
130
|
+
// The aggregate's own message is a summary ("Unable to shut down
|
|
131
|
+
// cleanly"); the causes underneath it are what the user can act on.
|
|
132
|
+
return [
|
|
133
|
+
error.message,
|
|
134
|
+
...error.errors.flatMap((nested) => errorMessages(nested, seen)),
|
|
135
|
+
].filter(Boolean);
|
|
136
|
+
}
|
|
137
|
+
if (error instanceof Error) {
|
|
138
|
+
return [error.message, ...errorMessages(error.cause, seen)].filter(Boolean);
|
|
139
|
+
}
|
|
140
|
+
return [String(error)].filter(Boolean);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Prints a command failure the way a CLI should: the actionable message first,
|
|
144
|
+
* nested causes indented under it, and the stack only when `--verbose` asked
|
|
145
|
+
* for it. Errors raised here are written for the person running the command,
|
|
146
|
+
* so a bare stack trace would bury the part that tells them what to do.
|
|
147
|
+
*/
|
|
148
|
+
export function reportCliError(error, argv = process.argv) {
|
|
149
|
+
const [message, ...causes] = errorMessages(error);
|
|
150
|
+
console.error(chalk.red(`❌ ${message ?? "Unknown error"}`));
|
|
151
|
+
for (const cause of causes) {
|
|
152
|
+
console.error(chalk.red(` ↳ ${cause}`));
|
|
153
|
+
}
|
|
154
|
+
if (argv.includes("--verbose")) {
|
|
155
|
+
if (error instanceof Error && error.stack)
|
|
156
|
+
console.error(error.stack);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.error(chalk.gray(" Re-run with --verbose for the full stack."));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
125
162
|
async function dependencyFingerprint(outputDir, packageManager) {
|
|
126
163
|
const packageJson = await fs.readFile(path.join(outputDir, "package.json"), "utf8");
|
|
127
164
|
return createHash("sha256")
|
|
@@ -259,6 +296,9 @@ export async function runCli(argv) {
|
|
|
259
296
|
.alias("generate")
|
|
260
297
|
.description("Generate the Next.js app once without running its build")
|
|
261
298
|
.option("--reset", "Reset configuration and prompt for new directories")
|
|
299
|
+
// Accepted so the failure hint printed by reportCliError is actionable
|
|
300
|
+
// here too, not only under `watch`.
|
|
301
|
+
.option("--verbose", "Show verbose output")
|
|
262
302
|
.action(async (options) => {
|
|
263
303
|
const configManager = new ConfigManager();
|
|
264
304
|
const config = await configManager.getConfig({
|
|
@@ -273,6 +313,7 @@ export async function runCli(argv) {
|
|
|
273
313
|
.description("Show or reset configuration")
|
|
274
314
|
.option("--show", "Show current configuration")
|
|
275
315
|
.option("--reset", "Reset configuration")
|
|
316
|
+
.option("--verbose", "Show verbose output")
|
|
276
317
|
.action(async (options) => {
|
|
277
318
|
const configManager = new ConfigManager();
|
|
278
319
|
if (options.show) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MDXFile } from "../lib/types.js";
|
|
2
|
+
import type { OperationDescriptor } from "../lib/openapi-types.js";
|
|
3
|
+
import { type HomepageSource } from "./page-renderer.js";
|
|
4
|
+
import { GeneratedRouteManager } from "./generated-route-manager.js";
|
|
5
|
+
export interface GeneratedPageCommit {
|
|
6
|
+
rollback(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class GeneratedPagePublisher {
|
|
9
|
+
private readonly outputDir;
|
|
10
|
+
private readonly routeManager;
|
|
11
|
+
constructor(outputDir: string, routeManager: GeneratedRouteManager);
|
|
12
|
+
private generatedFileSegments;
|
|
13
|
+
private readGeneratedFile;
|
|
14
|
+
private restoreGeneratedFile;
|
|
15
|
+
private commitRenderedPage;
|
|
16
|
+
generatePageFromMdx(mdxFile: MDXFile, options?: {
|
|
17
|
+
apiOperation?: OperationDescriptor;
|
|
18
|
+
}): Promise<GeneratedPageCommit>;
|
|
19
|
+
updateHomepage(source: HomepageSource | null, apiOperation?: OperationDescriptor): Promise<GeneratedPageCommit>;
|
|
20
|
+
updateSectionIndex(sectionSlug: string, frontmatter: Record<string, any>, mdxContent: string, sourcePath?: string): Promise<GeneratedPageCommit>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readOutputFileIfPresent, resolveOutputPath, } from "../lib/output-safety.js";
|
|
4
|
+
import { writeFileAtomic } from "../lib/utils.js";
|
|
5
|
+
import { renderHomepage, renderMdxPage, renderSectionPage, } from "./page-renderer.js";
|
|
6
|
+
export class GeneratedPagePublisher {
|
|
7
|
+
outputDir;
|
|
8
|
+
routeManager;
|
|
9
|
+
constructor(outputDir, routeManager) {
|
|
10
|
+
this.outputDir = outputDir;
|
|
11
|
+
this.routeManager = routeManager;
|
|
12
|
+
}
|
|
13
|
+
generatedFileSegments(filePath) {
|
|
14
|
+
return path
|
|
15
|
+
.relative(fs.realpathSync(this.outputDir), filePath)
|
|
16
|
+
.split(path.sep)
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
}
|
|
19
|
+
async readGeneratedFile(filePath) {
|
|
20
|
+
return readOutputFileIfPresent(this.outputDir, ...this.generatedFileSegments(filePath));
|
|
21
|
+
}
|
|
22
|
+
async restoreGeneratedFile(filePath, content) {
|
|
23
|
+
const target = resolveOutputPath(this.outputDir, ...this.generatedFileSegments(filePath));
|
|
24
|
+
if (content === null) {
|
|
25
|
+
await fs.remove(target);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await writeFileAtomic(target, content);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async commitRenderedPage(pagePath, rendered) {
|
|
32
|
+
if (rendered.rssRoute.action === "preserve") {
|
|
33
|
+
const previousPage = await this.readGeneratedFile(pagePath);
|
|
34
|
+
await writeFileAtomic(pagePath, rendered.pageContent);
|
|
35
|
+
return {
|
|
36
|
+
rollback: () => this.restoreGeneratedFile(pagePath, previousPage),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const rssDir = resolveOutputPath(path.dirname(pagePath), "rss.xml");
|
|
40
|
+
const rssPath = resolveOutputPath(path.dirname(pagePath), "rss.xml", "route.ts");
|
|
41
|
+
const [previousPage, previousRss] = await Promise.all([
|
|
42
|
+
this.readGeneratedFile(pagePath),
|
|
43
|
+
this.readGeneratedFile(rssPath),
|
|
44
|
+
]);
|
|
45
|
+
let pageChanged = false;
|
|
46
|
+
let rssChanged = false;
|
|
47
|
+
try {
|
|
48
|
+
if (rendered.rssRoute.action === "write") {
|
|
49
|
+
await writeFileAtomic(rssPath, rendered.rssRoute.content);
|
|
50
|
+
rssChanged = true;
|
|
51
|
+
await writeFileAtomic(pagePath, rendered.pageContent);
|
|
52
|
+
pageChanged = true;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await writeFileAtomic(pagePath, rendered.pageContent);
|
|
56
|
+
pageChanged = true;
|
|
57
|
+
await fs.remove(rssPath);
|
|
58
|
+
rssChanged = true;
|
|
59
|
+
await this.routeManager.removeEmptyDirsUpTo(rssDir, path.dirname(pagePath));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const rollbackErrors = [];
|
|
64
|
+
if (rssChanged) {
|
|
65
|
+
try {
|
|
66
|
+
await this.restoreGeneratedFile(rssPath, previousRss);
|
|
67
|
+
}
|
|
68
|
+
catch (rollbackError) {
|
|
69
|
+
rollbackErrors.push(rollbackError);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (pageChanged) {
|
|
73
|
+
try {
|
|
74
|
+
await this.restoreGeneratedFile(pagePath, previousPage);
|
|
75
|
+
}
|
|
76
|
+
catch (rollbackError) {
|
|
77
|
+
rollbackErrors.push(rollbackError);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (rollbackErrors.length > 0) {
|
|
81
|
+
throw new AggregateError([error, ...rollbackErrors], `Unable to publish or restore generated page ${pagePath}`);
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
rollback: async () => {
|
|
87
|
+
const rollbackErrors = [];
|
|
88
|
+
try {
|
|
89
|
+
await this.restoreGeneratedFile(rssPath, previousRss);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
rollbackErrors.push(error);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await this.restoreGeneratedFile(pagePath, previousPage);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
rollbackErrors.push(error);
|
|
99
|
+
}
|
|
100
|
+
if (rollbackErrors.length > 0) {
|
|
101
|
+
throw new AggregateError(rollbackErrors, `Unable to restore generated page ${pagePath}`);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async generatePageFromMdx(mdxFile, options) {
|
|
107
|
+
const rendered = renderMdxPage(mdxFile, options);
|
|
108
|
+
const pagePath = resolveOutputPath(this.outputDir, "app", "(site)", mdxFile.slug, "page.tsx");
|
|
109
|
+
await fs.ensureDir(path.dirname(pagePath));
|
|
110
|
+
return this.commitRenderedPage(pagePath, rendered);
|
|
111
|
+
}
|
|
112
|
+
async updateHomepage(source, apiOperation) {
|
|
113
|
+
const rendered = renderHomepage(source, apiOperation);
|
|
114
|
+
const pagePath = resolveOutputPath(this.outputDir, "app", "(site)", "page.tsx");
|
|
115
|
+
await fs.ensureDir(path.dirname(pagePath));
|
|
116
|
+
return this.commitRenderedPage(pagePath, rendered);
|
|
117
|
+
}
|
|
118
|
+
async updateSectionIndex(sectionSlug, frontmatter, mdxContent, sourcePath) {
|
|
119
|
+
const rendered = renderSectionPage(sectionSlug, frontmatter, mdxContent, sourcePath);
|
|
120
|
+
const pagePath = resolveOutputPath(this.outputDir, "app", "(site)", sectionSlug, "page.tsx");
|
|
121
|
+
await fs.ensureDir(path.dirname(pagePath));
|
|
122
|
+
return this.commitRenderedPage(pagePath, rendered);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -8,11 +8,14 @@ export declare class GeneratedRouteManager {
|
|
|
8
8
|
constructor(outputDir: string, artifacts: GeneratedArtifacts);
|
|
9
9
|
private outputPath;
|
|
10
10
|
routeForMdxSource(source: string): string | undefined;
|
|
11
|
+
sectionIndexSlugs(): Set<string>;
|
|
12
|
+
replaceSectionIndexSlugs(slugs: Iterable<string>): void;
|
|
11
13
|
replaceMdxRoutes(realPages: PageMeta[]): Promise<void>;
|
|
12
14
|
removeMdxRoute(source: string): Promise<void>;
|
|
13
15
|
removeOwnedRoute(slug: string): Promise<void>;
|
|
14
16
|
removeStaleMdxRoutes(realPages: PageMeta[], removeOwnedRoute: (slug: string) => Promise<void>, previousRoutes?: readonly RouteArtifact[]): Promise<void>;
|
|
15
17
|
cleanupStaleSectionIndexPages(nextSlugs: Set<string>, occupiedSlugs: Set<string>, removeEmptyDirs: (dir: string, stopDir: string) => Promise<void>): Promise<void>;
|
|
18
|
+
private removeSectionIndexPage;
|
|
16
19
|
/** Best-effort removal of now-empty directories up to (not incl.) stopDir. */
|
|
17
20
|
removeEmptyDirsUpTo(dir: string, stopDir: string): Promise<void>;
|
|
18
21
|
}
|
|
@@ -17,6 +17,12 @@ export class GeneratedRouteManager {
|
|
|
17
17
|
routeForMdxSource(source) {
|
|
18
18
|
return this.artifacts.routeFor("mdx", source);
|
|
19
19
|
}
|
|
20
|
+
sectionIndexSlugs() {
|
|
21
|
+
return new Set(this.generatedSectionIndexSlugs);
|
|
22
|
+
}
|
|
23
|
+
replaceSectionIndexSlugs(slugs) {
|
|
24
|
+
this.generatedSectionIndexSlugs = new Set(slugs);
|
|
25
|
+
}
|
|
20
26
|
async replaceMdxRoutes(realPages) {
|
|
21
27
|
await this.artifacts.replaceRoutesAndSave("mdx", realPages
|
|
22
28
|
.filter((page) => page.slug !== "")
|
|
@@ -75,25 +81,32 @@ export class GeneratedRouteManager {
|
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
async cleanupStaleSectionIndexPages(nextSlugs, occupiedSlugs, removeEmptyDirs) {
|
|
84
|
+
const errors = [];
|
|
78
85
|
for (const stale of this.generatedSectionIndexSlugs) {
|
|
79
86
|
if (nextSlugs.has(stale))
|
|
80
87
|
continue;
|
|
81
88
|
if (occupiedSlugs.has(stale))
|
|
82
89
|
continue;
|
|
83
|
-
const pagePath = resolveOutputPath(this.outputDir, "app", "(site)", stale, "page.tsx");
|
|
84
90
|
try {
|
|
85
|
-
|
|
86
|
-
continue;
|
|
87
|
-
await fs.remove(pagePath);
|
|
88
|
-
await removeEmptyDirs(path.dirname(pagePath), this.outputPath("app", "(site)"));
|
|
89
|
-
console.log(chalk.blue(`🧹 Removed stale section index redirect: /${stale}`));
|
|
91
|
+
await this.removeSectionIndexPage(stale, removeEmptyDirs);
|
|
90
92
|
}
|
|
91
|
-
catch {
|
|
92
|
-
|
|
93
|
+
catch (error) {
|
|
94
|
+
errors.push(error);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
97
|
+
if (errors.length > 0) {
|
|
98
|
+
throw new AggregateError(errors, "Unable to remove stale section index redirects");
|
|
99
|
+
}
|
|
95
100
|
this.generatedSectionIndexSlugs = nextSlugs;
|
|
96
101
|
}
|
|
102
|
+
async removeSectionIndexPage(slug, removeEmptyDirs) {
|
|
103
|
+
const pagePath = resolveOutputPath(this.outputDir, "app", "(site)", slug, "page.tsx");
|
|
104
|
+
if (!(await fs.pathExists(pagePath)))
|
|
105
|
+
return;
|
|
106
|
+
await fs.remove(pagePath);
|
|
107
|
+
await removeEmptyDirs(path.dirname(pagePath), this.outputPath("app", "(site)"));
|
|
108
|
+
console.log(chalk.blue(`🧹 Removed stale section index redirect: /${slug}`));
|
|
109
|
+
}
|
|
97
110
|
/** Best-effort removal of now-empty directories up to (not incl.) stopDir. */
|
|
98
111
|
async removeEmptyDirsUpTo(dir, stopDir) {
|
|
99
112
|
const stop = path.resolve(stopDir);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Stats } from "node:fs";
|
|
2
|
+
import type { PageMeta, SectionConfig } from "../lib/types.js";
|
|
3
|
+
import { SecureSourceFs } from "./secure-source-fs.js";
|
|
4
|
+
export interface MdxSourceSnapshot {
|
|
5
|
+
content: string;
|
|
6
|
+
stat: Stats;
|
|
7
|
+
}
|
|
8
|
+
export interface MdxPassSnapshot {
|
|
9
|
+
files: string[];
|
|
10
|
+
pages: PageMeta[];
|
|
11
|
+
sources: ReadonlyMap<string, MdxSourceSnapshot>;
|
|
12
|
+
sections: SectionConfig[] | null;
|
|
13
|
+
}
|
|
14
|
+
interface MdxPassBuilderOptions {
|
|
15
|
+
sourceFs: SecureSourceFs;
|
|
16
|
+
getAllMdxFiles(): Promise<string[]>;
|
|
17
|
+
getSections(): SectionConfig[] | null;
|
|
18
|
+
loadSectionsConfig(): Promise<SectionConfig[] | null>;
|
|
19
|
+
withApiReferenceSection(sections: SectionConfig[] | null): SectionConfig[] | null;
|
|
20
|
+
determineSectionForFile(filePath: string, frontmatter: Record<string, any>, sections: SectionConfig[] | null): {
|
|
21
|
+
sectionSlug: string;
|
|
22
|
+
pageSlug: string;
|
|
23
|
+
};
|
|
24
|
+
resolveHttpMethod(reference: string): string | undefined;
|
|
25
|
+
}
|
|
26
|
+
export declare class MdxPassBuilder {
|
|
27
|
+
private readonly options;
|
|
28
|
+
constructor(options: MdxPassBuilderOptions);
|
|
29
|
+
capture(files?: string[], seededSources?: ReadonlyMap<string, MdxSourceSnapshot>, refreshSections?: boolean): Promise<MdxPassSnapshot>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { safeMatter } from "../lib/utils.js";
|
|
2
|
+
import { buildRealPagesMeta, parseMdxPageMeta } from "./page-catalog.js";
|
|
3
|
+
import { discoverSections } from "./section-resolver.js";
|
|
4
|
+
export class MdxPassBuilder {
|
|
5
|
+
options;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async capture(files, seededSources = new Map(), refreshSections = false) {
|
|
10
|
+
const resolvedFiles = files ?? (await this.options.getAllMdxFiles());
|
|
11
|
+
const sources = new Map(seededSources);
|
|
12
|
+
await Promise.all(resolvedFiles.map(async (file) => {
|
|
13
|
+
const source = file.replace(/\\/g, "/");
|
|
14
|
+
if (!sources.has(source)) {
|
|
15
|
+
sources.set(source, await this.options.sourceFs.readMdxSourceFile(file));
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
let sections = this.options.getSections();
|
|
19
|
+
if (refreshSections) {
|
|
20
|
+
const configuredSections = await this.options.loadSectionsConfig();
|
|
21
|
+
if (configuredSections !== null) {
|
|
22
|
+
sections = this.options.withApiReferenceSection(configuredSections);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const documents = resolvedFiles.map((filePath) => {
|
|
26
|
+
const source = sources.get(filePath.replace(/\\/g, "/"));
|
|
27
|
+
if (!source)
|
|
28
|
+
throw new Error(`Unable to snapshot ${filePath}`);
|
|
29
|
+
return {
|
|
30
|
+
filePath,
|
|
31
|
+
frontmatter: safeMatter(source.content, filePath).data,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
sections = this.options.withApiReferenceSection(discoverSections(documents));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const pages = await buildRealPagesMeta(resolvedFiles, async (file) => {
|
|
38
|
+
const source = sources.get(file.replace(/\\/g, "/"));
|
|
39
|
+
if (!source)
|
|
40
|
+
throw new Error(`Unable to snapshot ${file}`);
|
|
41
|
+
return parseMdxPageMeta(file, async () => source, (filePath, frontmatter) => this.options.determineSectionForFile(filePath, frontmatter, sections), (reference) => this.options.resolveHttpMethod(reference));
|
|
42
|
+
});
|
|
43
|
+
return { files: resolvedFiles, pages, sources, sections };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { RouteArtifact } from "../lib/generated-artifacts.js";
|
|
2
|
+
import type { OperationDescriptor } from "../lib/openapi-types.js";
|
|
3
|
+
import type { MDXFile, PageMeta, SectionConfig } from "../lib/types.js";
|
|
4
|
+
import type { GeneratedPageCommit } from "./generated-page-publisher.js";
|
|
5
|
+
import { GeneratedRouteManager } from "./generated-route-manager.js";
|
|
6
|
+
import { type HomepageSource } from "./page-renderer.js";
|
|
7
|
+
import { SecureSourceFs } from "./secure-source-fs.js";
|
|
8
|
+
interface MdxReconciliationCoordinatorOptions {
|
|
9
|
+
sourceFs: SecureSourceFs;
|
|
10
|
+
generatedRouteManager: GeneratedRouteManager;
|
|
11
|
+
getAllMdxFiles(): Promise<string[]>;
|
|
12
|
+
getSections(): SectionConfig[] | null;
|
|
13
|
+
setSections(sections: SectionConfig[] | null): void;
|
|
14
|
+
loadSectionsConfig(): Promise<SectionConfig[] | null>;
|
|
15
|
+
withApiReferenceSection(sections: SectionConfig[] | null): SectionConfig[] | null;
|
|
16
|
+
determineSectionForFile(filePath: string, frontmatter: Record<string, any>, sections?: SectionConfig[] | null): {
|
|
17
|
+
sectionSlug: string;
|
|
18
|
+
pageSlug: string;
|
|
19
|
+
};
|
|
20
|
+
lookupOpenApi(reference: string): OperationDescriptor | undefined;
|
|
21
|
+
isOpenApiRegistryEmpty(): boolean;
|
|
22
|
+
syntheticOpenApiPages(): PageMeta[];
|
|
23
|
+
getMdxRoutes(): RouteArtifact[];
|
|
24
|
+
getOpenApiRoutes(): RouteArtifact[];
|
|
25
|
+
replaceMdxRoutes(routes: Iterable<{
|
|
26
|
+
source: string;
|
|
27
|
+
slug: string;
|
|
28
|
+
}>): Promise<void>;
|
|
29
|
+
generatePageFromMdx(mdxFile: MDXFile, options?: {
|
|
30
|
+
apiOperation?: OperationDescriptor;
|
|
31
|
+
}): Promise<GeneratedPageCommit>;
|
|
32
|
+
updateSectionIndex(sectionSlug: string, frontmatter: Record<string, any>, mdxContent: string, sourcePath?: string): Promise<GeneratedPageCommit>;
|
|
33
|
+
writeApiPages(realPages?: PageMeta[]): Promise<Map<string, string>>;
|
|
34
|
+
updatePagesIndex(pages?: readonly PageMeta[]): Promise<void>;
|
|
35
|
+
updateRootLayout(pages?: PageMeta[]): Promise<void>;
|
|
36
|
+
updateSitemap(pages?: PageMeta[]): Promise<void>;
|
|
37
|
+
updateLlmsFiles(pages?: PageMeta[]): Promise<void>;
|
|
38
|
+
generateSectionIndexPages(pages?: PageMeta[], declaredSlugs?: Set<string>): Promise<void>;
|
|
39
|
+
maybeUpdateSections(): Promise<void>;
|
|
40
|
+
removeOwnedRoute(slug: string): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export declare class MdxReconciliationCoordinator {
|
|
43
|
+
private readonly options;
|
|
44
|
+
private readonly mdxPassBuilder;
|
|
45
|
+
private retainExistingMdxOutput;
|
|
46
|
+
private mdxSnapshotInitialized;
|
|
47
|
+
private successfulMdxPages;
|
|
48
|
+
private successfulMdxContent;
|
|
49
|
+
private successfulMdxSourcesBySlug;
|
|
50
|
+
private collisionBlockedMdxSources;
|
|
51
|
+
constructor(options: MdxReconciliationCoordinatorOptions);
|
|
52
|
+
resetForInitialPublication(): void;
|
|
53
|
+
successfulPages(): PageMeta[];
|
|
54
|
+
occupiedSlugs(): Set<string>;
|
|
55
|
+
blockOpenApiPages(realPages: PageMeta[]): PageMeta[];
|
|
56
|
+
private captureMdxPass;
|
|
57
|
+
buildRealPagesMeta(): Promise<PageMeta[]>;
|
|
58
|
+
buildAllPagesMeta(): Promise<PageMeta[]>;
|
|
59
|
+
private mergeAllPagesMeta;
|
|
60
|
+
private successfulPagesInSourceOrder;
|
|
61
|
+
private recordSuccessfulMdxPage;
|
|
62
|
+
private removeSuccessfulMdxPage;
|
|
63
|
+
private captureSuccessfulMdxState;
|
|
64
|
+
private restoreSuccessfulMdxState;
|
|
65
|
+
private rollbackPageCommits;
|
|
66
|
+
private rollbackFailedMdxCommit;
|
|
67
|
+
private rollbackCommittedMdxChange;
|
|
68
|
+
private dropMissingMdxSnapshots;
|
|
69
|
+
private commitMdxSnapshot;
|
|
70
|
+
private refreshMdxDerivedOutput;
|
|
71
|
+
readAggregateMdxSource(filePath: string): Promise<{
|
|
72
|
+
content: string;
|
|
73
|
+
}>;
|
|
74
|
+
private homepageSource;
|
|
75
|
+
readHomepageSource(pages?: readonly PageMeta[]): Promise<HomepageSource | null>;
|
|
76
|
+
private writePageForFile;
|
|
77
|
+
private retryMdxPages;
|
|
78
|
+
refreshSiteAggregates(resolvedPages?: PageMeta[], declaredSlugs?: Set<string>): Promise<void>;
|
|
79
|
+
handleFileChange(action: string, filePath: string): Promise<void>;
|
|
80
|
+
handleFileDelete(filePath: string): Promise<void>;
|
|
81
|
+
processAllMdxFiles(): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
export {};
|