@lukoweb/apitogo 0.2.59 → 0.2.61

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 (43) hide show
  1. package/dist/cli/cli.js +897 -527
  2. package/docs/cli/commands.md +6 -6
  3. package/docs/cli/go-live.md +12 -12
  4. package/docs/cli/overview.md +26 -27
  5. package/docs/cli/setup.md +38 -46
  6. package/docs/cli/shape.md +32 -35
  7. package/docs/cli/walkthrough.md +19 -19
  8. package/docs/components/slot.mdx +116 -116
  9. package/docs/configuration/api-reference.md +1 -1
  10. package/docs/configuration/authentication.md +3 -3
  11. package/docs/configuration/footer.mdx +89 -89
  12. package/docs/configuration/gateway.md +8 -8
  13. package/docs/configuration/make-config.mdx +20 -10
  14. package/docs/configuration/overview.md +3 -3
  15. package/docs/configuration/plans.md +5 -5
  16. package/docs/configuration/portal.md +36 -0
  17. package/docs/customization/colors-theme.mdx +255 -255
  18. package/docs/customization/fonts.md +105 -105
  19. package/docs/customization/landing-page.md +1 -1
  20. package/docs/deploy/apitogo.md +3 -3
  21. package/docs/deployment.md +3 -3
  22. package/docs/guides/custom-pages.md +3 -3
  23. package/docs/guides/customer-account.md +1 -1
  24. package/docs/guides/stripe-setup.mdx +9 -9
  25. package/docs/markdown/frontmatter.md +2 -2
  26. package/docs/mcp/go-live.md +7 -7
  27. package/docs/mcp/overview.md +58 -58
  28. package/docs/mcp/setup.md +6 -6
  29. package/docs/mcp/shape.md +2 -2
  30. package/docs/mcp/tools.md +57 -57
  31. package/docs/quickstart.md +6 -4
  32. package/docs/writing.mdx +68 -68
  33. package/package.json +1 -1
  34. package/src/config/apitogo-config-core.ts +11 -1
  35. package/src/config/v2/resolve.ts +19 -0
  36. package/src/config/v2/rules.ts +88 -0
  37. package/src/config/v2/schema.ts +28 -0
  38. package/src/config/v2/wrapper.ts +85 -13
  39. package/src/vite/config.ts +278 -273
  40. package/src/vite/markdown-output-path.ts +48 -0
  41. package/src/vite/plugin-markdown-export.ts +210 -214
  42. package/src/vite/prerender/prerender.ts +4 -4
  43. package/src/vite/watch-ignore.ts +19 -0
@@ -1,214 +1,210 @@
1
- import { mkdir, writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { matchPath } from "react-router";
4
- import type { Plugin } from "vite";
5
- import { getCurrentConfig } from "../config/loader.js";
6
- import { ProtectedRoutesSchema } from "../config/validators/ProtectedRoutesSchema.js";
7
- import { joinUrl } from "../lib/util/joinUrl.js";
8
- import { readFrontmatter } from "../lib/util/readFrontmatter.js";
9
- import {
10
- globMarkdownFiles,
11
- resolveCustomNavigationPaths,
12
- } from "./plugin-docs.js";
13
-
14
- export type MarkdownFileInfo = {
15
- filePath: string;
16
- routePath: string;
17
- title?: string;
18
- description?: string;
19
- content: string;
20
- };
21
-
22
- const processMarkdownFile = async (
23
- filePath: string,
24
- ): Promise<{ content: string; title?: string; description?: string }> => {
25
- const { content: markdownContent, data: frontmatter } =
26
- await readFrontmatter(filePath);
27
-
28
- let finalMarkdown = markdownContent;
29
- if (frontmatter.title) {
30
- // Add title as H1 at the beginning, matching the behavior in MdxPage.tsx
31
- finalMarkdown = `# ${frontmatter.title}\n${markdownContent}`;
32
- }
33
-
34
- return {
35
- content: finalMarkdown,
36
- title: frontmatter.title,
37
- description: frontmatter.description,
38
- };
39
- };
40
-
41
- /**
42
- * This plugin exports markdown files (.md) for each document during the build process.
43
- * In development mode, you can access documents at their URL path with .md extension
44
- * (e.g., /foo/hello.md) to get the raw markdown without frontmatter.
45
- *
46
- * Markdown files are generated when:
47
- * - publishMarkdown is enabled (for copy button functionality)
48
- * - llmsTxt or llmsTxtFull is enabled (for generating llms.txt files)
49
- *
50
- * It also writes metadata to markdown-info.json used by the llms.txt generator.
51
- */
52
- const viteMarkdownExportPlugin = (): Plugin => {
53
- let markdownFiles: Record<string, string> = {};
54
- let markdownFileInfos: MarkdownFileInfo[] = [];
55
-
56
- return {
57
- name: "zudoku-markdown-export-plugin",
58
- applyToEnvironment(env) {
59
- return env.name === "ssr";
60
- },
61
- async buildStart() {
62
- const config = getCurrentConfig();
63
- const llmsConfig = config.docs?.llms;
64
-
65
- const needsMdFiles =
66
- config.docs?.publishMarkdown ||
67
- llmsConfig?.llmsTxt ||
68
- llmsConfig?.llmsTxtFull;
69
-
70
- if (config.__meta.mode === "standalone" || !needsMdFiles) {
71
- return;
72
- }
73
-
74
- markdownFiles = await resolveCustomNavigationPaths(
75
- config,
76
- await globMarkdownFiles(config, { absolute: true }),
77
- );
78
-
79
- // Filter out protected routes unless `includeProtected` is true
80
- if (!llmsConfig?.includeProtected) {
81
- const protectedRoutes = ProtectedRoutesSchema.parse(
82
- config.protectedRoutes,
83
- );
84
- if (protectedRoutes) {
85
- const isProtectedRoute = (routePath: string): boolean => {
86
- return Object.keys(protectedRoutes).some((route) =>
87
- matchPath({ path: route, end: true }, routePath),
88
- );
89
- };
90
-
91
- // Remove protected routes from the mapping
92
- for (const routePath of Object.keys(markdownFiles)) {
93
- if (isProtectedRoute(routePath)) {
94
- delete markdownFiles[routePath];
95
- }
96
- }
97
- }
98
- }
99
- },
100
- async configureServer(server) {
101
- const config = getCurrentConfig();
102
- const llmsConfig = config.docs?.llms;
103
-
104
- // Serve .md files if markdown export is needed
105
- const needsMdFiles =
106
- config.docs?.publishMarkdown ||
107
- llmsConfig?.llmsTxt ||
108
- llmsConfig?.llmsTxtFull;
109
-
110
- if (!needsMdFiles) return;
111
-
112
- markdownFiles = await resolveCustomNavigationPaths(
113
- config,
114
- await globMarkdownFiles(config, { absolute: true }),
115
- );
116
-
117
- server.middlewares.use(async (req, res, next) => {
118
- if (req.method !== "GET" || !req.url?.endsWith(".md")) {
119
- return next();
120
- }
121
-
122
- const basePath = joinUrl(config.basePath);
123
- const routePath = joinUrl(
124
- req.url.slice(basePath.length).replace(/\.mdx?$/, ""),
125
- );
126
- const filePath = markdownFiles[routePath];
127
-
128
- if (!filePath) return next();
129
-
130
- try {
131
- const { content } = await processMarkdownFile(filePath);
132
- res.setHeader("Content-Type", "text/markdown; charset=utf-8");
133
- res.end(content);
134
- } catch (error) {
135
- // biome-ignore lint/suspicious/noConsole: Logging allowed here
136
- console.warn(`Failed to serve markdown for ${routePath}:`, error);
137
- return next();
138
- }
139
- });
140
- },
141
- async closeBundle() {
142
- const config = getCurrentConfig();
143
- const llmsConfig = config.docs?.llms;
144
-
145
- const needsMdFiles =
146
- config.docs?.publishMarkdown ||
147
- llmsConfig?.llmsTxt ||
148
- llmsConfig?.llmsTxtFull;
149
-
150
- if (
151
- process.env.NODE_ENV !== "production" ||
152
- Object.keys(markdownFiles).length === 0 ||
153
- !needsMdFiles
154
- ) {
155
- return;
156
- }
157
-
158
- // During build, write .md files to the dist directory
159
- const distDir = path.join(
160
- config.__meta.rootDir,
161
- "dist",
162
- config.basePath ?? "",
163
- );
164
-
165
- markdownFileInfos = [];
166
-
167
- for (const [routePath, filePath] of Object.entries(markdownFiles)) {
168
- try {
169
- const {
170
- content: finalMarkdown,
171
- title,
172
- description,
173
- } = await processMarkdownFile(filePath);
174
-
175
- markdownFileInfos.push({
176
- filePath,
177
- routePath,
178
- title,
179
- description,
180
- content: finalMarkdown,
181
- });
182
-
183
- const segments =
184
- routePath === "/"
185
- ? ["index"]
186
- : routePath.split("/").filter(Boolean);
187
-
188
- const outputPath = `${path.join(distDir, ...segments)}.md`;
189
-
190
- await mkdir(path.dirname(outputPath), { recursive: true });
191
-
192
- await writeFile(outputPath, finalMarkdown, "utf-8");
193
- } catch (error) {
194
- // biome-ignore lint/suspicious/noConsole: Logging allowed here
195
- console.warn(`Failed to export markdown for ${routePath}:`, error);
196
- }
197
- }
198
-
199
- if (config.docs?.llms?.llmsTxt || config.docs?.llms?.llmsTxtFull) {
200
- const markdownInfoPath = path.join(
201
- config.__meta.rootDir,
202
- "node_modules/.apitogo/markdown-info.json",
203
- );
204
- await writeFile(
205
- markdownInfoPath,
206
- JSON.stringify(markdownFileInfos, null, 2),
207
- "utf-8",
208
- );
209
- }
210
- },
211
- };
212
- };
213
-
214
- export default viteMarkdownExportPlugin;
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { matchPath } from "react-router";
4
+ import type { Plugin } from "vite";
5
+ import { getCurrentConfig } from "../config/loader.js";
6
+ import { ProtectedRoutesSchema } from "../config/validators/ProtectedRoutesSchema.js";
7
+ import { joinUrl } from "../lib/util/joinUrl.js";
8
+ import { readFrontmatter } from "../lib/util/readFrontmatter.js";
9
+ import { markdownOutputPath } from "./markdown-output-path.js";
10
+ import {
11
+ globMarkdownFiles,
12
+ resolveCustomNavigationPaths,
13
+ } from "./plugin-docs.js";
14
+
15
+ export type MarkdownFileInfo = {
16
+ filePath: string;
17
+ routePath: string;
18
+ title?: string;
19
+ description?: string;
20
+ content: string;
21
+ };
22
+
23
+ const processMarkdownFile = async (
24
+ filePath: string,
25
+ ): Promise<{ content: string; title?: string; description?: string }> => {
26
+ const { content: markdownContent, data: frontmatter } =
27
+ await readFrontmatter(filePath);
28
+
29
+ let finalMarkdown = markdownContent;
30
+ if (frontmatter.title) {
31
+ // Add title as H1 at the beginning, matching the behavior in MdxPage.tsx
32
+ finalMarkdown = `# ${frontmatter.title}\n${markdownContent}`;
33
+ }
34
+
35
+ return {
36
+ content: finalMarkdown,
37
+ title: frontmatter.title,
38
+ description: frontmatter.description,
39
+ };
40
+ };
41
+
42
+ /**
43
+ * This plugin exports markdown files (.md) for each document during the build process.
44
+ * In development mode, you can access documents at their URL path with .md extension
45
+ * (e.g., /foo/hello.md) to get the raw markdown without frontmatter.
46
+ *
47
+ * Markdown files are generated when:
48
+ * - publishMarkdown is enabled (for copy button functionality)
49
+ * - llmsTxt or llmsTxtFull is enabled (for generating llms.txt files)
50
+ *
51
+ * It also writes metadata to markdown-info.json used by the llms.txt generator.
52
+ */
53
+ const viteMarkdownExportPlugin = (): Plugin => {
54
+ let markdownFiles: Record<string, string> = {};
55
+ let markdownFileInfos: MarkdownFileInfo[] = [];
56
+
57
+ return {
58
+ name: "zudoku-markdown-export-plugin",
59
+ applyToEnvironment(env) {
60
+ return env.name === "ssr";
61
+ },
62
+ async buildStart() {
63
+ const config = getCurrentConfig();
64
+ const llmsConfig = config.docs?.llms;
65
+
66
+ const needsMdFiles =
67
+ config.docs?.publishMarkdown ||
68
+ llmsConfig?.llmsTxt ||
69
+ llmsConfig?.llmsTxtFull;
70
+
71
+ if (config.__meta.mode === "standalone" || !needsMdFiles) {
72
+ return;
73
+ }
74
+
75
+ markdownFiles = await resolveCustomNavigationPaths(
76
+ config,
77
+ await globMarkdownFiles(config, { absolute: true }),
78
+ );
79
+
80
+ // Filter out protected routes unless `includeProtected` is true
81
+ if (!llmsConfig?.includeProtected) {
82
+ const protectedRoutes = ProtectedRoutesSchema.parse(
83
+ config.protectedRoutes,
84
+ );
85
+ if (protectedRoutes) {
86
+ const isProtectedRoute = (routePath: string): boolean => {
87
+ return Object.keys(protectedRoutes).some((route) =>
88
+ matchPath({ path: route, end: true }, routePath),
89
+ );
90
+ };
91
+
92
+ // Remove protected routes from the mapping
93
+ for (const routePath of Object.keys(markdownFiles)) {
94
+ if (isProtectedRoute(routePath)) {
95
+ delete markdownFiles[routePath];
96
+ }
97
+ }
98
+ }
99
+ }
100
+ },
101
+ async configureServer(server) {
102
+ const config = getCurrentConfig();
103
+ const llmsConfig = config.docs?.llms;
104
+
105
+ // Serve .md files if markdown export is needed
106
+ const needsMdFiles =
107
+ config.docs?.publishMarkdown ||
108
+ llmsConfig?.llmsTxt ||
109
+ llmsConfig?.llmsTxtFull;
110
+
111
+ if (!needsMdFiles) return;
112
+
113
+ markdownFiles = await resolveCustomNavigationPaths(
114
+ config,
115
+ await globMarkdownFiles(config, { absolute: true }),
116
+ );
117
+
118
+ server.middlewares.use(async (req, res, next) => {
119
+ if (req.method !== "GET" || !req.url?.endsWith(".md")) {
120
+ return next();
121
+ }
122
+
123
+ const basePath = joinUrl(config.basePath);
124
+ const routePath = joinUrl(
125
+ req.url.slice(basePath.length).replace(/\.mdx?$/, ""),
126
+ );
127
+ const filePath = markdownFiles[routePath];
128
+
129
+ if (!filePath) return next();
130
+
131
+ try {
132
+ const { content } = await processMarkdownFile(filePath);
133
+ res.setHeader("Content-Type", "text/markdown; charset=utf-8");
134
+ res.end(content);
135
+ } catch (error) {
136
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
137
+ console.warn(`Failed to serve markdown for ${routePath}:`, error);
138
+ return next();
139
+ }
140
+ });
141
+ },
142
+ async closeBundle() {
143
+ const config = getCurrentConfig();
144
+ const llmsConfig = config.docs?.llms;
145
+
146
+ const needsMdFiles =
147
+ config.docs?.publishMarkdown ||
148
+ llmsConfig?.llmsTxt ||
149
+ llmsConfig?.llmsTxtFull;
150
+
151
+ if (
152
+ process.env.NODE_ENV !== "production" ||
153
+ Object.keys(markdownFiles).length === 0 ||
154
+ !needsMdFiles
155
+ ) {
156
+ return;
157
+ }
158
+
159
+ // During build, write .md files to the dist directory
160
+ const distDir = path.join(
161
+ config.__meta.rootDir,
162
+ "dist",
163
+ config.basePath ?? "",
164
+ );
165
+
166
+ markdownFileInfos = [];
167
+
168
+ for (const [routePath, filePath] of Object.entries(markdownFiles)) {
169
+ try {
170
+ const {
171
+ content: finalMarkdown,
172
+ title,
173
+ description,
174
+ } = await processMarkdownFile(filePath);
175
+
176
+ markdownFileInfos.push({
177
+ filePath,
178
+ routePath,
179
+ title,
180
+ description,
181
+ content: finalMarkdown,
182
+ });
183
+
184
+ const outputPath = markdownOutputPath(distDir, routePath);
185
+
186
+ await mkdir(path.dirname(outputPath), { recursive: true });
187
+
188
+ await writeFile(outputPath, finalMarkdown, "utf-8");
189
+ } catch (error) {
190
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
191
+ console.warn(`Failed to export markdown for ${routePath}:`, error);
192
+ }
193
+ }
194
+
195
+ if (config.docs?.llms?.llmsTxt || config.docs?.llms?.llmsTxtFull) {
196
+ const markdownInfoPath = path.join(
197
+ config.__meta.rootDir,
198
+ "node_modules/.apitogo/markdown-info.json",
199
+ );
200
+ await writeFile(
201
+ markdownInfoPath,
202
+ JSON.stringify(markdownFileInfos, null, 2),
203
+ "utf-8",
204
+ );
205
+ }
206
+ },
207
+ };
208
+ };
209
+
210
+ export default viteMarkdownExportPlugin;
@@ -1,4 +1,4 @@
1
- import { readFile, rm } from "node:fs/promises";
1
+ import { readFile } from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { pathToFileURL } from "node:url";
@@ -13,6 +13,7 @@ import type { ZudokuConfig } from "../../config/validators/ZudokuConfig.js";
13
13
  import { runPluginTransformConfig } from "../../lib/core/transform-config.js";
14
14
  import invariant from "../../lib/util/invariant.js";
15
15
  import { joinUrl } from "../../lib/util/joinUrl.js";
16
+ import { removeExportedMarkdown } from "../markdown-output-path.js";
16
17
  import type { MarkdownFileInfo } from "../plugin-markdown-export.js";
17
18
  import { isTTY, throttle, writeLine } from "../reporter.js";
18
19
  import { generateSitemap } from "../sitemap.js";
@@ -231,10 +232,9 @@ export const prerender = async ({
231
232
  });
232
233
  }
233
234
 
235
+ // The .md copies were only written for llms.txt: remove them from dist again.
234
236
  if (!docsConfig.publishMarkdown) {
235
- await Promise.all(
236
- markdownFileInfos.map((info) => rm(info.filePath).catch(() => {})),
237
- );
237
+ await removeExportedMarkdown(distDir, markdownFileInfos);
238
238
  }
239
239
  }
240
240
 
@@ -69,6 +69,25 @@ export function stateIgnore(
69
69
  };
70
70
  }
71
71
 
72
+ /** A state folder (`.apitogo/` or `apitogo/.state/`) anywhere in a path relative to the site root. */
73
+ const STATE_FOLDER = /(?:^|[\\/])(?:\.apitogo|apitogo[\\/]\.state)(?:[\\/]|$)/;
74
+
75
+ /**
76
+ * What the dev server's watcher must leave alone below the site root of any project: the state folder of a config
77
+ * version 2 project kept inside it (a test project in a subfolder, say). Its `generated/content` links back to that
78
+ * project's folder, so a watcher that follows the link walks `content/apitogo/.state/generated/content/...` forever
79
+ * and keeps a CPU core busy, and every page waits seconds for the server. Paths outside the site root are left to
80
+ * {@link stateIgnore}.
81
+ */
82
+ export function nestedStateIgnore(root: string): (file: string) => boolean {
83
+ const resolvedRoot = path.resolve(root);
84
+ return (file) => {
85
+ const relative = path.relative(resolvedRoot, path.resolve(file));
86
+ if (relative.startsWith("..") || path.isAbsolute(relative)) return false;
87
+ return STATE_FOLDER.test(relative);
88
+ };
89
+ }
90
+
72
91
  /**
73
92
  * The folders the dev server may serve files from. The site root of a config version 2 workspace sits inside the
74
93
  * state folder, so the package (`node_modules`) and the tenant's pages are outside it. Without them the page's main