@lexibase/rdx-core 1.4.0 → 2.1.0
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/check/index.d.ts +25 -0
- package/dist/check/index.js +310 -0
- package/dist/chunk-CGOXC3S6.js +233 -0
- package/dist/chunk-FPBRKD4M.js +14 -0
- package/dist/{chunk-Z6GCGXVC.js → chunk-LCBSNAUH.js} +7 -2
- package/dist/chunk-SNNEXRLQ.js +75 -0
- package/dist/chunk-WDWRIRH2.js +947 -0
- package/dist/config/index.d.ts +2 -16
- package/dist/config/index.js +9 -1
- package/dist/{document-links-BtWSWs2x.d.ts → document-links-Dr4JVYuN.d.ts} +4 -0
- package/dist/index-DjuvW7o_.d.ts +49 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +22 -169
- package/dist/mdx/index.d.ts +1 -1
- package/dist/mdx/index.js +1 -1
- package/dist/search/index.js +3 -5
- package/package.json +10 -6
- package/dist/chunk-75BDBF5N.js +0 -468
package/dist/chunk-75BDBF5N.js
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
// src/config/index.ts
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { existsSync } from "fs";
|
|
4
|
-
|
|
5
|
-
// src/config/error.ts
|
|
6
|
-
var RdxConfigError = class extends Error {
|
|
7
|
-
constructor(message) {
|
|
8
|
-
super(`Invalid rdx.config.ts: ${message}`);
|
|
9
|
-
this.name = "RdxConfigError";
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// src/config/metadata.ts
|
|
14
|
-
function validateMetadata(input) {
|
|
15
|
-
function string(value, field) {
|
|
16
|
-
if (typeof value !== "string" || !value.trim())
|
|
17
|
-
throw new RdxConfigError(`${field} must be a non-empty string.`);
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
function url(value, field, relative = false) {
|
|
21
|
-
const source = string(value, field);
|
|
22
|
-
try {
|
|
23
|
-
if (/[\s\\]/.test(source)) throw new Error();
|
|
24
|
-
if (relative && /^\/(?!\/)/.test(source)) return;
|
|
25
|
-
const parsed = new URL(source);
|
|
26
|
-
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password)
|
|
27
|
-
throw new Error();
|
|
28
|
-
} catch {
|
|
29
|
-
throw new RdxConfigError(
|
|
30
|
-
`${field} must be ${relative ? "a root-relative path or " : ""}an absolute http(s) URL.`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function object2(value, field, allowed) {
|
|
35
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
36
|
-
throw new RdxConfigError(`${field} must be an object.`);
|
|
37
|
-
const result = value;
|
|
38
|
-
for (const key of Object.keys(result))
|
|
39
|
-
if (!allowed.includes(key))
|
|
40
|
-
throw new RdxConfigError(`unknown option ${field}.${key}.`);
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
function array(value, field, validate) {
|
|
44
|
-
if (!Array.isArray(value))
|
|
45
|
-
throw new RdxConfigError(`${field} must be an array.`);
|
|
46
|
-
value.forEach((item, index) => validate(item, `${field}[${index}]`));
|
|
47
|
-
}
|
|
48
|
-
const metadata = object2(input, "metadata", [
|
|
49
|
-
"metadataBase",
|
|
50
|
-
"applicationName",
|
|
51
|
-
"since",
|
|
52
|
-
"authors",
|
|
53
|
-
"keywords",
|
|
54
|
-
"icons",
|
|
55
|
-
"manifest",
|
|
56
|
-
"robots",
|
|
57
|
-
"openGraph",
|
|
58
|
-
"twitter"
|
|
59
|
-
]);
|
|
60
|
-
if (metadata.metadataBase !== void 0)
|
|
61
|
-
url(metadata.metadataBase, "metadata.metadataBase");
|
|
62
|
-
string(metadata.applicationName, "metadata.applicationName");
|
|
63
|
-
if (metadata.since !== void 0 && (typeof metadata.since !== "number" || !Number.isInteger(metadata.since) || metadata.since < 1 || metadata.since > (/* @__PURE__ */ new Date()).getFullYear()))
|
|
64
|
-
throw new RdxConfigError(
|
|
65
|
-
"metadata.since must be a positive integer no later than the current year."
|
|
66
|
-
);
|
|
67
|
-
if (metadata.manifest !== void 0)
|
|
68
|
-
url(metadata.manifest, "metadata.manifest", true);
|
|
69
|
-
if (metadata.keywords !== void 0)
|
|
70
|
-
array(metadata.keywords, "metadata.keywords", string);
|
|
71
|
-
if (metadata.authors !== void 0)
|
|
72
|
-
array(metadata.authors, "metadata.authors", (value, field) => {
|
|
73
|
-
const author = object2(value, field, ["name", "url"]);
|
|
74
|
-
string(author.name, `${field}.name`);
|
|
75
|
-
if (author.url !== void 0) url(author.url, `${field}.url`);
|
|
76
|
-
});
|
|
77
|
-
if (metadata.icons !== void 0) {
|
|
78
|
-
const icons = object2(metadata.icons, "metadata.icons", [
|
|
79
|
-
"icon",
|
|
80
|
-
"shortcut",
|
|
81
|
-
"apple"
|
|
82
|
-
]);
|
|
83
|
-
for (const [key, value] of Object.entries(icons)) {
|
|
84
|
-
if (value === void 0) continue;
|
|
85
|
-
const field = `metadata.icons.${key}`;
|
|
86
|
-
if (key === "icon" && Array.isArray(value))
|
|
87
|
-
array(value, field, (item, field2) => {
|
|
88
|
-
const icon = object2(item, field2, ["url", "sizes", "type"]);
|
|
89
|
-
url(icon.url, `${field2}.url`, true);
|
|
90
|
-
for (const key2 of ["sizes", "type"])
|
|
91
|
-
if (icon[key2] !== void 0) string(icon[key2], `${field2}.${key2}`);
|
|
92
|
-
});
|
|
93
|
-
else url(value, field, true);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (metadata.robots !== void 0) {
|
|
97
|
-
const robots = object2(metadata.robots, "metadata.robots", [
|
|
98
|
-
"index",
|
|
99
|
-
"follow"
|
|
100
|
-
]);
|
|
101
|
-
for (const [key, value] of Object.entries(robots))
|
|
102
|
-
if (value !== void 0 && typeof value !== "boolean")
|
|
103
|
-
throw new RdxConfigError(`metadata.robots.${key} must be a boolean.`);
|
|
104
|
-
}
|
|
105
|
-
for (const key of ["openGraph", "twitter"]) {
|
|
106
|
-
if (metadata[key] === void 0) continue;
|
|
107
|
-
const field = `metadata.${key}`;
|
|
108
|
-
const social = object2(
|
|
109
|
-
metadata[key],
|
|
110
|
-
field,
|
|
111
|
-
key === "openGraph" ? ["title", "description", "siteName", "locale", "type", "images"] : ["title", "description", "card", "site", "creator", "images"]
|
|
112
|
-
);
|
|
113
|
-
for (const [name, value] of Object.entries(social)) {
|
|
114
|
-
if (name === "images" || value === void 0) continue;
|
|
115
|
-
string(value, `${field}.${name}`);
|
|
116
|
-
if (name === "type" && value !== "website" || name === "card" && !["summary", "summary_large_image"].includes(value))
|
|
117
|
-
throw new RdxConfigError(`${field}.${name} has an unsupported value.`);
|
|
118
|
-
}
|
|
119
|
-
if (social.images !== void 0)
|
|
120
|
-
array(social.images, `${field}.images`, (value, field2) => {
|
|
121
|
-
if (key === "twitter") return url(value, field2, true);
|
|
122
|
-
const image = object2(value, field2, ["url", "width", "height", "alt"]);
|
|
123
|
-
url(image.url, `${field2}.url`, true);
|
|
124
|
-
if (image.alt !== void 0) string(image.alt, `${field2}.alt`);
|
|
125
|
-
for (const dimension of ["width", "height"])
|
|
126
|
-
if (image[dimension] !== void 0 && (typeof image[dimension] !== "number" || !Number.isInteger(image[dimension]) || image[dimension] <= 0))
|
|
127
|
-
throw new RdxConfigError(
|
|
128
|
-
`${field2}.${dimension} must be a positive integer.`
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/config/index.ts
|
|
135
|
-
function record(value) {
|
|
136
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
137
|
-
}
|
|
138
|
-
function object(value, field) {
|
|
139
|
-
if (!record(value)) throw new RdxConfigError(`${field} must be an object.`);
|
|
140
|
-
return value;
|
|
141
|
-
}
|
|
142
|
-
function text(value, field, allowEmpty = false) {
|
|
143
|
-
if (typeof value !== "string" || !allowEmpty && !value.trim()) {
|
|
144
|
-
throw new RdxConfigError(
|
|
145
|
-
`${field} must be ${allowEmpty ? "a string" : "a non-empty string"}.`
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
function component(value, field) {
|
|
151
|
-
if (typeof value !== "function" && !(record(value) && [
|
|
152
|
-
/* @__PURE__ */ Symbol.for("react.memo"),
|
|
153
|
-
/* @__PURE__ */ Symbol.for("react.forward_ref"),
|
|
154
|
-
/* @__PURE__ */ Symbol.for("react.lazy")
|
|
155
|
-
].includes(value.$$typeof)))
|
|
156
|
-
throw new RdxConfigError(
|
|
157
|
-
`${field} must be a React component, not JSX or a file path.`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
function keys(value, allowed, field) {
|
|
161
|
-
for (const key of Object.keys(value)) {
|
|
162
|
-
if (!allowed.includes(key))
|
|
163
|
-
throw new RdxConfigError(`unknown option ${field}${key}.`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function resolveProjectPath(rootDir, value, field) {
|
|
167
|
-
text(value, field);
|
|
168
|
-
const resolved = path.resolve(
|
|
169
|
-
/* turbopackIgnore: true */
|
|
170
|
-
rootDir,
|
|
171
|
-
value
|
|
172
|
-
);
|
|
173
|
-
const relative = path.relative(rootDir, resolved);
|
|
174
|
-
if (path.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
175
|
-
throw new RdxConfigError(
|
|
176
|
-
`${field} must be a relative path inside the project.`
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
return resolved;
|
|
180
|
-
}
|
|
181
|
-
function resolveConfig(input) {
|
|
182
|
-
const config = object(input, "default export");
|
|
183
|
-
if ("title" in config)
|
|
184
|
-
throw new RdxConfigError(
|
|
185
|
-
"title has been removed. Set the site name in metadata.applicationName instead."
|
|
186
|
-
);
|
|
187
|
-
if ("docsDir" in config)
|
|
188
|
-
throw new RdxConfigError(
|
|
189
|
-
"docsDir is not configurable. Live documentation must be stored in docs/."
|
|
190
|
-
);
|
|
191
|
-
keys(
|
|
192
|
-
config,
|
|
193
|
-
[
|
|
194
|
-
"description",
|
|
195
|
-
"metadata",
|
|
196
|
-
"lang",
|
|
197
|
-
"theme",
|
|
198
|
-
"navbar",
|
|
199
|
-
"plugins",
|
|
200
|
-
"homepage",
|
|
201
|
-
"TOC",
|
|
202
|
-
"search"
|
|
203
|
-
],
|
|
204
|
-
""
|
|
205
|
-
);
|
|
206
|
-
if (config.search !== void 0 && typeof config.search !== "boolean")
|
|
207
|
-
throw new RdxConfigError("search must be a boolean.");
|
|
208
|
-
if (config.TOC !== void 0 && typeof config.TOC !== "boolean")
|
|
209
|
-
throw new RdxConfigError("TOC must be a boolean.");
|
|
210
|
-
if (config.description !== void 0)
|
|
211
|
-
text(config.description, "description", true);
|
|
212
|
-
if (config.lang !== void 0) text(config.lang, "lang");
|
|
213
|
-
validateMetadata(config.metadata);
|
|
214
|
-
if (config.homepage !== void 0) {
|
|
215
|
-
const homepage = object(config.homepage, "homepage");
|
|
216
|
-
keys(
|
|
217
|
-
homepage,
|
|
218
|
-
["enabled", "component", "title", "description", "buttons"],
|
|
219
|
-
"homepage."
|
|
220
|
-
);
|
|
221
|
-
if (homepage.component !== void 0)
|
|
222
|
-
component(homepage.component, "homepage.component");
|
|
223
|
-
if (homepage.enabled !== void 0 && typeof homepage.enabled !== "boolean")
|
|
224
|
-
throw new RdxConfigError("homepage.enabled must be a boolean.");
|
|
225
|
-
if (homepage.title !== void 0) text(homepage.title, "homepage.title");
|
|
226
|
-
if (homepage.description !== void 0)
|
|
227
|
-
text(homepage.description, "homepage.description", true);
|
|
228
|
-
if (homepage.buttons !== void 0) {
|
|
229
|
-
if (!Array.isArray(homepage.buttons))
|
|
230
|
-
throw new RdxConfigError("homepage.buttons must be an array.");
|
|
231
|
-
for (const [index, value] of homepage.buttons.entries()) {
|
|
232
|
-
const field = `homepage.buttons[${index}]`;
|
|
233
|
-
const button = object(value, field);
|
|
234
|
-
keys(button, ["label", "href"], `${field}.`);
|
|
235
|
-
text(button.label, `${field}.label`);
|
|
236
|
-
const href = text(button.href, `${field}.href`);
|
|
237
|
-
if (/[\s\\]/.test(href) || !/^\/(?!\/)/.test(href) && !/^https?:\/\//i.test(href))
|
|
238
|
-
throw new RdxConfigError(
|
|
239
|
-
`${field}.href must be a root-relative path or http(s) URL.`
|
|
240
|
-
);
|
|
241
|
-
try {
|
|
242
|
-
new URL(href, "https://rdx.local");
|
|
243
|
-
} catch {
|
|
244
|
-
throw new RdxConfigError(`${field}.href must be a valid URL.`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (config.theme !== void 0) {
|
|
250
|
-
const theme = object(config.theme, "theme");
|
|
251
|
-
keys(theme, ["defaultTheme"], "theme.");
|
|
252
|
-
if (theme.defaultTheme !== void 0 && (typeof theme.defaultTheme !== "string" || !["system", "dark", "light"].includes(theme.defaultTheme))) {
|
|
253
|
-
throw new RdxConfigError(
|
|
254
|
-
"theme.defaultTheme must be system, dark, or light."
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (config.navbar !== void 0) {
|
|
259
|
-
const navbar = object(config.navbar, "navbar");
|
|
260
|
-
keys(navbar, ["title", "logo", "actions"], "navbar.");
|
|
261
|
-
if (navbar.logo !== void 0) component(navbar.logo, "navbar.logo");
|
|
262
|
-
if (navbar.title !== void 0) text(navbar.title, "navbar.title", true);
|
|
263
|
-
if (navbar.actions !== void 0) {
|
|
264
|
-
const actions = object(navbar.actions, "navbar.actions");
|
|
265
|
-
keys(actions, ["github", "showToggleMode"], "navbar.actions.");
|
|
266
|
-
if (actions.showToggleMode !== void 0 && typeof actions.showToggleMode !== "boolean")
|
|
267
|
-
throw new RdxConfigError(
|
|
268
|
-
"navbar.actions.showToggleMode must be a boolean."
|
|
269
|
-
);
|
|
270
|
-
if (actions.github !== void 0) {
|
|
271
|
-
const github = object(actions.github, "navbar.actions.github");
|
|
272
|
-
keys(github, ["visible", "url"], "navbar.actions.github.");
|
|
273
|
-
if (typeof github.visible !== "boolean")
|
|
274
|
-
throw new RdxConfigError(
|
|
275
|
-
"navbar.actions.github.visible must be a boolean."
|
|
276
|
-
);
|
|
277
|
-
const url = text(github.url, "navbar.actions.github.url");
|
|
278
|
-
if (url !== "#" && !/^https?:\/\//i.test(url))
|
|
279
|
-
throw new RdxConfigError(
|
|
280
|
-
'navbar.actions.github.url must use http or https, or "#" as a placeholder.'
|
|
281
|
-
);
|
|
282
|
-
try {
|
|
283
|
-
if (url !== "#") new URL(url);
|
|
284
|
-
} catch {
|
|
285
|
-
throw new RdxConfigError(
|
|
286
|
-
"navbar.actions.github.url must be a valid URL."
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (config.plugins !== void 0 && !Array.isArray(config.plugins)) {
|
|
293
|
-
throw new RdxConfigError("plugins must be an array of plugin objects.");
|
|
294
|
-
}
|
|
295
|
-
const names = /* @__PURE__ */ new Set();
|
|
296
|
-
for (const [index, value] of (config.plugins ?? []).entries()) {
|
|
297
|
-
const plugin = object(
|
|
298
|
-
value,
|
|
299
|
-
`plugins[${index}] (call the plugin factory, e.g. versioning())`
|
|
300
|
-
);
|
|
301
|
-
const name = text(plugin.name, `plugins[${index}].name`);
|
|
302
|
-
if (names.has(name))
|
|
303
|
-
throw new RdxConfigError(`plugin "${name}" is configured more than once.`);
|
|
304
|
-
names.add(name);
|
|
305
|
-
if (plugin.apiVersion !== 1)
|
|
306
|
-
throw new RdxConfigError(`plugin "${name}" must support apiVersion 1.`);
|
|
307
|
-
if (plugin.setup !== void 0 && typeof plugin.setup !== "function")
|
|
308
|
-
throw new RdxConfigError(`plugin "${name}" setup must be a function.`);
|
|
309
|
-
if (plugin.commands !== void 0 && !Array.isArray(plugin.commands))
|
|
310
|
-
throw new RdxConfigError(`plugin "${name}" commands must be an array.`);
|
|
311
|
-
}
|
|
312
|
-
const typed = config;
|
|
313
|
-
return {
|
|
314
|
-
...typed,
|
|
315
|
-
TOC: typed.TOC ?? false,
|
|
316
|
-
search: typed.search ?? false,
|
|
317
|
-
description: typed.description ?? "",
|
|
318
|
-
lang: typed.lang ?? "en",
|
|
319
|
-
theme: { defaultTheme: typed.theme?.defaultTheme ?? "system" },
|
|
320
|
-
plugins: typed.plugins ?? []
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
function defineConfig(config) {
|
|
324
|
-
resolveConfig(config);
|
|
325
|
-
return config;
|
|
326
|
-
}
|
|
327
|
-
async function createRdxProject(input, {
|
|
328
|
-
rootDir = process.cwd(),
|
|
329
|
-
command = "runtime"
|
|
330
|
-
} = {}) {
|
|
331
|
-
rootDir = path.resolve(
|
|
332
|
-
/* turbopackIgnore: true */
|
|
333
|
-
rootDir
|
|
334
|
-
);
|
|
335
|
-
const config = resolveConfig(input);
|
|
336
|
-
const docsRoot = resolveProjectPath(
|
|
337
|
-
rootDir,
|
|
338
|
-
"docs",
|
|
339
|
-
"documentation directory"
|
|
340
|
-
);
|
|
341
|
-
const sources = [
|
|
342
|
-
{
|
|
343
|
-
id: "current",
|
|
344
|
-
label: "Current",
|
|
345
|
-
docsDir: "docs",
|
|
346
|
-
routePrefix: ""
|
|
347
|
-
}
|
|
348
|
-
];
|
|
349
|
-
const commands = [];
|
|
350
|
-
const runtimeFiles = /* @__PURE__ */ new Set();
|
|
351
|
-
const commandNames = /* @__PURE__ */ new Set([
|
|
352
|
-
"dev",
|
|
353
|
-
"build",
|
|
354
|
-
"start",
|
|
355
|
-
"prepare",
|
|
356
|
-
"help",
|
|
357
|
-
"add"
|
|
358
|
-
]);
|
|
359
|
-
for (const plugin of config.plugins) {
|
|
360
|
-
for (const value of plugin.commands ?? []) {
|
|
361
|
-
const entry = object(value, `plugin "${plugin.name}" command`);
|
|
362
|
-
const name = text(entry.name, `plugin "${plugin.name}" command.name`);
|
|
363
|
-
if (!/^[a-z][a-z0-9-]*$/.test(name) || commandNames.has(name)) {
|
|
364
|
-
throw new RdxConfigError(
|
|
365
|
-
`plugin "${plugin.name}" command "${name}" is invalid or already registered.`
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
text(entry.description, `command ${name}.description`);
|
|
369
|
-
if (typeof entry.run !== "function")
|
|
370
|
-
throw new RdxConfigError(`command ${name}.run must be a function.`);
|
|
371
|
-
commandNames.add(name);
|
|
372
|
-
commands.push(value);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
for (const plugin of config.plugins) {
|
|
376
|
-
let result;
|
|
377
|
-
try {
|
|
378
|
-
result = await plugin.setup?.({ rootDir, command, config });
|
|
379
|
-
} catch (error) {
|
|
380
|
-
throw new Error(
|
|
381
|
-
`[${plugin.name}] ${error instanceof Error ? error.message : String(error)}`
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
if (result === void 0) continue;
|
|
385
|
-
const contribution = object(result, `plugin "${plugin.name}" setup result`);
|
|
386
|
-
if (contribution.runtimeFiles !== void 0) {
|
|
387
|
-
if (!Array.isArray(contribution.runtimeFiles))
|
|
388
|
-
throw new RdxConfigError(
|
|
389
|
-
`plugin "${plugin.name}" runtimeFiles must be an array.`
|
|
390
|
-
);
|
|
391
|
-
for (const value of contribution.runtimeFiles) {
|
|
392
|
-
const field = `plugin "${plugin.name}" runtimeFiles`;
|
|
393
|
-
const filename = text(value, field);
|
|
394
|
-
const resolved = resolveProjectPath(rootDir, filename, field);
|
|
395
|
-
runtimeFiles.add(path.relative(rootDir, resolved));
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
if (contribution.sources === void 0) continue;
|
|
399
|
-
if (!Array.isArray(contribution.sources))
|
|
400
|
-
throw new RdxConfigError(
|
|
401
|
-
`plugin "${plugin.name}" sources must be an array.`
|
|
402
|
-
);
|
|
403
|
-
for (const value of contribution.sources) {
|
|
404
|
-
const source = object(value, `plugin "${plugin.name}" content source`);
|
|
405
|
-
const id = text(source.id, "content source id");
|
|
406
|
-
const prefix = text(
|
|
407
|
-
source.routePrefix,
|
|
408
|
-
`content source ${id}.routePrefix`
|
|
409
|
-
);
|
|
410
|
-
text(source.label, `content source ${id}.label`);
|
|
411
|
-
const docsDir = text(source.docsDir, `content source ${id}.docsDir`);
|
|
412
|
-
resolveProjectPath(rootDir, docsDir, `content source ${id}.docsDir`);
|
|
413
|
-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(prefix) || prefix === "." || prefix === "..") {
|
|
414
|
-
throw new RdxConfigError(
|
|
415
|
-
`content source ${id}.routePrefix must be a single safe URL segment.`
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
if (sources.some((other) => other.id === id || other.routePrefix === prefix)) {
|
|
419
|
-
throw new RdxConfigError(
|
|
420
|
-
`duplicate content source id or route prefix: ${id}.`
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
if (existsSync(
|
|
424
|
-
/* turbopackIgnore: true */
|
|
425
|
-
path.join(
|
|
426
|
-
/* turbopackIgnore: true */
|
|
427
|
-
docsRoot,
|
|
428
|
-
prefix
|
|
429
|
-
)
|
|
430
|
-
) || existsSync(
|
|
431
|
-
/* turbopackIgnore: true */
|
|
432
|
-
path.join(
|
|
433
|
-
/* turbopackIgnore: true */
|
|
434
|
-
docsRoot,
|
|
435
|
-
`${prefix}.mdx`
|
|
436
|
-
)
|
|
437
|
-
)) {
|
|
438
|
-
throw new RdxConfigError(
|
|
439
|
-
`content source ${id} conflicts with live documentation at /docs/${prefix}.`
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
if (source.badge !== void 0)
|
|
443
|
-
text(source.badge, `content source ${id}.badge`);
|
|
444
|
-
if (source.redirectTo !== void 0)
|
|
445
|
-
text(source.redirectTo, `content source ${id}.redirectTo`);
|
|
446
|
-
sources.push(source);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
for (const source of sources) {
|
|
450
|
-
if (source.redirectTo === void 0) continue;
|
|
451
|
-
const target = sources.find(
|
|
452
|
-
(entry) => entry.routePrefix === source.redirectTo
|
|
453
|
-
);
|
|
454
|
-
if (!target || target === source || target.redirectTo !== void 0 || target.docsDir !== source.docsDir)
|
|
455
|
-
throw new RdxConfigError(
|
|
456
|
-
`content source ${source.id}.redirectTo must reference a canonical source with the same docsDir.`
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
return { rootDir, config, sources, commands, runtimeFiles: [...runtimeFiles] };
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export {
|
|
463
|
-
RdxConfigError,
|
|
464
|
-
resolveProjectPath,
|
|
465
|
-
resolveConfig,
|
|
466
|
-
defineConfig,
|
|
467
|
-
createRdxProject
|
|
468
|
-
};
|