@farming-labs/docs 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.
@@ -1,5 +1,12 @@
1
1
  //#region src/cli/index.d.ts
2
+ declare const UPGRADE_TAGS: readonly ["latest", "beta"];
3
+ type UpgradeTag = (typeof UPGRADE_TAGS)[number];
4
+ /** Normalize command aliases like `upgrade@beta` into the base command + dist-tag. */
5
+ declare function parseCommandAlias(rawCommand?: string): {
6
+ command?: string;
7
+ tag?: UpgradeTag;
8
+ };
2
9
  /** Parse flags like --template next, --name my-docs, --theme concrete, --entry docs, --framework astro (exported for tests). */
3
10
  declare function parseFlags(argv: string[]): Record<string, string | boolean | undefined>;
4
11
  //#endregion
5
- export { parseFlags };
12
+ export { parseCommandAlias, parseFlags };
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import fs from "node:fs";
3
- import path from "node:path";
2
+ import "../api-reference-wh4_pwG8.mjs";
3
+ import { createFilesystemDocsMcpSource, resolveDocsMcpConfig, runDocsMcpStdio } from "../mcp.mjs";
4
+ import "../server.mjs";
5
+ import fs, { existsSync, readFileSync } from "node:fs";
6
+ import path, { join, resolve } from "node:path";
4
7
  import pc from "picocolors";
5
8
  import * as p from "@clack/prompts";
6
9
  import { execSync, spawn } from "node:child_process";
@@ -3414,6 +3417,92 @@ function scaffoldNuxt(cwd, cfg, globalCssRelPath, write, skipped, written) {
3414
3417
  }
3415
3418
  }
3416
3419
 
3420
+ //#endregion
3421
+ //#region src/cli/mcp.ts
3422
+ const FILE_EXTS = [
3423
+ "tsx",
3424
+ "ts",
3425
+ "jsx",
3426
+ "js"
3427
+ ];
3428
+ async function runMcp(options = {}) {
3429
+ const rootDir = process.cwd();
3430
+ const content = readFileSync(resolveDocsConfigPath(rootDir, options.configPath), "utf-8");
3431
+ const entry = readStringProperty(content, "entry") ?? "docs";
3432
+ const contentDir = readStringProperty(content, "contentDir") ?? entry;
3433
+ const navTitle = readNavTitle(content);
3434
+ const mcp = readMcpConfig(content);
3435
+ await runDocsMcpStdio({
3436
+ source: createFilesystemDocsMcpSource({
3437
+ rootDir,
3438
+ entry,
3439
+ contentDir,
3440
+ siteTitle: navTitle ?? "Documentation"
3441
+ }),
3442
+ mcp: resolveDocsMcpConfig(mcp ?? true, { defaultName: navTitle ?? "@farming-labs/docs" }),
3443
+ defaultName: navTitle ?? "@farming-labs/docs"
3444
+ });
3445
+ }
3446
+ function resolveDocsConfigPath(rootDir, explicitPath) {
3447
+ if (explicitPath) {
3448
+ const resolvedPath = resolve(rootDir, explicitPath);
3449
+ if (!existsSync(resolvedPath)) throw new Error(`Could not find docs config at ${explicitPath}.`);
3450
+ return resolvedPath;
3451
+ }
3452
+ for (const ext of FILE_EXTS) {
3453
+ const configPath = join(rootDir, `docs.config.${ext}`);
3454
+ if (existsSync(configPath)) return configPath;
3455
+ }
3456
+ throw new Error("Could not find docs.config.ts or docs.config.tsx in the current project. Use --config to point at a custom path.");
3457
+ }
3458
+ function readStringProperty(content, key) {
3459
+ return content.match(new RegExp(`${key}\\s*:\\s*["']([^"']+)["']`))?.[1];
3460
+ }
3461
+ function readNavTitle(content) {
3462
+ const block = extractObjectLiteral(content, "nav");
3463
+ if (!block) return void 0;
3464
+ return readStringProperty(block, "title");
3465
+ }
3466
+ function readMcpConfig(content) {
3467
+ if (content.match(/mcp\s*:\s*false/)) return false;
3468
+ if (content.match(/mcp\s*:\s*true/)) return true;
3469
+ const block = extractObjectLiteral(content, "mcp");
3470
+ if (!block) return void 0;
3471
+ return {
3472
+ enabled: readBooleanProperty(block, "enabled"),
3473
+ route: readStringProperty(block, "route"),
3474
+ name: readStringProperty(block, "name"),
3475
+ version: readStringProperty(block, "version"),
3476
+ tools: {
3477
+ listPages: readBooleanProperty(block, "listPages"),
3478
+ readPage: readBooleanProperty(block, "readPage"),
3479
+ searchDocs: readBooleanProperty(block, "searchDocs"),
3480
+ getNavigation: readBooleanProperty(block, "getNavigation")
3481
+ }
3482
+ };
3483
+ }
3484
+ function readBooleanProperty(content, key) {
3485
+ const match = content.match(new RegExp(`${key}\\s*:\\s*(true|false)`));
3486
+ return match ? match[1] === "true" : void 0;
3487
+ }
3488
+ function extractObjectLiteral(content, key) {
3489
+ const keyIndex = content.search(new RegExp(`${key}\\s*:\\s*\\{`));
3490
+ if (keyIndex === -1) return void 0;
3491
+ const braceStart = content.indexOf("{", keyIndex);
3492
+ if (braceStart === -1) return void 0;
3493
+ let depth = 0;
3494
+ for (let index = braceStart; index < content.length; index += 1) {
3495
+ const char = content[index];
3496
+ if (char === "{") {
3497
+ depth += 1;
3498
+ continue;
3499
+ }
3500
+ if (char !== "}") continue;
3501
+ depth -= 1;
3502
+ if (depth === 0) return content.slice(braceStart + 1, index);
3503
+ }
3504
+ }
3505
+
3417
3506
  //#endregion
3418
3507
  //#region src/cli/upgrade.ts
3419
3508
  /**
@@ -3550,6 +3639,17 @@ async function upgrade(options = {}) {
3550
3639
  //#region src/cli/index.ts
3551
3640
  const args = process.argv.slice(2);
3552
3641
  const command = args[0];
3642
+ const UPGRADE_TAGS = ["latest", "beta"];
3643
+ /** Normalize command aliases like `upgrade@beta` into the base command + dist-tag. */
3644
+ function parseCommandAlias(rawCommand) {
3645
+ if (!rawCommand) return {};
3646
+ const [baseCommand, rawTag] = rawCommand.split("@");
3647
+ if (baseCommand === "upgrade" && rawTag && UPGRADE_TAGS.includes(rawTag)) return {
3648
+ command: "upgrade",
3649
+ tag: rawTag
3650
+ };
3651
+ return { command: rawCommand };
3652
+ }
3553
3653
  /** Parse flags like --template next, --name my-docs, --theme concrete, --entry docs, --framework astro (exported for tests). */
3554
3654
  function parseFlags(argv) {
3555
3655
  const flags = {};
@@ -3572,6 +3672,7 @@ function parseFlags(argv) {
3572
3672
  }
3573
3673
  async function main() {
3574
3674
  const flags = parseFlags(args);
3675
+ const parsedCommand = parseCommandAlias(command);
3575
3676
  const initOptions = {
3576
3677
  template: typeof flags.template === "string" ? flags.template : void 0,
3577
3678
  name: typeof flags.name === "string" ? flags.name : void 0,
@@ -3580,13 +3681,15 @@ async function main() {
3580
3681
  apiReference: typeof flags["api-reference"] === "boolean" ? flags["api-reference"] : void 0,
3581
3682
  apiRouteRoot: typeof flags["api-route-root"] === "string" ? flags["api-route-root"] : void 0
3582
3683
  };
3583
- if (!command || command === "init") await init(initOptions);
3584
- else if (command === "upgrade") await upgrade({
3684
+ const mcpOptions = { configPath: typeof flags.config === "string" ? flags.config : void 0 };
3685
+ if (!parsedCommand.command || parsedCommand.command === "init") await init(initOptions);
3686
+ else if (parsedCommand.command === "mcp") await runMcp(mcpOptions);
3687
+ else if (parsedCommand.command === "upgrade") await upgrade({
3585
3688
  framework: (typeof flags.framework === "string" ? flags.framework : void 0) ?? (args[1] && !args[1].startsWith("--") ? args[1] : void 0),
3586
- tag: args.includes("--beta") ? "beta" : "latest"
3689
+ tag: args.includes("--beta") ? "beta" : args.includes("--latest") ? "latest" : parsedCommand.tag ?? "latest"
3587
3690
  });
3588
- else if (command === "--help" || command === "-h") printHelp();
3589
- else if (command === "--version" || command === "-v") printVersion();
3691
+ else if (parsedCommand.command === "--help" || parsedCommand.command === "-h") printHelp();
3692
+ else if (parsedCommand.command === "--version" || parsedCommand.command === "-v") printVersion();
3590
3693
  else {
3591
3694
  console.error(pc.red(`Unknown command: ${command}`));
3592
3695
  console.error();
@@ -3603,6 +3706,7 @@ ${pc.dim("Usage:")}
3603
3706
 
3604
3707
  ${pc.dim("Commands:")}
3605
3708
  ${pc.cyan("init")} Scaffold docs in your project (default)
3709
+ ${pc.cyan("mcp")} Run the built-in docs MCP server over stdio
3606
3710
  ${pc.cyan("upgrade")} Upgrade @farming-labs/* packages to latest (auto-detect or use --framework)
3607
3711
 
3608
3712
  ${pc.dim("Supported frameworks:")}
@@ -3617,10 +3721,15 @@ ${pc.dim("Options for init:")}
3617
3721
  ${pc.cyan("--no-api-reference")} Skip API reference scaffold during ${pc.cyan("init")}
3618
3722
  ${pc.cyan("--api-route-root <path>")} Override the API route root scanned by ${pc.cyan("apiReference.routeRoot")} (e.g. ${pc.dim("api")}, ${pc.dim("internal-api")})
3619
3723
 
3724
+ ${pc.dim("Options for mcp:")}
3725
+ ${pc.cyan("--config <path>")} Use a custom docs config path instead of ${pc.dim("docs.config.ts[x]")}
3726
+
3620
3727
  ${pc.dim("Options for upgrade:")}
3621
3728
  ${pc.cyan("--framework <name>")} Explicit framework (${pc.dim("next")}, ${pc.dim("tanstack-start")}, ${pc.dim("nuxt")}, ${pc.dim("sveltekit")}, ${pc.dim("astro")}); omit to auto-detect
3622
3729
  ${pc.cyan("--latest")} Install latest stable (default)
3623
3730
  ${pc.cyan("--beta")} Install beta versions
3731
+ ${pc.cyan("upgrade@beta")} Shortcut for ${pc.cyan("upgrade --beta")}
3732
+ ${pc.cyan("upgrade@latest")} Shortcut for ${pc.cyan("upgrade --latest")}
3624
3733
 
3625
3734
  ${pc.cyan("-h, --help")} Show this help message
3626
3735
  ${pc.cyan("-v, --version")} Show version
@@ -3636,4 +3745,4 @@ main().catch((err) => {
3636
3745
  });
3637
3746
 
3638
3747
  //#endregion
3639
- export { parseFlags };
3748
+ export { parseCommandAlias, parseFlags };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as SidebarNode, C as PageActionsConfig, D as SidebarComponentProps, E as PageTwitter, F as UIConfig, M as SidebarTree, N as ThemeToggleConfig, O as SidebarConfig, P as TypographyConfig, S as OrderingItem, T as PageOpenGraph, _ as LlmsTxtConfig, a as CopyMarkdownConfig, b as OpenDocsProvider, c as DocsFeedbackValue, d as DocsNav, f as DocsTheme, g as LastUpdatedConfig, h as GithubConfig, i as CodeBlockCopyData, j as SidebarPageNode, k as SidebarFolderNode, l as DocsI18nConfig, m as FontStyle, n as ApiReferenceConfig, o as DocsConfig, p as FeedbackConfig, r as BreadcrumbConfig, s as DocsFeedbackData, t as AIConfig, u as DocsMetadata, v as OGConfig, w as PageFrontmatter, x as OpenGraphImage, y as OpenDocsConfig } from "./types-DpijZMth.mjs";
1
+ import { A as SidebarConfig, C as OpenGraphImage, D as PageOpenGraph, E as PageFrontmatter, F as ThemeToggleConfig, I as TypographyConfig, L as UIConfig, M as SidebarNode, N as SidebarPageNode, O as PageTwitter, P as SidebarTree, S as OpenDocsProvider, T as PageActionsConfig, _ as GithubConfig, a as CopyMarkdownConfig, b as OGConfig, c as DocsFeedbackValue, d as DocsMcpToolsConfig, f as DocsMetadata, g as FontStyle, h as FeedbackConfig, i as CodeBlockCopyData, j as SidebarFolderNode, k as SidebarComponentProps, l as DocsI18nConfig, m as DocsTheme, n as ApiReferenceConfig, o as DocsConfig, p as DocsNav, r as BreadcrumbConfig, s as DocsFeedbackData, t as AIConfig, u as DocsMcpConfig, v as LastUpdatedConfig, w as OrderingItem, x as OpenDocsConfig, y as LlmsTxtConfig } from "./types-Bd3kyFF1.mjs";
2
2
 
3
3
  //#region src/define-docs.d.ts
4
4
  /**
@@ -97,4 +97,4 @@ declare function buildPageOpenGraph(page: Pick<PageFrontmatter, "title" | "descr
97
97
  */
98
98
  declare function buildPageTwitter(page: Pick<PageFrontmatter, "title" | "description" | "ogImage" | "openGraph" | "twitter">, ogConfig?: OGConfig, baseUrl?: string): PageTwitter | undefined;
99
99
  //#endregion
100
- export { type AIConfig, type ApiReferenceConfig, type BreadcrumbConfig, type CodeBlockCopyData, type CopyMarkdownConfig, type DocsConfig, type DocsFeedbackData, type DocsFeedbackValue, type DocsI18nConfig, type DocsMetadata, type DocsNav, type DocsPathMatch, type DocsTheme, type FeedbackConfig, type FontStyle, type GithubConfig, type LastUpdatedConfig, type LlmsTxtConfig, type OGConfig, type OpenDocsConfig, type OpenDocsProvider, type OpenGraphImage, type OrderingItem, type PageActionsConfig, type PageFrontmatter, type PageOpenGraph, type PageTwitter, type ResolvedDocsI18n, type SidebarComponentProps, type SidebarConfig, type SidebarFolderNode, type SidebarNode, type SidebarPageNode, type SidebarTree, type ThemeToggleConfig, type TypographyConfig, type UIConfig, buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
100
+ export { type AIConfig, type ApiReferenceConfig, type BreadcrumbConfig, type CodeBlockCopyData, type CopyMarkdownConfig, type DocsConfig, type DocsFeedbackData, type DocsFeedbackValue, type DocsI18nConfig, type DocsMcpConfig, type DocsMcpToolsConfig, type DocsMetadata, type DocsNav, type DocsPathMatch, type DocsTheme, type FeedbackConfig, type FontStyle, type GithubConfig, type LastUpdatedConfig, type LlmsTxtConfig, type OGConfig, type OpenDocsConfig, type OpenDocsProvider, type OpenGraphImage, type OrderingItem, type PageActionsConfig, type PageFrontmatter, type PageOpenGraph, type PageTwitter, type ResolvedDocsI18n, type SidebarComponentProps, type SidebarConfig, type SidebarFolderNode, type SidebarNode, type SidebarPageNode, type SidebarTree, type ThemeToggleConfig, type TypographyConfig, type UIConfig, buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
package/dist/index.mjs CHANGED
@@ -16,6 +16,7 @@ function defineDocs(config) {
16
16
  components: config.components,
17
17
  onCopyClick: config.onCopyClick,
18
18
  feedback: config.feedback,
19
+ mcp: config.mcp,
19
20
  icons: config.icons,
20
21
  pageActions: config.pageActions,
21
22
  lastUpdated: config.lastUpdated,
package/dist/mcp.d.mts ADDED
@@ -0,0 +1,86 @@
1
+ import { u as DocsMcpConfig, w as OrderingItem } from "./types-Bd3kyFF1.mjs";
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
3
+
4
+ //#region src/mcp.d.ts
5
+ interface DocsMcpPage {
6
+ slug: string;
7
+ url: string;
8
+ title: string;
9
+ description?: string;
10
+ icon?: string;
11
+ content: string;
12
+ rawContent?: string;
13
+ }
14
+ interface DocsMcpPageNode {
15
+ type: "page";
16
+ name: string;
17
+ url: string;
18
+ icon?: string;
19
+ description?: string;
20
+ }
21
+ interface DocsMcpFolderNode {
22
+ type: "folder";
23
+ name: string;
24
+ icon?: string;
25
+ index?: DocsMcpPageNode;
26
+ children: DocsMcpNavigationNode[];
27
+ }
28
+ type DocsMcpNavigationNode = DocsMcpPageNode | DocsMcpFolderNode;
29
+ interface DocsMcpNavigationTree {
30
+ name: string;
31
+ children: DocsMcpNavigationNode[];
32
+ }
33
+ interface DocsMcpSource {
34
+ entry?: string;
35
+ siteTitle?: string;
36
+ getPages(locale?: string): DocsMcpPage[] | Promise<DocsMcpPage[]>;
37
+ getNavigation(locale?: string): DocsMcpNavigationTree | Promise<DocsMcpNavigationTree>;
38
+ }
39
+ interface DocsMcpResolvedConfig {
40
+ enabled: boolean;
41
+ route: string;
42
+ name: string;
43
+ version: string;
44
+ tools: {
45
+ listPages: boolean;
46
+ readPage: boolean;
47
+ searchDocs: boolean;
48
+ getNavigation: boolean;
49
+ };
50
+ }
51
+ interface DocsMcpHttpHandlers {
52
+ GET: (context: {
53
+ request: Request;
54
+ }) => Promise<Response>;
55
+ POST: (context: {
56
+ request: Request;
57
+ }) => Promise<Response>;
58
+ DELETE: (context: {
59
+ request: Request;
60
+ }) => Promise<Response>;
61
+ }
62
+ interface CreateDocsMcpServerOptions {
63
+ source: DocsMcpSource;
64
+ mcp?: boolean | DocsMcpConfig;
65
+ defaultName?: string;
66
+ defaultVersion?: string;
67
+ }
68
+ interface CreateFilesystemDocsMcpSourceOptions {
69
+ rootDir?: string;
70
+ entry?: string;
71
+ contentDir?: string;
72
+ siteTitle?: string;
73
+ ordering?: "alphabetical" | "numeric" | OrderingItem[];
74
+ }
75
+ declare function normalizeDocsMcpRoute(route?: string): string;
76
+ declare function resolveDocsMcpConfig(mcp?: boolean | DocsMcpConfig, defaults?: {
77
+ defaultName?: string;
78
+ defaultVersion?: string;
79
+ defaultRoute?: string;
80
+ }): DocsMcpResolvedConfig;
81
+ declare function createFilesystemDocsMcpSource(options?: CreateFilesystemDocsMcpSourceOptions): DocsMcpSource;
82
+ declare function createDocsMcpServer(options: CreateDocsMcpServerOptions): Promise<McpServer>;
83
+ declare function createDocsMcpHttpHandler(options: CreateDocsMcpServerOptions): DocsMcpHttpHandlers;
84
+ declare function runDocsMcpStdio(options: CreateDocsMcpServerOptions): Promise<void>;
85
+ //#endregion
86
+ export { DocsMcpFolderNode, DocsMcpHttpHandlers, DocsMcpNavigationNode, DocsMcpNavigationTree, DocsMcpPage, DocsMcpPageNode, DocsMcpResolvedConfig, DocsMcpSource, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, normalizeDocsMcpRoute, resolveDocsMcpConfig, runDocsMcpStdio };