@farming-labs/docs 0.2.62 → 0.2.64
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/dist/agent-CQTH7NFu.mjs +624 -0
- package/dist/agent-DKKptIgy.mjs +4365 -0
- package/dist/agent-evals-B7MIxuEX.mjs +2144 -0
- package/dist/agent-export-CBgWgPvH.mjs +910 -0
- package/dist/agent-scope-C_U--OZ7.mjs +283 -0
- package/dist/agent-skills-bundle.d.mts +13 -0
- package/dist/agent-skills-bundle.mjs +12 -0
- package/dist/agent-skills-server-CPja6Syt.d.mts +14 -0
- package/dist/agent-skills-server-DraIb6FV.mjs +415 -0
- package/dist/agent-skills-vite.d.mts +31 -0
- package/dist/agent-skills-vite.mjs +70 -0
- package/dist/agents-XWZBub6f.mjs +221 -0
- package/dist/analytics-Bx44lg6d.mjs +177 -0
- package/dist/cli/index.d.mts +15 -0
- package/dist/cli/index.mjs +452 -0
- package/dist/client/react.d.mts +45 -0
- package/dist/client/react.mjs +223 -0
- package/dist/cloud-analytics-CSyFE6SS.mjs +132 -0
- package/dist/cloud-ask-ai-sbpjOR2K.mjs +382 -0
- package/dist/cloud-ask-ai-zpwkdwnF.d.mts +23 -0
- package/dist/cloud-pdNC-tyj.mjs +1615 -0
- package/dist/code-blocks-DnNVNK2M.mjs +871 -0
- package/dist/codeblocks-CFuurVIH.mjs +250 -0
- package/dist/config-Wcdj-D0a.mjs +369 -0
- package/dist/dev-Cmy6DtdF.mjs +1333 -0
- package/dist/docs-cloud-server.d.mts +70 -0
- package/dist/docs-cloud-server.mjs +310 -0
- package/dist/doctor-DtGYZ41i.mjs +2036 -0
- package/dist/downgrade-w7e6Se0L.mjs +184 -0
- package/dist/errors-DbOhkE1h.mjs +20 -0
- package/dist/golden-evaluations-Dj-9Eo3v.mjs +1785 -0
- package/dist/i18n-CCaFUnAN.mjs +40 -0
- package/dist/index.d.mts +1150 -0
- package/dist/index.mjs +10 -0
- package/dist/init-CQY0Woe3.mjs +1264 -0
- package/dist/mcp-B9dcsivk.mjs +156 -0
- package/dist/mcp.d.mts +298 -0
- package/dist/mcp.mjs +4430 -0
- package/dist/metadata-DWExHQnx.mjs +237 -0
- package/dist/package-version-n5AFur8a.mjs +128 -0
- package/dist/reading-time-CYZ5VvKU.mjs +742 -0
- package/dist/review-CLoHTywU.mjs +673 -0
- package/dist/robots-BIpC4j4P.mjs +201 -0
- package/dist/robots-CUTahhoY.mjs +179 -0
- package/dist/search-B6V6qtiI.mjs +1826 -0
- package/dist/search-CaSyi6H6.d.mts +279 -0
- package/dist/search-DSjCeOk7.mjs +104 -0
- package/dist/server.d.mts +343 -0
- package/dist/server.mjs +14 -0
- package/dist/sitemap-Cykpe3Tz.mjs +249 -0
- package/dist/sitemap-server-C_6Wes83.mjs +1137 -0
- package/dist/standards-discovery-C4HUqMd2.d.mts +227 -0
- package/dist/standards-discovery-jkykaXq1.mjs +519 -0
- package/dist/templates-Bq_P7ctv.mjs +2465 -0
- package/dist/types-lMBIdZg0.d.mts +3315 -0
- package/dist/upgrade-oz-GChgt.mjs +56 -0
- package/dist/utils-DpiIioYb.mjs +225 -0
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Ft as resolveDocsSitemapConfig, S as DEFAULT_SKILL_MD_WELL_KNOWN_ROUTE, X as normalizeDocsPathSegment, a as DEFAULT_AGENT_MD_ROUTE, c as DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE, en as DEFAULT_MCP_PUBLIC_ROUTE, g as DEFAULT_LLMS_FULL_TXT_WELL_KNOWN_ROUTE, h as DEFAULT_LLMS_FULL_TXT_ROUTE, l as DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE, n as DEFAULT_AGENTS_MD_WELL_KNOWN_ROUTE, nn as DEFAULT_MCP_WELL_KNOWN_ROUTE, o as DEFAULT_AGENT_MD_WELL_KNOWN_ROUTE, t as DEFAULT_AGENTS_MD_ROUTE, v as DEFAULT_LLMS_TXT_ROUTE, x as DEFAULT_SKILL_MD_ROUTE, y as DEFAULT_LLMS_TXT_WELL_KNOWN_ROUTE } from "./agent-DKKptIgy.mjs";
|
|
2
|
+
import { a as DEFAULT_A2A_AGENT_CARD_ROUTE, c as DEFAULT_AGENT_SKILLS_INDEX_ROUTE, g as DEFAULT_API_CATALOG_ROUTE, u as DEFAULT_AGENT_SKILLS_ROUTE_PREFIX, v as DEFAULT_LEGACY_SKILLS_INDEX_ROUTE, y as DEFAULT_LEGACY_SKILLS_ROUTE_PREFIX } from "./standards-discovery-jkykaXq1.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/robots.ts
|
|
5
|
+
const DEFAULT_ROBOTS_TXT_ROUTE = "/robots.txt";
|
|
6
|
+
const DOCS_ROBOTS_GENERATED_BLOCK_START = "# BEGIN @farming-labs/docs robots";
|
|
7
|
+
const DOCS_ROBOTS_GENERATED_BLOCK_END = "# END @farming-labs/docs robots";
|
|
8
|
+
const DEFAULT_DOCS_AI_ROBOTS_USER_AGENTS = [
|
|
9
|
+
"GPTBot",
|
|
10
|
+
"ChatGPT-User",
|
|
11
|
+
"OAI-SearchBot",
|
|
12
|
+
"ClaudeBot",
|
|
13
|
+
"Claude-User",
|
|
14
|
+
"anthropic-ai",
|
|
15
|
+
"CCBot",
|
|
16
|
+
"Google-Extended"
|
|
17
|
+
];
|
|
18
|
+
function normalizeRoute(value) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (!trimmed) return "/";
|
|
21
|
+
return trimmed.startsWith("/") ? trimmed.replace(/\/{2,}/g, "/") : `/${trimmed}`;
|
|
22
|
+
}
|
|
23
|
+
function normalizeBaseUrl(value) {
|
|
24
|
+
if (!value) return void 0;
|
|
25
|
+
try {
|
|
26
|
+
const url = new URL(value);
|
|
27
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
28
|
+
url.search = "";
|
|
29
|
+
url.hash = "";
|
|
30
|
+
return url.toString().replace(/\/+$/, "");
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function normalizeStringArray(value) {
|
|
36
|
+
if (Array.isArray(value)) return value;
|
|
37
|
+
return value ? [value] : [];
|
|
38
|
+
}
|
|
39
|
+
function normalizeAiPolicy(value) {
|
|
40
|
+
return value === false || value === "disallow" ? "disallow" : "allow";
|
|
41
|
+
}
|
|
42
|
+
function unique(values) {
|
|
43
|
+
return [...new Set(values.filter(Boolean))];
|
|
44
|
+
}
|
|
45
|
+
function resolveDocsRobotsConfig(input, options = {}) {
|
|
46
|
+
if (input === false) return {
|
|
47
|
+
enabled: false,
|
|
48
|
+
ai: "allow",
|
|
49
|
+
userAgents: [...DEFAULT_DOCS_AI_ROBOTS_USER_AGENTS],
|
|
50
|
+
extraRules: []
|
|
51
|
+
};
|
|
52
|
+
const config = typeof input === "object" ? input : {};
|
|
53
|
+
return {
|
|
54
|
+
enabled: config.enabled ?? true,
|
|
55
|
+
path: config.path,
|
|
56
|
+
baseUrl: normalizeBaseUrl(config.baseUrl) ?? normalizeBaseUrl(options.baseUrl),
|
|
57
|
+
ai: normalizeAiPolicy(config.ai),
|
|
58
|
+
userAgents: unique([...DEFAULT_DOCS_AI_ROBOTS_USER_AGENTS, ...normalizeStringArray(config.aiUserAgents)]),
|
|
59
|
+
extraRules: config.extraRules ?? []
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getDocsRobotsAllowRoutes(options = {}) {
|
|
63
|
+
const normalizedEntry = normalizeDocsPathSegment(options.entry ?? "docs") || "docs";
|
|
64
|
+
const sitemapConfig = resolveDocsSitemapConfig(options.sitemap);
|
|
65
|
+
const routes = [
|
|
66
|
+
"/",
|
|
67
|
+
`/${normalizedEntry}`,
|
|
68
|
+
`/${normalizedEntry}/`,
|
|
69
|
+
`/${normalizedEntry}.md`,
|
|
70
|
+
`/${normalizedEntry}/*.md`,
|
|
71
|
+
DEFAULT_LLMS_TXT_ROUTE,
|
|
72
|
+
DEFAULT_LLMS_FULL_TXT_ROUTE,
|
|
73
|
+
DEFAULT_LLMS_TXT_WELL_KNOWN_ROUTE,
|
|
74
|
+
DEFAULT_LLMS_FULL_TXT_WELL_KNOWN_ROUTE,
|
|
75
|
+
DEFAULT_SKILL_MD_ROUTE,
|
|
76
|
+
DEFAULT_SKILL_MD_WELL_KNOWN_ROUTE,
|
|
77
|
+
DEFAULT_AGENTS_MD_ROUTE,
|
|
78
|
+
DEFAULT_AGENTS_MD_WELL_KNOWN_ROUTE,
|
|
79
|
+
DEFAULT_AGENT_MD_ROUTE,
|
|
80
|
+
DEFAULT_AGENT_MD_WELL_KNOWN_ROUTE,
|
|
81
|
+
DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE,
|
|
82
|
+
DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE,
|
|
83
|
+
...options.apiCatalog === false ? [] : [DEFAULT_API_CATALOG_ROUTE],
|
|
84
|
+
DEFAULT_AGENT_SKILLS_INDEX_ROUTE,
|
|
85
|
+
`${DEFAULT_AGENT_SKILLS_ROUTE_PREFIX}/*`,
|
|
86
|
+
DEFAULT_LEGACY_SKILLS_INDEX_ROUTE,
|
|
87
|
+
`${DEFAULT_LEGACY_SKILLS_ROUTE_PREFIX}/*`,
|
|
88
|
+
...options.agentCard ? [DEFAULT_A2A_AGENT_CARD_ROUTE] : [],
|
|
89
|
+
DEFAULT_MCP_PUBLIC_ROUTE,
|
|
90
|
+
DEFAULT_MCP_WELL_KNOWN_ROUTE
|
|
91
|
+
];
|
|
92
|
+
if (sitemapConfig.enabled) {
|
|
93
|
+
if (sitemapConfig.xml.enabled) routes.push(sitemapConfig.xml.route);
|
|
94
|
+
if (sitemapConfig.markdown.enabled) {
|
|
95
|
+
routes.push(sitemapConfig.markdown.route, sitemapConfig.markdown.wellKnownRoute);
|
|
96
|
+
if (sitemapConfig.markdown.docsRoute) routes.push(sitemapConfig.markdown.docsRoute);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return unique(routes.map(normalizeRoute));
|
|
100
|
+
}
|
|
101
|
+
function sitemapUrls(robots, sitemap) {
|
|
102
|
+
const sitemapConfig = resolveDocsSitemapConfig(sitemap, { baseUrl: robots.baseUrl });
|
|
103
|
+
if (!robots.baseUrl || !sitemapConfig.enabled || !sitemapConfig.xml.enabled) return [];
|
|
104
|
+
try {
|
|
105
|
+
return [new URL(sitemapConfig.xml.route, `${robots.baseUrl}/`).toString()];
|
|
106
|
+
} catch {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function appendRule(lines, rule) {
|
|
111
|
+
const userAgents = normalizeStringArray(rule.userAgent);
|
|
112
|
+
if (userAgents.length === 0) return;
|
|
113
|
+
lines.push("");
|
|
114
|
+
for (const userAgent of userAgents) lines.push(`User-agent: ${userAgent}`);
|
|
115
|
+
for (const route of normalizeStringArray(rule.allow)) lines.push(`Allow: ${normalizeRoute(route)}`);
|
|
116
|
+
for (const route of normalizeStringArray(rule.disallow)) lines.push(`Disallow: ${normalizeRoute(route)}`);
|
|
117
|
+
if (typeof rule.crawlDelay === "number" && Number.isFinite(rule.crawlDelay)) lines.push(`Crawl-delay: ${rule.crawlDelay}`);
|
|
118
|
+
}
|
|
119
|
+
function renderDocsRobotsTxt(options = {}) {
|
|
120
|
+
const robots = resolveDocsRobotsConfig(options.robots, { baseUrl: options.baseUrl });
|
|
121
|
+
if (!robots.enabled) return "";
|
|
122
|
+
const lines = [
|
|
123
|
+
"# Generated by @farming-labs/docs.",
|
|
124
|
+
"# Edit docs.config or rerun `docs robots generate --append` / `--force`.",
|
|
125
|
+
"",
|
|
126
|
+
"User-agent: *"
|
|
127
|
+
];
|
|
128
|
+
for (const route of getDocsRobotsAllowRoutes(options)) lines.push(`Allow: ${route}`);
|
|
129
|
+
for (const userAgent of robots.userAgents) {
|
|
130
|
+
lines.push("", `User-agent: ${userAgent}`);
|
|
131
|
+
lines.push(robots.ai === "allow" ? "Allow: /" : "Disallow: /");
|
|
132
|
+
}
|
|
133
|
+
for (const rule of robots.extraRules) appendRule(lines, rule);
|
|
134
|
+
const sitemap = sitemapUrls(robots, options.sitemap);
|
|
135
|
+
if (sitemap.length > 0) {
|
|
136
|
+
lines.push("");
|
|
137
|
+
for (const url of sitemap) lines.push(`Sitemap: ${url}`);
|
|
138
|
+
}
|
|
139
|
+
return `${lines.join("\n")}\n`;
|
|
140
|
+
}
|
|
141
|
+
function resolveDocsRobotsRequest(url, robots) {
|
|
142
|
+
const pathname = normalizeRoute(url.pathname);
|
|
143
|
+
const format = url.searchParams.get("format")?.trim();
|
|
144
|
+
if (pathname === "/api/docs" && format === "robots") return "robots";
|
|
145
|
+
if (!resolveDocsRobotsConfig(robots).enabled) return null;
|
|
146
|
+
return pathname === DEFAULT_ROBOTS_TXT_ROUTE ? "robots" : null;
|
|
147
|
+
}
|
|
148
|
+
function createDocsRobotsResponse({ request, ...options }) {
|
|
149
|
+
const url = new URL(request.url);
|
|
150
|
+
if (!resolveDocsRobotsRequest(url, options.robots)) return null;
|
|
151
|
+
const content = renderDocsRobotsTxt({
|
|
152
|
+
...options,
|
|
153
|
+
baseUrl: options.baseUrl ?? url.origin
|
|
154
|
+
});
|
|
155
|
+
if (!content) return null;
|
|
156
|
+
return new Response(content, { headers: {
|
|
157
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
158
|
+
"Cache-Control": "public, max-age=0, s-maxage=3600"
|
|
159
|
+
} });
|
|
160
|
+
}
|
|
161
|
+
function renderDocsRobotsGeneratedBlock(options = {}) {
|
|
162
|
+
return `${DOCS_ROBOTS_GENERATED_BLOCK_START}\n${renderDocsRobotsTxt(options).trimEnd()}\n${DOCS_ROBOTS_GENERATED_BLOCK_END}\n`;
|
|
163
|
+
}
|
|
164
|
+
function upsertDocsRobotsGeneratedBlock(existing, block) {
|
|
165
|
+
const escapedStart = DOCS_ROBOTS_GENERATED_BLOCK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
166
|
+
const escapedEnd = DOCS_ROBOTS_GENERATED_BLOCK_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
167
|
+
const pattern = new RegExp(`${escapedStart}[\\s\\S]*?${escapedEnd}\\n?`);
|
|
168
|
+
if (pattern.test(existing)) return existing.replace(pattern, block);
|
|
169
|
+
const prefix = existing.trimEnd();
|
|
170
|
+
return `${prefix}${prefix ? "\n\n" : ""}${block}`;
|
|
171
|
+
}
|
|
172
|
+
function blockForUserAgent(content, userAgent) {
|
|
173
|
+
const escaped = userAgent.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
174
|
+
return content.match(new RegExp(`(?:^|\\n)\\s*User-agent:\\s*${escaped}\\s*(?:\\n[ \\t]*(?!User-agent:).*)*`, "i"))?.[0] ?? "";
|
|
175
|
+
}
|
|
176
|
+
function disallowsRoute(content, route) {
|
|
177
|
+
const escapedRoute = route.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
178
|
+
return new RegExp(`^\\s*Disallow:\\s*${escapedRoute}(?:\\s|$)`, "im").test(content);
|
|
179
|
+
}
|
|
180
|
+
function analyzeDocsRobotsTxt(content, options = {}) {
|
|
181
|
+
const expectedRoutes = getDocsRobotsAllowRoutes(options).filter((route) => [
|
|
182
|
+
DEFAULT_LLMS_TXT_ROUTE,
|
|
183
|
+
DEFAULT_LLMS_FULL_TXT_ROUTE,
|
|
184
|
+
DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE,
|
|
185
|
+
DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE,
|
|
186
|
+
DEFAULT_AGENTS_MD_ROUTE,
|
|
187
|
+
DEFAULT_SKILL_MD_ROUTE,
|
|
188
|
+
DEFAULT_MCP_PUBLIC_ROUTE
|
|
189
|
+
].includes(route) || route.includes("sitemap"));
|
|
190
|
+
const missingRoutes = expectedRoutes.filter((route) => !content.includes(route));
|
|
191
|
+
return {
|
|
192
|
+
blocksAgentRoutes: /Disallow:\s*\/(?:\s|$)/i.test(blockForUserAgent(content, "*")) || expectedRoutes.some((route) => disallowsRoute(content, route)),
|
|
193
|
+
blocksAiAgents: DEFAULT_DOCS_AI_ROBOTS_USER_AGENTS.some((userAgent) => /Disallow:\s*\/(?:\s|$)/i.test(blockForUserAgent(content, userAgent))),
|
|
194
|
+
hasAgentRoutes: missingRoutes.length === 0,
|
|
195
|
+
hasAiPolicy: DEFAULT_DOCS_AI_ROBOTS_USER_AGENTS.some((userAgent) => content.includes(userAgent)),
|
|
196
|
+
missingRoutes
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
export { analyzeDocsRobotsTxt as a, renderDocsRobotsGeneratedBlock as c, resolveDocsRobotsRequest as d, upsertDocsRobotsGeneratedBlock as f, DOCS_ROBOTS_GENERATED_BLOCK_START as i, renderDocsRobotsTxt as l, DEFAULT_ROBOTS_TXT_ROUTE as n, createDocsRobotsResponse as o, DOCS_ROBOTS_GENERATED_BLOCK_END as r, getDocsRobotsAllowRoutes as s, DEFAULT_DOCS_AI_ROBOTS_USER_AGENTS as t, resolveDocsRobotsConfig as u };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import "./agent-DKKptIgy.mjs";
|
|
2
|
+
import "./standards-discovery-jkykaXq1.mjs";
|
|
3
|
+
import { c as renderDocsRobotsGeneratedBlock, f as upsertDocsRobotsGeneratedBlock, i as DOCS_ROBOTS_GENERATED_BLOCK_START, r as DOCS_ROBOTS_GENERATED_BLOCK_END, u as resolveDocsRobotsConfig } from "./robots-BIpC4j4P.mjs";
|
|
4
|
+
import { a as loadDocsConfigModule, g as resolveDocsConfigPath, h as readTopLevelStringProperty, l as readBooleanProperty, p as readStringProperty, t as extractNestedObjectLiteral } from "./config-Wcdj-D0a.mjs";
|
|
5
|
+
import { t as detectFramework } from "./utils-DpiIioYb.mjs";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import pc from "picocolors";
|
|
9
|
+
|
|
10
|
+
//#region src/cli/robots.ts
|
|
11
|
+
function parseInlineFlag(arg) {
|
|
12
|
+
const [rawKey, value] = arg.slice(2).split("=", 2);
|
|
13
|
+
return {
|
|
14
|
+
key: rawKey.trim(),
|
|
15
|
+
value
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function parseRobotsGenerateArgs(argv) {
|
|
19
|
+
const parsed = {};
|
|
20
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
21
|
+
const arg = argv[index];
|
|
22
|
+
if (arg === "--help" || arg === "-h") {
|
|
23
|
+
parsed.help = true;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (arg === "--append") {
|
|
27
|
+
parsed.append = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (arg === "--force") {
|
|
31
|
+
parsed.force = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (arg === "--check") {
|
|
35
|
+
parsed.check = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (arg.startsWith("--config=")) {
|
|
39
|
+
const value = parseInlineFlag(arg).value;
|
|
40
|
+
if (!value) throw new Error("Missing value for --config.");
|
|
41
|
+
parsed.configPath = value;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (arg === "--config") {
|
|
45
|
+
const value = argv[index + 1];
|
|
46
|
+
if (!value || value.startsWith("--")) throw new Error("Missing value for --config.");
|
|
47
|
+
parsed.configPath = value;
|
|
48
|
+
index += 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (arg.startsWith("--path=")) {
|
|
52
|
+
const value = parseInlineFlag(arg).value;
|
|
53
|
+
if (!value) throw new Error("Missing value for --path.");
|
|
54
|
+
parsed.path = value;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (arg === "--path") {
|
|
58
|
+
const value = argv[index + 1];
|
|
59
|
+
if (!value || value.startsWith("--")) throw new Error("Missing value for --path.");
|
|
60
|
+
parsed.path = value;
|
|
61
|
+
index += 1;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!arg.startsWith("--") && !parsed.path) {
|
|
65
|
+
parsed.path = arg;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`Unknown robots generate flag: ${arg}.`);
|
|
69
|
+
}
|
|
70
|
+
if (parsed.append && parsed.force) throw new Error("Use either --append or --force, not both.");
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
function readTopLevelBooleanProperty(content, key) {
|
|
74
|
+
const match = content.match(new RegExp(`\\b${key}\\b\\s*:\\s*(true|false)`));
|
|
75
|
+
return match ? match[1] === "true" : void 0;
|
|
76
|
+
}
|
|
77
|
+
function readLlmsBaseUrlFromConfig(content, config) {
|
|
78
|
+
if (config?.llmsTxt && typeof config.llmsTxt === "object") return config.llmsTxt.baseUrl;
|
|
79
|
+
const block = extractNestedObjectLiteral(content, ["llmsTxt"]);
|
|
80
|
+
return block ? readStringProperty(block, "baseUrl") : void 0;
|
|
81
|
+
}
|
|
82
|
+
function readSitemapConfigFromStatic(content) {
|
|
83
|
+
const topLevelBoolean = readTopLevelBooleanProperty(content, "sitemap");
|
|
84
|
+
if (typeof topLevelBoolean === "boolean") return topLevelBoolean;
|
|
85
|
+
const block = extractNestedObjectLiteral(content, ["sitemap"]);
|
|
86
|
+
if (!block) return void 0;
|
|
87
|
+
return {
|
|
88
|
+
enabled: readBooleanProperty(block, "enabled") ?? true,
|
|
89
|
+
routePrefix: readStringProperty(block, "routePrefix"),
|
|
90
|
+
baseUrl: readStringProperty(block, "baseUrl"),
|
|
91
|
+
manifestPath: readStringProperty(block, "manifestPath")
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function readRobotsConfigFromStatic(content) {
|
|
95
|
+
const topLevelBoolean = readTopLevelBooleanProperty(content, "robots");
|
|
96
|
+
if (typeof topLevelBoolean === "boolean") return topLevelBoolean;
|
|
97
|
+
const block = extractNestedObjectLiteral(content, ["robots"]);
|
|
98
|
+
if (!block) return void 0;
|
|
99
|
+
const aiString = readStringProperty(block, "ai");
|
|
100
|
+
const aiBoolean = readBooleanProperty(block, "ai");
|
|
101
|
+
return {
|
|
102
|
+
enabled: readBooleanProperty(block, "enabled") ?? true,
|
|
103
|
+
path: readStringProperty(block, "path"),
|
|
104
|
+
baseUrl: readStringProperty(block, "baseUrl"),
|
|
105
|
+
ai: aiString === "allow" || aiString === "disallow" ? aiString : typeof aiBoolean === "boolean" ? aiBoolean : void 0
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function resolveConfiguredRobots(content, config) {
|
|
109
|
+
if (config?.robots !== void 0) return config.robots;
|
|
110
|
+
return readRobotsConfigFromStatic(content) ?? true;
|
|
111
|
+
}
|
|
112
|
+
function resolvePublicDir(rootDir) {
|
|
113
|
+
if (detectFramework(rootDir) === "sveltekit") return path.join(rootDir, "static");
|
|
114
|
+
return path.join(rootDir, "public");
|
|
115
|
+
}
|
|
116
|
+
function resolveRobotsPath(rootDir, options, robots) {
|
|
117
|
+
const configuredPath = options.path ?? robots?.path;
|
|
118
|
+
if (configuredPath) return path.isAbsolute(configuredPath) ? configuredPath : path.resolve(rootDir, configuredPath);
|
|
119
|
+
return path.join(resolvePublicDir(rootDir), "robots.txt");
|
|
120
|
+
}
|
|
121
|
+
function writeIfChanged(filePath, content, check) {
|
|
122
|
+
if ((existsSync(filePath) ? readFileSync(filePath, "utf-8") : void 0) === content) return false;
|
|
123
|
+
if (check) return true;
|
|
124
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
125
|
+
writeFileSync(filePath, content, "utf-8");
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
async function generateRobots(options = {}) {
|
|
129
|
+
const rootDir = process.cwd();
|
|
130
|
+
const loadedConfigModule = await loadDocsConfigModule(rootDir, options.configPath);
|
|
131
|
+
const configContent = readFileSync(loadedConfigModule?.path ?? resolveDocsConfigPath(rootDir, options.configPath), "utf-8");
|
|
132
|
+
const config = loadedConfigModule?.config;
|
|
133
|
+
const entry = config?.entry ?? readTopLevelStringProperty(configContent, "entry") ?? "docs";
|
|
134
|
+
const sitemap = config?.sitemap ?? readSitemapConfigFromStatic(configContent) ?? true;
|
|
135
|
+
const sitemapBaseUrl = typeof sitemap === "object" ? sitemap.baseUrl : void 0;
|
|
136
|
+
const llmsBaseUrl = readLlmsBaseUrlFromConfig(configContent, config);
|
|
137
|
+
const configuredRobots = resolveConfiguredRobots(configContent, config);
|
|
138
|
+
if (configuredRobots === false) throw new Error("Robots generation is disabled by `robots: false`.");
|
|
139
|
+
const robotsInput = typeof configuredRobots === "object" ? configuredRobots : {};
|
|
140
|
+
const robots = resolveDocsRobotsConfig(robotsInput, { baseUrl: robotsInput.baseUrl ?? sitemapBaseUrl ?? llmsBaseUrl });
|
|
141
|
+
if (!robots.enabled) throw new Error("Robots generation is disabled by `robots.enabled: false`.");
|
|
142
|
+
const robotsPath = resolveRobotsPath(rootDir, options, robotsInput);
|
|
143
|
+
const relativeRobotsPath = path.relative(rootDir, robotsPath).replace(/\\/g, "/");
|
|
144
|
+
const generatedBlock = renderDocsRobotsGeneratedBlock({
|
|
145
|
+
entry,
|
|
146
|
+
sitemap,
|
|
147
|
+
baseUrl: robots.baseUrl,
|
|
148
|
+
robots
|
|
149
|
+
});
|
|
150
|
+
const existing = existsSync(robotsPath) ? readFileSync(robotsPath, "utf-8") : void 0;
|
|
151
|
+
const hasGeneratedBlock = existing?.includes(DOCS_ROBOTS_GENERATED_BLOCK_START) === true && existing.includes(DOCS_ROBOTS_GENERATED_BLOCK_END);
|
|
152
|
+
if (existing !== void 0 && !options.force && !options.append && !hasGeneratedBlock) {
|
|
153
|
+
console.log(pc.yellow(`Found existing robots.txt at ${relativeRobotsPath}.`));
|
|
154
|
+
console.log(pc.dim("Keeping the user-owned file. Use --append to add/update the generated block, or --force to replace it."));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const changed = writeIfChanged(robotsPath, existing !== void 0 && (options.append || hasGeneratedBlock) ? upsertDocsRobotsGeneratedBlock(existing, generatedBlock) : generatedBlock, options.check === true);
|
|
158
|
+
if (options.check && changed) throw new Error(`Robots output is stale at ${relativeRobotsPath}. Run \`docs robots generate${options.append ? " --append" : options.force ? " --force" : ""}${options.path ? ` --path ${options.path}` : ""}\` to update it.`);
|
|
159
|
+
console.log(changed ? pc.green(`Generated robots policy at ${relativeRobotsPath}.`) : pc.green(`Robots policy is current at ${relativeRobotsPath}.`));
|
|
160
|
+
}
|
|
161
|
+
function printRobotsGenerateHelp() {
|
|
162
|
+
console.log(`
|
|
163
|
+
${pc.bold("docs robots generate")} — Generate a static robots.txt agent access policy.
|
|
164
|
+
|
|
165
|
+
${pc.dim("Usage:")}
|
|
166
|
+
pnpm exec docs ${pc.cyan("robots generate")} ${pc.dim("[path]")}
|
|
167
|
+
|
|
168
|
+
${pc.dim("Options:")}
|
|
169
|
+
${pc.cyan("--path <path>")} Write to a specific robots.txt path; defaults to the framework public directory
|
|
170
|
+
${pc.cyan("--append")} Add or update a generated block inside an existing robots.txt
|
|
171
|
+
${pc.cyan("--force")} Replace the target robots.txt with the generated policy
|
|
172
|
+
${pc.cyan("--check")} Fail if the generated output would change
|
|
173
|
+
${pc.cyan("--config <path>")} Use a custom docs config path instead of ${pc.dim("docs.config.ts[x]")}
|
|
174
|
+
${pc.cyan("-h, --help")} Show this help message
|
|
175
|
+
`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//#endregion
|
|
179
|
+
export { generateRobots, parseRobotsGenerateArgs, printRobotsGenerateHelp };
|