@farming-labs/docs 0.1.1 → 0.1.3

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.
@@ -0,0 +1,95 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+
4
+ //#region src/cli/config.ts
5
+ const FILE_EXTS = [
6
+ "tsx",
7
+ "ts",
8
+ "jsx",
9
+ "js"
10
+ ];
11
+ function escapeRegExp(value) {
12
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13
+ }
14
+ function createPropertyPattern(key, valuePattern) {
15
+ return new RegExp(`\\b${escapeRegExp(key)}\\b\\s*:\\s*${valuePattern}`);
16
+ }
17
+ function resolveDocsConfigPath(rootDir, explicitPath) {
18
+ if (explicitPath) {
19
+ const resolvedPath = resolve(rootDir, explicitPath);
20
+ if (!existsSync(resolvedPath)) throw new Error(`Could not find docs config at ${explicitPath}.`);
21
+ return resolvedPath;
22
+ }
23
+ for (const ext of FILE_EXTS) {
24
+ const configPath = join(rootDir, `docs.config.${ext}`);
25
+ if (existsSync(configPath)) return configPath;
26
+ }
27
+ 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.");
28
+ }
29
+ function readStringProperty(content, key) {
30
+ return content.match(createPropertyPattern(key, `["']([^"']+)["']`))?.[1];
31
+ }
32
+ function readBooleanProperty(content, key) {
33
+ const match = content.match(createPropertyPattern(key, "(true|false)"));
34
+ return match ? match[1] === "true" : void 0;
35
+ }
36
+ function extractObjectLiteral(content, key) {
37
+ const keyIndex = content.search(new RegExp(`${key}\\s*:\\s*\\{`));
38
+ if (keyIndex === -1) return void 0;
39
+ const braceStart = content.indexOf("{", keyIndex);
40
+ if (braceStart === -1) return void 0;
41
+ let depth = 0;
42
+ for (let index = braceStart; index < content.length; index += 1) {
43
+ const char = content[index];
44
+ if (char === "{") {
45
+ depth += 1;
46
+ continue;
47
+ }
48
+ if (char !== "}") continue;
49
+ depth -= 1;
50
+ if (depth === 0) return content.slice(braceStart + 1, index);
51
+ }
52
+ }
53
+ function readNavTitle(content) {
54
+ const block = extractObjectLiteral(content, "nav");
55
+ if (!block) return void 0;
56
+ return readStringProperty(block, "title");
57
+ }
58
+ function resolveDocsContentDir(rootDir, content, entry) {
59
+ const configuredContentDir = readStringProperty(content, "contentDir");
60
+ if (configuredContentDir) return configuredContentDir;
61
+ const candidates = [
62
+ entry,
63
+ join("app", entry),
64
+ join("src", "app", entry)
65
+ ];
66
+ for (const candidate of candidates) if (existsSync(join(rootDir, candidate))) return candidate;
67
+ return entry;
68
+ }
69
+ function parseEnvValue(rawValue) {
70
+ const value = rawValue.trim();
71
+ if (value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1);
72
+ return value;
73
+ }
74
+ function loadProjectEnv(rootDir) {
75
+ const env = {};
76
+ for (const filename of [".env", ".env.local"]) {
77
+ const fullPath = join(rootDir, filename);
78
+ if (!existsSync(fullPath)) continue;
79
+ const lines = readFileSync(fullPath, "utf-8").split(/\r?\n/);
80
+ for (const line of lines) {
81
+ const trimmed = line.trim();
82
+ if (!trimmed || trimmed.startsWith("#")) continue;
83
+ const equalsIndex = trimmed.indexOf("=");
84
+ if (equalsIndex === -1) continue;
85
+ const key = trimmed.slice(0, equalsIndex).trim();
86
+ const rawValue = trimmed.slice(equalsIndex + 1);
87
+ if (!key) continue;
88
+ env[key] = parseEnvValue(rawValue);
89
+ }
90
+ }
91
+ return env;
92
+ }
93
+
94
+ //#endregion
95
+ export { readStringProperty as a, readNavTitle as i, loadProjectEnv as n, resolveDocsConfigPath as o, readBooleanProperty as r, resolveDocsContentDir as s, extractObjectLiteral as t };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
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";
1
+ import { $ as UIConfig, A as GithubConfig, B as PageFrontmatter, C as DocsSearchQuery, D as DocsTheme, E as DocsSearchSourcePage, F as OpenDocsConfig, G as SidebarFolderNode, H as PageTwitter, I as OpenDocsProvider, J as SidebarTree, K as SidebarNode, L as OpenGraphImage, M as LlmsTxtConfig, N as McpDocsSearchConfig, O as FeedbackConfig, P as OGConfig, Q as TypographyConfig, R as OrderingItem, S as DocsSearchEmbeddingsConfig, T as DocsSearchResultType, U as SidebarComponentProps, V as PageOpenGraph, W as SidebarConfig, X as ThemeToggleConfig, Y as SimpleDocsSearchConfig, Z as TypesenseDocsSearchConfig, _ as DocsSearchAdapterContext, a as CodeBlockCopyData, b as DocsSearchConfig, c as DocsConfig, d as DocsI18nConfig, f as DocsMcpConfig, g as DocsSearchAdapter, h as DocsNav, i as BreadcrumbConfig, j as LastUpdatedConfig, k as FontStyle, l as DocsFeedbackData, m as DocsMetadata, n as AlgoliaDocsSearchConfig, o as CopyMarkdownConfig, p as DocsMcpToolsConfig, q as SidebarPageNode, r as ApiReferenceConfig, s as CustomDocsSearchConfig, t as AIConfig, u as DocsFeedbackValue, v as DocsSearchAdapterFactory, w as DocsSearchResult, x as DocsSearchDocument, y as DocsSearchChunkingConfig, z as PageActionsConfig } from "./types-BAulrjlV.mjs";
2
+ import { a as createSimpleSearchAdapter, c as resolveSearchRequestConfig, i as createMcpSearchAdapter, n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, r as createCustomSearchAdapter, s as performDocsSearch, t as buildDocsSearchDocuments } from "./search-KzREATdM.mjs";
2
3
 
3
4
  //#region src/define-docs.d.ts
4
5
  /**
@@ -97,4 +98,4 @@ declare function buildPageOpenGraph(page: Pick<PageFrontmatter, "title" | "descr
97
98
  */
98
99
  declare function buildPageTwitter(page: Pick<PageFrontmatter, "title" | "description" | "ogImage" | "openGraph" | "twitter">, ogConfig?: OGConfig, baseUrl?: string): PageTwitter | undefined;
99
100
  //#endregion
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 };
101
+ export { type AIConfig, type AlgoliaDocsSearchConfig, type ApiReferenceConfig, type BreadcrumbConfig, type CodeBlockCopyData, type CopyMarkdownConfig, type CustomDocsSearchConfig, type DocsConfig, type DocsFeedbackData, type DocsFeedbackValue, type DocsI18nConfig, type DocsMcpConfig, type DocsMcpToolsConfig, type DocsMetadata, type DocsNav, type DocsPathMatch, type DocsSearchAdapter, type DocsSearchAdapterContext, type DocsSearchAdapterFactory, type DocsSearchChunkingConfig, type DocsSearchConfig, type DocsSearchDocument, type DocsSearchEmbeddingsConfig, type DocsSearchQuery, type DocsSearchResult, type DocsSearchResultType, type DocsSearchSourcePage, type DocsTheme, type FeedbackConfig, type FontStyle, type GithubConfig, type LastUpdatedConfig, type LlmsTxtConfig, type McpDocsSearchConfig, 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 SimpleDocsSearchConfig, type ThemeToggleConfig, type TypesenseDocsSearchConfig, type TypographyConfig, type UIConfig, buildDocsSearchDocuments, buildPageOpenGraph, buildPageTwitter, createAlgoliaSearchAdapter, createCustomSearchAdapter, createMcpSearchAdapter, createSimpleSearchAdapter, createTheme, createTypesenseSearchAdapter, deepMerge, defineDocs, extendTheme, performDocsSearch, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveSearchRequestConfig, resolveTitle };
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { a as createSimpleSearchAdapter, c as resolveSearchRequestConfig, i as createMcpSearchAdapter, n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, r as createCustomSearchAdapter, s as performDocsSearch, t as buildDocsSearchDocuments } from "./search-BS6C5N1i.mjs";
2
+
1
3
  //#region src/define-docs.ts
2
4
  /**
3
5
  * Define docs configuration. Validates and returns the config.
@@ -16,6 +18,7 @@ function defineDocs(config) {
16
18
  components: config.components,
17
19
  onCopyClick: config.onCopyClick,
18
20
  feedback: config.feedback,
21
+ search: config.search,
19
22
  mcp: config.mcp,
20
23
  icons: config.icons,
21
24
  pageActions: config.pageActions,
@@ -224,4 +227,4 @@ function buildPageTwitter(page, ogConfig, baseUrl) {
224
227
  }
225
228
 
226
229
  //#endregion
227
- export { buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
230
+ export { buildDocsSearchDocuments, buildPageOpenGraph, buildPageTwitter, createAlgoliaSearchAdapter, createCustomSearchAdapter, createMcpSearchAdapter, createSimpleSearchAdapter, createTheme, createTypesenseSearchAdapter, deepMerge, defineDocs, extendTheme, performDocsSearch, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveSearchRequestConfig, resolveTitle };