docs: refactor medusa workflows reference (#8692)

* docs: fix handling of namespaces in core flows under definitions directory

* change nested handling

* docs-util: expand workflows under definitions in workflows reference

* remove check for definitions
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-08-22 13:39:52 +03:00
1 parent 4219674ead
commit 0acd94aac3
5 files changed
+126 -67

No files matched your search

@@ -11,7 +11,37 @@ const coreFlowsOptions: FormattingOptionsType = {
workflowDiagramComponent: "WorkflowDiagram",
mdxImports: [`import { TypeList, WorkflowDiagram } from "docs-ui"`],
},
"^core_flows/.*/functions/.*Workflow/page\\.mdx": {
"^core_flows/.*/.*Steps_.*/page\\.mdx": {
reflectionGroups: {
Namespaces: false,
Enumerations: false,
Classes: false,
Interfaces: false,
"Type Aliases": false,
Variables: false,
"Enumeration Members": false,
Properties: false,
"Type Literals": false,
Functions: true,
},
hideTocHeaders: true,
},
"^core_flows/.*/.*Workflows_.*/page\\.mdx": {
reflectionGroups: {
Namespaces: false,
Enumerations: false,
Classes: false,
Interfaces: false,
"Type Aliases": false,
Variables: false,
"Enumeration Members": false,
Properties: false,
"Type Literals": false,
Functions: true,
},
hideTocHeaders: true,
},
"^core_flows/.*/Workflows_.*/functions/.*/page\\.mdx": {
reflectionDescription:
"This documentation provides a reference to the `{{alias}}`. It belongs to the `@medusajs/core-flows` package.",
frontmatterData: {
@@ -24,7 +54,7 @@ const coreFlowsOptions: FormattingOptionsType = {
suffix: "- Medusa Workflows API Reference",
},
},
"^core_flows/.*/functions/.*Step/page\\.mdx": {
"^core_flows/.*/Steps_.*/functions/.*/page\\.mdx": {
reflectionDescription:
"This documentation provides a reference to the `{{alias}}`. It belongs to the `@medusajs/core-flows` package.",
frontmatterData: {
@@ -1,4 +1,4 @@
import { readdirSync } from "fs"
import { Dirent, readdirSync } from "fs"
import { rootPathPrefix } from "../constants/general.js"
import { NamespaceGenerateDetails } from "types"
import { capitalize, kebabToTitle } from "utils"
@@ -19,40 +19,50 @@ export function getCoreFlowNamespaces(): NamespaceGenerateDetails[] {
withFileTypes: true,
})
directories.forEach((directory) => {
if (!directory.isDirectory()) {
return
}
const namespaceName = kebabToTitle(directory.name)
const pathPattern = `**/packages/core/core-flows/src/${directory.name}/**`
const namespace: NamespaceGenerateDetails = {
name: namespaceName,
pathPattern,
children: [],
}
const subDirs = readdirSync(path.join(rootFlowsPath, directory.name), {
withFileTypes: true,
})
subDirs.forEach((dir) => {
if (
!dir.isDirectory() ||
(dir.name !== "workflows" && dir.name !== "steps")
) {
const loopDirectories = (dirs: Dirent[], parentDirs: string[] = []) => {
dirs.forEach((directory) => {
if (!directory.isDirectory()) {
return
}
namespace.children!.push({
name: `${capitalize(dir.name)}_${namespaceName}`,
pathPattern: `**/packages/core/core-flows/src/${directory.name}/${dir.name}`,
})
})
const namespaceName = kebabToTitle(directory.name)
const pathPatternPrefix = `**/packages/core/core-flows/src/${
parentDirs.length ? `${parentDirs.join("/")}/` : ""
}${directory.name}`
const pathPattern = `${pathPatternPrefix}/**`
namespaces.push(namespace)
})
const namespace: NamespaceGenerateDetails = {
name: namespaceName,
pathPattern,
children: [],
}
const subDirs = readdirSync(
path.join(rootFlowsPath, ...parentDirs, directory.name),
{
withFileTypes: true,
}
)
subDirs.forEach((dir) => {
if (
!dir.isDirectory() ||
(dir.name !== "workflows" && dir.name !== "steps")
) {
return
}
namespace.children!.push({
name: `${capitalize(dir.name)}_${namespaceName}`,
pathPattern: `${pathPatternPrefix}/${dir.name}/**`,
})
})
namespaces.push(namespace)
})
}
loopDirectories(directories)
return namespaces
}