docs: add generator for llms-full.txt (#11323)

* initial

* improvements

* finished implementation

* transform links to index.html.md links

* fix for resources
This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-02-05 16:34:39 +02:00
1 parent da25980d24
commit 5f7ff7f9f0
17 files changed
+31023 -17

No files matched your search

+1
View File
@@ -24,6 +24,7 @@
"autoprefixer": "10.4.14",
"clsx": "^2.0.0",
"docs-ui": "*",
"docs-utils": "*",
"jsdom": "^22.1.0",
"json-schema": "^0.4.0",
"json-stringify-pretty-compact": "^4.0.0",
@@ -6,6 +6,7 @@ import readSpecDocument from "./read-spec-document"
import getSectionId from "./get-section-id"
import dereference from "./dereference"
import { unstable_cache } from "next/cache"
import { oasFileToPath } from "docs-utils"
async function getPathsOfTag_(
tagName: string,
@@ -25,9 +26,7 @@ async function getPathsOfTag_(
return {
...fileContent,
operationPath: `/${file
.replaceAll(/(?<!\{[^}]*)_(?![^{]*\})/g, "/")
.replace(/\.[A-Za-z]+$/, "")}`,
operationPath: oasFileToPath(file),
}
})
)
+2 -1
View File
@@ -17,4 +17,5 @@ NEXT_PUBLIC_AI_WEBSITE_ID=
NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY=
CLOUDINARY_CLOUD_NAME=
NEXT_PUBLIC_BASE_PATH=
NEXT_PUBLIC_GA_ID=
NEXT_PUBLIC_GA_ID=
NEXT_PUBLIC_PROD_BASE_URL=
@@ -67,7 +67,7 @@ export async function GET(req: NextRequest, { params }: Params) {
const getCleanMd_ = unstable_cache(
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) =>
getCleanMd({ filePath, plugins }),
getCleanMd({ file: filePath, plugins }),
["clean-md"],
{
revalidate: 3600,
File diff suppressed because it is too large. Load diff
+224 -1
View File
@@ -1,11 +1,234 @@
import "dotenv/config"
import path from "path"
import { sidebar } from "../sidebar.mjs"
import { generateEditedDates, generateSidebar } from "build-scripts"
import {
generateEditedDates,
generateLlmsFull,
generateSidebar,
} from "build-scripts"
import {
addUrlToRelativeLink,
crossProjectLinksPlugin,
localLinksRehypePlugin,
} from "remark-rehype-plugins"
async function main() {
await generateEditedDates()
await generateSidebar(sidebar, {
addNumbering: true,
})
const baseUrl =
process.env.NEXT_PUBLIC_PROD_BASE_URL || process.env.NEXT_PUBLIC_BASE_URL
await generateLlmsFull({
outputPath: path.join(process.cwd(), "public", "llms-full.txt"),
plugins: {
before: [
[
crossProjectLinksPlugin,
{
baseUrl,
projectUrls: {
resources: {
url: baseUrl,
},
"user-guide": {
url: baseUrl,
},
ui: {
url: baseUrl,
},
api: {
url: baseUrl,
},
},
useBaseUrl: true,
},
],
[localLinksRehypePlugin],
],
after: [[addUrlToRelativeLink, { url: baseUrl }]],
},
scanDirs: [
{
dir: path.join(process.cwd(), "app"),
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"app",
"commerce-modules"
),
allowedFilesPatterns: [
/^(?!.*\/(workflows|js-sdk|extend|events|admin-widget-zones)\/).*$/,
],
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"references",
"core_flows"
),
allowedFilesPatterns: [/Workflows_[^.]+\/functions/],
generator: {
name: "workflows",
options: {
baseUrl,
},
},
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"references",
"core_flows"
),
allowedFilesPatterns: [/Steps_[^.]+\/functions/],
generator: {
name: "steps",
options: {
baseUrl,
},
},
},
{
dir: path.join(process.cwd(), "..", "resources", "app", "medusa-cli"),
},
{
dir: path.join(process.cwd(), "..", "resources", "app", "medusa-cli"),
},
{
dir: path.join(process.cwd(), "..", "resources", "app", "js-sdk"),
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"references",
"js_sdk",
"admin"
),
allowedFilesPatterns: [/\/methods\//],
generator: {
name: "jsSdk",
options: {
baseUrl,
type: "Admin",
},
},
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"references",
"js_sdk",
"auth"
),
allowedFilesPatterns: [/\/methods\//],
generator: {
name: "jsSdk",
options: {
baseUrl,
type: "Auth",
},
},
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"references",
"js_sdk",
"store"
),
allowedFilesPatterns: [/\/properties\//],
generator: {
name: "jsSdk",
options: {
baseUrl,
type: "Store",
},
},
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"references",
"medusa_config",
"interfaces",
"medusa_config.ConfigModule"
),
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"app",
"admin-components"
),
},
{
dir: path.join(
process.cwd(),
"..",
"resources",
"app",
"service-factory-reference"
),
},
{
dir: path.join(process.cwd(), "..", "api-reference", "markdown"),
},
{
dir: path.join(
process.cwd(),
"..",
"api-reference",
"specs",
"admin",
"paths"
),
ext: "yaml",
generator: {
name: "apiRef",
options: {
baseUrl: `${baseUrl}/api/admin`,
type: "Admin",
},
},
},
{
dir: path.join(
process.cwd(),
"..",
"api-reference",
"specs",
"store",
"paths"
),
ext: "yaml",
generator: {
name: "apiRef",
options: {
baseUrl: `${baseUrl}/api/store`,
type: "Store",
},
},
},
],
})
}
void main()
@@ -24,7 +24,9 @@ export async function GET(req: NextRequest, { params }: Params) {
path.join(process.cwd(), "app")
path.join(process.cwd(), "references")
const filePathFromMap = await getFileFromMaps(`/${slug.join("/")}`)
const filePathFromMap = await getFileFromMaps(
`/${slug.join("/")}`.replace("//", "/")
)
if (!filePathFromMap) {
return notFound()
}
@@ -77,7 +79,7 @@ export async function GET(req: NextRequest, { params }: Params) {
const getCleanMd_ = unstable_cache(
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) =>
getCleanMd({ filePath, plugins }),
getCleanMd({ file: filePath, plugins }),
["clean-md"],
{
revalidate: 3600,
@@ -58,7 +58,7 @@ const getCleanMd_ = unstable_cache(
const iconNames = Object.keys(Icons).filter((name) => name !== "default")
return getCleanMd({
filePath,
file: filePath,
plugins,
parserOptions: {
ComponentExample: {
@@ -68,7 +68,7 @@ export async function GET(req: NextRequest, { params }: Params) {
const getCleanMd_ = unstable_cache(
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) =>
getCleanMd({ filePath, plugins }),
getCleanMd({ file: filePath, plugins }),
["clean-md"],
{
revalidate: 3600,