@farming-labs/next 0.1.1-beta.2 → 0.1.1

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 (2) hide show
  1. package/dist/config.mjs +59 -0
  2. package/package.json +3 -3
package/dist/config.mjs CHANGED
@@ -73,6 +73,21 @@ export const { GET, POST } = createDocsAPI({
73
73
  i18n: docsConfig.i18n,
74
74
  });
75
75
 
76
+ export const revalidate = false;
77
+ `;
78
+ const DOCS_MCP_ROUTE_TEMPLATE = `\
79
+ ${GENERATED_BANNER}
80
+ import docsConfig from "@/docs.config";
81
+ import { createDocsMCPAPI } from "@farming-labs/theme/api";
82
+
83
+ export const { GET, POST, DELETE } = createDocsMCPAPI({
84
+ entry: docsConfig.entry,
85
+ contentDir: docsConfig.contentDir,
86
+ nav: docsConfig.nav,
87
+ ordering: docsConfig.ordering,
88
+ mcp: docsConfig.mcp,
89
+ });
90
+
76
91
  export const revalidate = false;
77
92
  `;
78
93
  const API_REFERENCE_ROUTE_TEMPLATE = `\
@@ -187,6 +202,44 @@ function extractObjectLiteral(content, key) {
187
202
  if (depth === 0) return content.slice(braceStart + 1, index);
188
203
  }
189
204
  }
205
+ function readMcpConfig(root) {
206
+ for (const ext of FILE_EXTS) {
207
+ const configPath = join(root, `docs.config.${ext}`);
208
+ if (!existsSync(configPath)) continue;
209
+ try {
210
+ const content = readFileSync(configPath, "utf-8");
211
+ if (content.match(/mcp\s*:\s*false/)) return {
212
+ enabled: false,
213
+ route: "/api/docs/mcp"
214
+ };
215
+ if (content.match(/mcp\s*:\s*true/)) return {
216
+ enabled: true,
217
+ route: "/api/docs/mcp"
218
+ };
219
+ const block = extractObjectLiteral(content, "mcp");
220
+ if (!block) continue;
221
+ const enabledMatch = block.match(/enabled\s*:\s*(true|false)/);
222
+ const routeMatch = block.match(/route\s*:\s*["']([^"']+)["']/);
223
+ return {
224
+ enabled: enabledMatch ? enabledMatch[1] !== "false" : true,
225
+ route: normalizeRoutePath(routeMatch?.[1] ?? "/api/docs/mcp")
226
+ };
227
+ } catch {
228
+ return {
229
+ enabled: false,
230
+ route: "/api/docs/mcp"
231
+ };
232
+ }
233
+ }
234
+ return {
235
+ enabled: false,
236
+ route: "/api/docs/mcp"
237
+ };
238
+ }
239
+ function normalizeRoutePath(route) {
240
+ const normalized = `/${route}`.replace(/\/+/g, "/");
241
+ return normalized !== "/" ? normalized.replace(/\/+$/, "") : "/api/docs/mcp";
242
+ }
190
243
  function withDocs(nextConfig = {}) {
191
244
  const root = process.cwd();
192
245
  const docsConfigPath = readDocsConfigPath(root);
@@ -205,6 +258,12 @@ function withDocs(nextConfig = {}) {
205
258
  mkdirSync(docsApiRouteDir, { recursive: true });
206
259
  writeFileSync(join(docsApiRouteDir, "route.ts"), DOCS_API_ROUTE_TEMPLATE);
207
260
  }
261
+ const mcp = readMcpConfig(root);
262
+ const docsMcpRouteDir = join(root, appDir, "api", "docs", "mcp");
263
+ if (mcp.enabled && mcp.route === "/api/docs/mcp" && !isStaticExport && !hasFile(docsMcpRouteDir, "route")) {
264
+ mkdirSync(docsMcpRouteDir, { recursive: true });
265
+ writeFileSync(join(docsMcpRouteDir, "route.ts"), DOCS_MCP_ROUTE_TEMPLATE);
266
+ }
208
267
  const apiReference = readApiReferenceConfig(root);
209
268
  if (apiReference.enabled && !isStaticExport) {
210
269
  const apiReferenceRouteDir = join(root, appDir, ...apiReference.path.split("/"), "[[...slug]]");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/next",
3
- "version": "0.1.1-beta.2",
3
+ "version": "0.1.1",
4
4
  "description": "Next.js adapter for @farming-labs/docs — MDX config wrapper",
5
5
  "keywords": [
6
6
  "docs",
@@ -79,8 +79,8 @@
79
79
  "tsdown": "^0.20.3",
80
80
  "typescript": "^5.9.3",
81
81
  "vitest": "^3.2.4",
82
- "@farming-labs/docs": "0.1.1-beta.2",
83
- "@farming-labs/theme": "0.1.1-beta.2"
82
+ "@farming-labs/docs": "0.1.1",
83
+ "@farming-labs/theme": "0.1.1"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@farming-labs/docs": ">=0.0.1",