@lexibase/rdx-core 1.0.0-beta.0 → 1.0.0-beta.2

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,214 @@
1
+ // src/config/index.ts
2
+ import path from "path";
3
+ import { existsSync } from "fs";
4
+ var RdxConfigError = class extends Error {
5
+ constructor(message) {
6
+ super(`Invalid rdx.config.ts: ${message}`);
7
+ this.name = "RdxConfigError";
8
+ }
9
+ };
10
+ function record(value) {
11
+ return typeof value === "object" && value !== null && !Array.isArray(value);
12
+ }
13
+ function object(value, field) {
14
+ if (!record(value)) throw new RdxConfigError(`${field} must be an object.`);
15
+ return value;
16
+ }
17
+ function text(value, field, allowEmpty = false) {
18
+ if (typeof value !== "string" || !allowEmpty && !value.trim()) {
19
+ throw new RdxConfigError(
20
+ `${field} must be ${allowEmpty ? "a string" : "a non-empty string"}.`
21
+ );
22
+ }
23
+ return value;
24
+ }
25
+ function keys(value, allowed, field) {
26
+ for (const key of Object.keys(value)) {
27
+ if (!allowed.includes(key))
28
+ throw new RdxConfigError(`unknown option ${field}${key}.`);
29
+ }
30
+ }
31
+ function resolveProjectPath(rootDir, value, field) {
32
+ text(value, field);
33
+ const resolved = path.resolve(rootDir, value);
34
+ const relative = path.relative(rootDir, resolved);
35
+ if (path.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
36
+ throw new RdxConfigError(
37
+ `${field} must be a relative path inside the project.`
38
+ );
39
+ }
40
+ return resolved;
41
+ }
42
+ function resolveConfig(input) {
43
+ const config = object(input, "default export");
44
+ keys(
45
+ config,
46
+ ["title", "description", "lang", "docsDir", "theme", "navbar", "plugins"],
47
+ ""
48
+ );
49
+ text(config.title, "title");
50
+ if (config.description !== void 0)
51
+ text(config.description, "description", true);
52
+ if (config.lang !== void 0) text(config.lang, "lang");
53
+ if (config.docsDir !== void 0) text(config.docsDir, "docsDir");
54
+ if (config.theme !== void 0) {
55
+ const theme = object(config.theme, "theme");
56
+ keys(theme, ["defaultTheme"], "theme.");
57
+ if (theme.defaultTheme !== void 0 && (typeof theme.defaultTheme !== "string" || !["system", "dark", "light"].includes(theme.defaultTheme))) {
58
+ throw new RdxConfigError(
59
+ "theme.defaultTheme must be system, dark, or light."
60
+ );
61
+ }
62
+ }
63
+ if (config.navbar !== void 0) {
64
+ const navbar = object(config.navbar, "navbar");
65
+ keys(navbar, ["title", "actions"], "navbar.");
66
+ if (navbar.title !== void 0) text(navbar.title, "navbar.title", true);
67
+ if (navbar.actions !== void 0) {
68
+ const actions = object(navbar.actions, "navbar.actions");
69
+ keys(actions, ["github"], "navbar.actions.");
70
+ if (actions.github !== void 0) {
71
+ const github = object(actions.github, "navbar.actions.github");
72
+ keys(github, ["visible", "url"], "navbar.actions.github.");
73
+ if (typeof github.visible !== "boolean")
74
+ throw new RdxConfigError(
75
+ "navbar.actions.github.visible must be a boolean."
76
+ );
77
+ const url = text(github.url, "navbar.actions.github.url");
78
+ if (!/^https?:\/\//i.test(url))
79
+ throw new RdxConfigError(
80
+ "navbar.actions.github.url must use http or https."
81
+ );
82
+ try {
83
+ new URL(url);
84
+ } catch {
85
+ throw new RdxConfigError(
86
+ "navbar.actions.github.url must be a valid URL."
87
+ );
88
+ }
89
+ }
90
+ }
91
+ }
92
+ if (config.plugins !== void 0 && !Array.isArray(config.plugins)) {
93
+ throw new RdxConfigError("plugins must be an array of plugin objects.");
94
+ }
95
+ const names = /* @__PURE__ */ new Set();
96
+ for (const [index, value] of (config.plugins ?? []).entries()) {
97
+ const plugin = object(
98
+ value,
99
+ `plugins[${index}] (call the plugin factory, e.g. versioning())`
100
+ );
101
+ const name = text(plugin.name, `plugins[${index}].name`);
102
+ if (names.has(name))
103
+ throw new RdxConfigError(`plugin "${name}" is configured more than once.`);
104
+ names.add(name);
105
+ if (plugin.apiVersion !== 1)
106
+ throw new RdxConfigError(`plugin "${name}" must support apiVersion 1.`);
107
+ if (plugin.setup !== void 0 && typeof plugin.setup !== "function")
108
+ throw new RdxConfigError(`plugin "${name}" setup must be a function.`);
109
+ if (plugin.commands !== void 0 && !Array.isArray(plugin.commands))
110
+ throw new RdxConfigError(`plugin "${name}" commands must be an array.`);
111
+ }
112
+ const typed = config;
113
+ return {
114
+ ...typed,
115
+ description: typed.description ?? "",
116
+ lang: typed.lang ?? "en",
117
+ docsDir: typed.docsDir ?? "docs",
118
+ theme: { defaultTheme: typed.theme?.defaultTheme ?? "system" },
119
+ plugins: typed.plugins ?? []
120
+ };
121
+ }
122
+ function defineConfig(config) {
123
+ resolveConfig(config);
124
+ return config;
125
+ }
126
+ async function createRdxProject(input, {
127
+ rootDir = process.cwd(),
128
+ command = "runtime"
129
+ } = {}) {
130
+ rootDir = path.resolve(rootDir);
131
+ const config = resolveConfig(input);
132
+ const docsRoot = resolveProjectPath(rootDir, config.docsDir, "docsDir");
133
+ const sources = [
134
+ {
135
+ id: "current",
136
+ label: "Current",
137
+ docsDir: config.docsDir,
138
+ routePrefix: ""
139
+ }
140
+ ];
141
+ const commands = [];
142
+ const commandNames = /* @__PURE__ */ new Set(["dev", "build", "start", "prepare", "help"]);
143
+ for (const plugin of config.plugins) {
144
+ for (const value of plugin.commands ?? []) {
145
+ const entry = object(value, `plugin "${plugin.name}" command`);
146
+ const name = text(entry.name, `plugin "${plugin.name}" command.name`);
147
+ if (!/^[a-z][a-z0-9-]*$/.test(name) || commandNames.has(name)) {
148
+ throw new RdxConfigError(
149
+ `plugin "${plugin.name}" command "${name}" is invalid or already registered.`
150
+ );
151
+ }
152
+ text(entry.description, `command ${name}.description`);
153
+ if (typeof entry.run !== "function")
154
+ throw new RdxConfigError(`command ${name}.run must be a function.`);
155
+ commandNames.add(name);
156
+ commands.push(value);
157
+ }
158
+ }
159
+ for (const plugin of config.plugins) {
160
+ let result;
161
+ try {
162
+ result = await plugin.setup?.({ rootDir, command, config });
163
+ } catch (error) {
164
+ throw new Error(
165
+ `[${plugin.name}] ${error instanceof Error ? error.message : String(error)}`
166
+ );
167
+ }
168
+ if (result === void 0) continue;
169
+ const contribution = object(result, `plugin "${plugin.name}" setup result`);
170
+ if (contribution.sources === void 0) continue;
171
+ if (!Array.isArray(contribution.sources))
172
+ throw new RdxConfigError(
173
+ `plugin "${plugin.name}" sources must be an array.`
174
+ );
175
+ for (const value of contribution.sources) {
176
+ const source = object(value, `plugin "${plugin.name}" content source`);
177
+ const id = text(source.id, "content source id");
178
+ const prefix = text(
179
+ source.routePrefix,
180
+ `content source ${id}.routePrefix`
181
+ );
182
+ text(source.label, `content source ${id}.label`);
183
+ const docsDir = text(source.docsDir, `content source ${id}.docsDir`);
184
+ resolveProjectPath(rootDir, docsDir, `content source ${id}.docsDir`);
185
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(prefix) || prefix === "." || prefix === "..") {
186
+ throw new RdxConfigError(
187
+ `content source ${id}.routePrefix must be a single safe URL segment.`
188
+ );
189
+ }
190
+ if (sources.some((other) => other.id === id || other.routePrefix === prefix)) {
191
+ throw new RdxConfigError(
192
+ `duplicate content source id or route prefix: ${id}.`
193
+ );
194
+ }
195
+ if (existsSync(path.join(docsRoot, prefix)) || existsSync(path.join(docsRoot, `${prefix}.mdx`))) {
196
+ throw new RdxConfigError(
197
+ `content source ${id} conflicts with live documentation at /docs/${prefix}.`
198
+ );
199
+ }
200
+ if (source.badge !== void 0)
201
+ text(source.badge, `content source ${id}.badge`);
202
+ sources.push(source);
203
+ }
204
+ }
205
+ return { rootDir, config, sources, commands };
206
+ }
207
+
208
+ export {
209
+ RdxConfigError,
210
+ resolveProjectPath,
211
+ resolveConfig,
212
+ defineConfig,
213
+ createRdxProject
214
+ };
@@ -0,0 +1,15 @@
1
+ import { RdxProject, RdxConfig, ResolvedRdxConfig } from '@lexibase/rdx-types';
2
+
3
+ declare class RdxConfigError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ /** Resolve project-owned paths without allowing traversal or filesystem roots. */
7
+ declare function resolveProjectPath(rootDir: string, value: string, field: string): string;
8
+ declare function resolveConfig(input: unknown): ResolvedRdxConfig;
9
+ declare function defineConfig(config: RdxConfig): RdxConfig;
10
+ declare function createRdxProject(input: unknown, { rootDir, command, }?: {
11
+ rootDir?: string;
12
+ command?: string;
13
+ }): Promise<RdxProject>;
14
+
15
+ export { RdxConfigError, createRdxProject, defineConfig, resolveConfig, resolveProjectPath };
@@ -0,0 +1,14 @@
1
+ import {
2
+ RdxConfigError,
3
+ createRdxProject,
4
+ defineConfig,
5
+ resolveConfig,
6
+ resolveProjectPath
7
+ } from "../chunk-WPEYN7KN.js";
8
+ export {
9
+ RdxConfigError,
10
+ createRdxProject,
11
+ defineConfig,
12
+ resolveConfig,
13
+ resolveProjectPath
14
+ };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,6 @@
1
- import { DocCategory, MDXLoader, RdxDocsOptions, RdxDocCategory, RdxDocument } from '@lexibase/rdx-types';
2
- import * as react from 'react';
3
-
4
- declare function docsIndexer(version?: string): DocCategory[];
5
-
6
- declare function mdxLoader({ filename, version, versionsRaw, mdxComponents, docsRoot, }: MDXLoader): Promise<{
7
- content: react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
8
- frontmatter: Record<string, unknown>;
9
- }>;
1
+ import * as _lexibase_rdx_types from '@lexibase/rdx-types';
2
+ import { RdxDocsOptions, RdxDocCategory, RdxDocument, RdxProject, RdxContentSource } from '@lexibase/rdx-types';
3
+ export { RdxConfigError, createRdxProject, defineConfig, resolveConfig, resolveProjectPath } from './config/index.js';
10
4
 
11
5
  /**
12
6
  * Reads the documentation tree from the user's project. The URL slug always
@@ -17,4 +11,16 @@ declare function getDocsIndex({ docsDir, }?: RdxDocsOptions): RdxDocCategory[];
17
11
  declare function getDocsPaths(options?: RdxDocsOptions): string[];
18
12
  declare function getDocument(slug: string, { docsDir }?: RdxDocsOptions): RdxDocument | null;
19
13
 
20
- export { docsIndexer, getDocsIndex, getDocsPaths, getDocument, mdxLoader };
14
+ declare function getSourceOptions(project: RdxProject, source: RdxContentSource): {
15
+ docsDir: string;
16
+ };
17
+ /** Match plugin routes before looking up pages in the live documentation. */
18
+ declare function resolveDocsRoute(project: RdxProject, segments?: string[]): {
19
+ source: RdxContentSource;
20
+ slug: string | undefined;
21
+ document: _lexibase_rdx_types.RdxDocument | null;
22
+ categories: _lexibase_rdx_types.RdxDocCategory[];
23
+ };
24
+ declare function getProjectDocsPaths(project: RdxProject): string[];
25
+
26
+ export { getDocsIndex, getDocsPaths, getDocument, getProjectDocsPaths, getSourceOptions, resolveDocsRoute };
package/dist/index.js CHANGED
@@ -1,154 +1,19 @@
1
- // src/loaders/docs-indexer/index.ts
1
+ import {
2
+ RdxConfigError,
3
+ createRdxProject,
4
+ defineConfig,
5
+ resolveConfig,
6
+ resolveProjectPath
7
+ } from "./chunk-WPEYN7KN.js";
8
+
9
+ // src/content/index.ts
2
10
  import fs from "fs";
3
11
  import path from "path";
4
12
  import matter from "gray-matter";
5
- function docsIndexer(version) {
6
- const resolvedVersion = version || "canary";
7
- let basePath;
8
- if (resolvedVersion === "canary") {
9
- basePath = path.join(process.cwd(), "app/docs/(canary)");
10
- } else {
11
- const versionedPath = path.join(
12
- process.cwd(),
13
- "app/docs/(versioned)",
14
- `version-${resolvedVersion}`
15
- );
16
- const archivedPath = path.join(
17
- process.cwd(),
18
- "app/docs/(archived)",
19
- `version-${resolvedVersion}`
20
- );
21
- basePath = fs.existsSync(versionedPath) ? versionedPath : archivedPath;
22
- }
23
- if (!fs.existsSync(basePath)) {
24
- console.warn(`Docs Folder not found: ${basePath}`);
25
- return [];
26
- }
27
- const categories = [];
28
- const entries = fs.readdirSync(basePath, { withFileTypes: true });
29
- entries.forEach((entry) => {
30
- if (!entry.isDirectory()) {
31
- if (entry.name.endsWith(".mdx")) {
32
- throw new Error(
33
- `File '${entry.name}' detected inside "${basePath}".
34
- Please move it into a folder`
35
- );
36
- }
37
- }
38
- const categoryPath = path.join(basePath, entry.name);
39
- const hasMdxFile = fs.readdirSync(categoryPath).some((file) => file.endsWith(".mdx"));
40
- if (!hasMdxFile) return;
41
- const categoryMetaPath = path.join(categoryPath, "_category.json");
42
- let categoryTitle = entry.name;
43
- let categoryPosition = 999;
44
- if (fs.existsSync(categoryMetaPath)) {
45
- try {
46
- const rawMeta = fs.readFileSync(categoryMetaPath, "utf-8");
47
- const meta = JSON.parse(rawMeta);
48
- categoryTitle = meta.title || categoryTitle;
49
- categoryPosition = meta.sidebar_position ?? categoryPosition;
50
- } catch (err) {
51
- console.warn(`Error reading _category.json em ${entry.name}:`, err);
52
- }
53
- }
54
- const files = fs.readdirSync(categoryPath);
55
- const links = files.filter((file) => file.endsWith(".mdx")).map((file) => {
56
- const filePath = path.join(categoryPath, file);
57
- const raw = fs.readFileSync(filePath, "utf-8");
58
- const { data } = matter(raw);
59
- const filename = file.replace(".mdx", "");
60
- const slug = resolvedVersion === "canary" ? `/docs/canary/${filename}` : `/docs/${resolvedVersion}/${filename}`;
61
- return {
62
- href: slug,
63
- label: data.title || filename,
64
- description: data.description || "",
65
- position: data.link_position ?? 1
66
- };
67
- }).sort((a, b) => a.position - b.position).map(({ position: _position, ...link }) => link);
68
- categories.push({
69
- title: categoryTitle,
70
- links,
71
- position: categoryPosition
72
- });
73
- });
74
- return categories.sort((a, b) => a.position - b.position).map(({ position: _position, ...category }) => category);
75
- }
76
-
77
- // src/loaders/mdx-loader/index.ts
78
- import fs2 from "fs";
79
- import path2 from "path";
80
- import { compileMDX } from "next-mdx-remote/rsc";
81
- async function mdxLoader({
82
- filename,
83
- version,
84
- versionsRaw,
85
- mdxComponents,
86
- docsRoot = "app/docs"
87
- }) {
88
- const defaultVersion = versionsRaw.active[0];
89
- if (!defaultVersion) {
90
- throw new Error("No static versions provided");
91
- }
92
- let basePath;
93
- if (version === "canary") {
94
- basePath = path2.join(process.cwd(), docsRoot, "(canary)");
95
- } else if (version) {
96
- const versionedPath = path2.join(
97
- process.cwd(),
98
- docsRoot,
99
- "(versioned)",
100
- `version-${version}`
101
- );
102
- const archivedPath = path2.join(
103
- process.cwd(),
104
- docsRoot,
105
- "(archived)",
106
- `version-${version}`
107
- );
108
- basePath = fs2.existsSync(versionedPath) ? versionedPath : archivedPath;
109
- } else {
110
- basePath = path2.join(
111
- process.cwd(),
112
- docsRoot,
113
- "(versioned)",
114
- `version-${defaultVersion}`
115
- );
116
- }
117
- const findFile = (dir) => {
118
- const entries = fs2.readdirSync(dir, { withFileTypes: true });
119
- for (const entry of entries) {
120
- const fullPath = path2.join(dir, entry.name);
121
- if (entry.isDirectory()) {
122
- const found = findFile(fullPath);
123
- if (found) return found;
124
- }
125
- if (entry.isFile() && entry.name === `${filename}.mdx`) {
126
- return fullPath;
127
- }
128
- }
129
- return null;
130
- };
131
- const filePath = findFile(basePath);
132
- if (!filePath) {
133
- throw new Error(`MDX File not found: ${filename}`);
134
- }
135
- const source = fs2.readFileSync(filePath, "utf8");
136
- const { content, frontmatter } = await compileMDX({
137
- source,
138
- components: mdxComponents,
139
- options: { parseFrontmatter: true }
140
- });
141
- return { content, frontmatter };
142
- }
143
-
144
- // src/content/index.ts
145
- import fs3 from "fs";
146
- import path3 from "path";
147
- import matter2 from "gray-matter";
148
13
  var MDX_EXTENSION = ".mdx";
149
14
  var DEFAULT_POSITION = Number.MAX_SAFE_INTEGER;
150
15
  function getDocsRoot(docsDir = "docs") {
151
- return path3.resolve(process.cwd(), docsDir);
16
+ return path.resolve(process.cwd(), docsDir);
152
17
  }
153
18
  function toTitle(value) {
154
19
  return value.replace(/[-_]/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
@@ -163,12 +28,12 @@ function numberValue(value, fallback = DEFAULT_POSITION) {
163
28
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
164
29
  }
165
30
  function readCategoryMeta(categoryPath, fallbackTitle) {
166
- const metaPath = path3.join(categoryPath, "_category.json");
167
- if (!fs3.existsSync(metaPath)) {
31
+ const metaPath = path.join(categoryPath, "_category.json");
32
+ if (!fs.existsSync(metaPath)) {
168
33
  return { title: fallbackTitle, position: DEFAULT_POSITION };
169
34
  }
170
35
  try {
171
- const parsed = JSON.parse(fs3.readFileSync(metaPath, "utf8"));
36
+ const parsed = JSON.parse(fs.readFileSync(metaPath, "utf8"));
172
37
  if (!isRecord(parsed)) {
173
38
  return { title: fallbackTitle, position: DEFAULT_POSITION };
174
39
  }
@@ -181,32 +46,32 @@ function readCategoryMeta(categoryPath, fallbackTitle) {
181
46
  }
182
47
  }
183
48
  function findMdxFiles(directory) {
184
- const entries = fs3.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
49
+ const entries = fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
185
50
  return entries.flatMap((entry) => {
186
- const entryPath = path3.join(directory, entry.name);
51
+ const entryPath = path.join(directory, entry.name);
187
52
  if (entry.isDirectory()) return findMdxFiles(entryPath);
188
53
  if (entry.isFile() && entry.name.endsWith(MDX_EXTENSION)) return [entryPath];
189
54
  return [];
190
55
  });
191
56
  }
192
57
  function slugFromRelativePath(relativePath) {
193
- return relativePath.split(path3.sep).join("/").replace(/\.mdx$/, "");
58
+ return relativePath.split(path.sep).join("/").replace(/\.mdx$/, "");
194
59
  }
195
60
  function isSafeSlug(slug) {
196
- if (path3.isAbsolute(slug) || slug.includes("\\")) return false;
61
+ if (path.isAbsolute(slug) || slug.includes("\\")) return false;
197
62
  return slug.split("/").every((segment) => segment && segment !== "." && segment !== "..");
198
63
  }
199
64
  function getDocsIndex({
200
65
  docsDir
201
66
  } = {}) {
202
67
  const docsRoot = getDocsRoot(docsDir);
203
- if (!fs3.existsSync(docsRoot)) return [];
68
+ if (!fs.existsSync(docsRoot)) return [];
204
69
  const categories = /* @__PURE__ */ new Map();
205
70
  for (const filePath of findMdxFiles(docsRoot)) {
206
- const relativePath = path3.relative(docsRoot, filePath);
207
- const pathParts = relativePath.split(path3.sep);
71
+ const relativePath = path.relative(docsRoot, filePath);
72
+ const pathParts = relativePath.split(path.sep);
208
73
  const categoryId = pathParts.length > 1 ? pathParts[0] ?? "_root" : "_root";
209
- const categoryPath = categoryId === "_root" ? docsRoot : path3.join(docsRoot, categoryId);
74
+ const categoryPath = categoryId === "_root" ? docsRoot : path.join(docsRoot, categoryId);
210
75
  const fallbackCategoryTitle = categoryId === "_root" ? "Overview" : toTitle(categoryId);
211
76
  let category = categories.get(categoryId);
212
77
  if (!category) {
@@ -221,11 +86,11 @@ function getDocsIndex({
221
86
  categories.set(categoryId, createdCategory);
222
87
  category = createdCategory;
223
88
  }
224
- const source = fs3.readFileSync(filePath, "utf8");
225
- const parsed = matter2(source);
89
+ const source = fs.readFileSync(filePath, "utf8");
90
+ const parsed = matter(source);
226
91
  const frontmatter = isRecord(parsed.data) ? parsed.data : {};
227
92
  const slug = slugFromRelativePath(relativePath);
228
- const fallbackTitle = toTitle(path3.basename(slug));
93
+ const fallbackTitle = toTitle(path.basename(slug));
229
94
  category.pages.push({
230
95
  slug,
231
96
  title: stringValue(frontmatter.title, fallbackTitle),
@@ -251,12 +116,12 @@ function getDocsPaths(options) {
251
116
  function getDocument(slug, { docsDir } = {}) {
252
117
  if (!isSafeSlug(slug)) return null;
253
118
  const docsRoot = getDocsRoot(docsDir);
254
- const sourcePath = path3.resolve(docsRoot, `${slug}${MDX_EXTENSION}`);
255
- const relativePath = path3.relative(docsRoot, sourcePath);
256
- if (relativePath.startsWith("..") || path3.isAbsolute(relativePath))
119
+ const sourcePath = path.resolve(docsRoot, `${slug}${MDX_EXTENSION}`);
120
+ const relativePath = path.relative(docsRoot, sourcePath);
121
+ if (relativePath.startsWith("..") || path.isAbsolute(relativePath))
257
122
  return null;
258
- if (!fs3.existsSync(sourcePath)) return null;
259
- const parsed = matter2(fs3.readFileSync(sourcePath, "utf8"));
123
+ if (!fs.existsSync(sourcePath)) return null;
124
+ const parsed = matter(fs.readFileSync(sourcePath, "utf8"));
260
125
  return {
261
126
  slug,
262
127
  sourcePath,
@@ -264,10 +129,54 @@ function getDocument(slug, { docsDir } = {}) {
264
129
  frontmatter: isRecord(parsed.data) ? parsed.data : {}
265
130
  };
266
131
  }
132
+
133
+ // src/project/index.ts
134
+ import path2 from "path";
135
+ function getSourceOptions(project, source) {
136
+ return { docsDir: path2.resolve(project.rootDir, source.docsDir) };
137
+ }
138
+ function resolveDocsRoute(project, segments = []) {
139
+ const source = project.sources.find(
140
+ (entry) => entry.routePrefix && entry.routePrefix === segments[0]
141
+ ) ?? project.sources[0];
142
+ const options = getSourceOptions(project, source);
143
+ const slug = (source.routePrefix ? segments.slice(1) : segments).join("/") || getDocsPaths(options)[0];
144
+ return {
145
+ source,
146
+ slug,
147
+ document: slug ? getDocument(slug, options) : null,
148
+ categories: getDocsIndex(options)
149
+ };
150
+ }
151
+ function getProjectDocsPaths(project) {
152
+ const paths = /* @__PURE__ */ new Set();
153
+ for (const source of project.sources) {
154
+ for (const slug of getDocsPaths(getSourceOptions(project, source))) {
155
+ const route = [source.routePrefix, slug].filter(Boolean).join("/");
156
+ if (paths.has(route))
157
+ throw new Error(`Conflicting documentation route: /docs/${route}`);
158
+ if (!source.routePrefix && project.sources.some(
159
+ (other) => other.routePrefix === slug.split("/")[0]
160
+ )) {
161
+ throw new Error(
162
+ `Live documentation route /docs/${slug} conflicts with a plugin content source.`
163
+ );
164
+ }
165
+ paths.add(route);
166
+ }
167
+ }
168
+ return [...paths];
169
+ }
267
170
  export {
268
- docsIndexer,
171
+ RdxConfigError,
172
+ createRdxProject,
173
+ defineConfig,
269
174
  getDocsIndex,
270
175
  getDocsPaths,
271
176
  getDocument,
272
- mdxLoader
177
+ getProjectDocsPaths,
178
+ getSourceOptions,
179
+ resolveConfig,
180
+ resolveDocsRoute,
181
+ resolveProjectPath
273
182
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexibase/rdx-core",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Content indexing and document utilities for RDX documentation projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,6 +10,10 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js"
13
+ },
14
+ "./config": {
15
+ "types": "./dist/config/index.d.ts",
16
+ "import": "./dist/config/index.js"
13
17
  }
14
18
  },
15
19
  "files": [
@@ -30,11 +34,7 @@
30
34
  "homepage": "https://github.com/lexibase/rdx#readme",
31
35
  "dependencies": {
32
36
  "gray-matter": "^4.0.3",
33
- "next-mdx-remote": "^5.0.0",
34
- "@lexibase/rdx-types": "1.0.0-beta.0"
35
- },
36
- "peerDependencies": {
37
- "react": "^19.1.1"
37
+ "@lexibase/rdx-types": "1.0.0-beta.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^22.15.3",
@@ -43,7 +43,8 @@
43
43
  "@rdx/typescript-config": "1.0.0"
44
44
  },
45
45
  "scripts": {
46
- "build": "tsup src/index.ts --format esm --dts --clean --external @lexibase/rdx-types --external gray-matter --external next-mdx-remote",
47
- "check-types": "tsc --noEmit"
46
+ "build": "tsup src/index.ts src/config/index.ts --format esm --dts --clean --external @lexibase/rdx-types --external gray-matter",
47
+ "check-types": "tsc --noEmit",
48
+ "test": "node --test tests/*.test.mjs"
48
49
  }
49
50
  }