From cd0acbd9210a7de5237741fdc953adc6b6d5f12b Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 13 Aug 2024 15:30:55 +0300 Subject: [PATCH] docs: fixes and preparations for workflows reference (#8579) - Fix the merger configuration that adds the correct slug / sidebar labels - Add an overview page for the workflows reference. - Fixes to components and build scripts --- .../app/medusa-workflows-reference/page.mdx | 13 +++++++ www/apps/resources/generated/files-map.mjs | 4 ++ www/apps/resources/package.json | 5 +-- .../get-core-flows-ref-sidebar-children.ts | 4 ++ .../docs-ui/src/components/Card/index.tsx | 6 +-- .../src/components/ChildDocs/index.tsx | 33 +++++++++++++++- .../merger-custom-options/core-flows.ts | 39 +------------------ 7 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 www/apps/resources/app/medusa-workflows-reference/page.mdx diff --git a/www/apps/resources/app/medusa-workflows-reference/page.mdx b/www/apps/resources/app/medusa-workflows-reference/page.mdx new file mode 100644 index 0000000000..0b282d532b --- /dev/null +++ b/www/apps/resources/app/medusa-workflows-reference/page.mdx @@ -0,0 +1,13 @@ +import { ChildDocs } from "docs-ui" + +export const metadata = { + title: `Medusa Workflows Reference`, +} + +# {metadata.title} + +This section of the documentation provides a reference to the workflows created by Medusa. These workflows are used in the Store and Admin API routes. + +You can use these workflows in your customizations as well. They're available in the `@medusajs/core-flows` package. + + \ No newline at end of file diff --git a/www/apps/resources/generated/files-map.mjs b/www/apps/resources/generated/files-map.mjs index 1b6effefc7..99876c020f 100644 --- a/www/apps/resources/generated/files-map.mjs +++ b/www/apps/resources/generated/files-map.mjs @@ -683,6 +683,10 @@ export const filesMap = [ "filePath": "/www/apps/resources/app/medusa-container-resources/page.mdx", "pathname": "/medusa-container-resources" }, + { + "filePath": "/www/apps/resources/app/medusa-workflows-reference/page.mdx", + "pathname": "/medusa-workflows-reference" + }, { "filePath": "/www/apps/resources/app/nextjs-starter/page.mdx", "pathname": "/nextjs-starter" diff --git a/www/apps/resources/package.json b/www/apps/resources/package.json index 7168bacbc0..7cde5d5279 100644 --- a/www/apps/resources/package.json +++ b/www/apps/resources/package.json @@ -3,10 +3,9 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "yarn prep && next dev", - "dev:monorepo": "yarn prep && yarn dev -p 3003", + "dev": "next dev", + "dev:monorepo": "yarn dev -p 3003", "build": "next build", - "build:dev": "NODE_ENV=test yarn prep && yarn build", "start": "next start", "start:monorepo": "yarn start -p 3003", "lint": "next lint --fix", diff --git a/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts b/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts index dee20cdbd3..0ef99a1106 100644 --- a/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts +++ b/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts @@ -45,6 +45,10 @@ export default async function getCoreFlowsRefSidebarChildren(): Promise< const childDirPath = path.join(namespaceBasePath, childDir.name) const childFile = readdirSync(childDirPath) + if (!childFile.length) { + continue + } + const sidebarItem = await getSidebarItemLink({ filePath: path.join(childDirPath, childFile[0]), basePath: projPath, diff --git a/www/packages/docs-ui/src/components/Card/index.tsx b/www/packages/docs-ui/src/components/Card/index.tsx index 174ca5ddf2..7167d1ce3f 100644 --- a/www/packages/docs-ui/src/components/Card/index.tsx +++ b/www/packages/docs-ui/src/components/Card/index.tsx @@ -42,11 +42,11 @@ export const Card = ({ )} > {startIcon} -
-
+
+
{title && ( - + {title} {badge && } diff --git a/www/packages/docs-ui/src/components/ChildDocs/index.tsx b/www/packages/docs-ui/src/components/ChildDocs/index.tsx index e237852c48..ec33520709 100644 --- a/www/packages/docs-ui/src/components/ChildDocs/index.tsx +++ b/www/packages/docs-ui/src/components/ChildDocs/index.tsx @@ -10,6 +10,7 @@ type ChildDocsProps = { hideItems?: string[] showItems?: string[] hideTitle?: boolean + childLevel?: number } export const ChildDocs = ({ @@ -18,6 +19,7 @@ export const ChildDocs = ({ showItems, type = "sidebar", hideTitle = false, + childLevel = 1, }: ChildDocsProps) => { const { currentItems, getActiveItem } = useSidebar() const filterType = useMemo(() => { @@ -79,6 +81,32 @@ export const ChildDocs = ({ } }, [currentItems, type, getActiveItem, filterItems]) + const getChildrenForLevel = ( + item: SidebarItemType, + currentLevel = 1 + ): SidebarItemType[] | undefined => { + if (currentLevel === childLevel) { + return item.children + } + if (!item.children) { + return + } + + const childrenResult: SidebarItemType[] = [] + + item.children.forEach((child) => { + const childChildren = getChildrenForLevel(child, currentLevel + 1) + + if (!childChildren) { + return + } + + childrenResult.push(...childChildren) + }) + + return childrenResult + } + const getTopLevelElms = (items?: SidebarItemType[]) => ( items?.map((item, key) => { - const HeadingComponent = item.children?.length + const itemChildren = getChildrenForLevel(item) + const HeadingComponent = itemChildren?.length ? MDXComponents["h2"] : undefined @@ -104,7 +133,7 @@ export const ChildDocs = ({ {!hideTitle && {item.title}} ({ + itemChildren?.map((childItem) => ({ title: childItem.title, href: childItem.path, showLinkIcon: false, diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/core-flows.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/core-flows.ts index 3e36900b75..cd675aaebd 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/core-flows.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/core-flows.ts @@ -11,42 +11,7 @@ const coreFlowsOptions: FormattingOptionsType = { workflowDiagramComponent: "WorkflowDiagram", mdxImports: [`import { TypeList, WorkflowDiagram } from "docs-ui"`], }, - "^modules/core_flows/page\\.mdx": { - reflectionDescription: - "This section of the documentation provides a reference to Medusa's workflows and steps that you can use in your customizations.", - reflectionGroups: { - Namespaces: true, - Enumerations: false, - Classes: false, - Interfaces: false, - "Type Aliases": false, - Variables: false, - "Enumeration Members": false, - Functions: false, - }, - hideTocHeaders: true, - frontmatterData: { - slug: "/references/medusa-workflows", - }, - reflectionTitle: { - fullReplacement: "Medusa Workflows API Reference", - }, - }, - "^core_flows/.*/.*(Workflows|Steps)/page\\.mdx": { - expandMembers: false, - reflectionGroups: { - Variables: false, - Properties: false, - "Type Literals": false, - }, - sections: { - ...baseSectionsOptions, - member_getterSetter: false, - members_categories: false, - }, - hideTocHeaders: true, - }, - "^core_flows/.*Workflows/functions/.*/page\\.mdx": { + "^core_flows/.*/functions/.*Workflow/page\\.mdx": { reflectionDescription: "This documentation provides a reference to the `{{alias}}`. It belongs to the `@medusajs/core-flows` package.", frontmatterData: { @@ -59,7 +24,7 @@ const coreFlowsOptions: FormattingOptionsType = { suffix: "- Medusa Workflows API Reference", }, }, - "^core_flows/.*Steps/functions/.*/page\\.mdx": { + "^core_flows/.*/functions/.*Step/page\\.mdx": { reflectionDescription: "This documentation provides a reference to the `{{alias}}`. It belongs to the `@medusajs/core-flows` package.", frontmatterData: {