-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs-util: add examples generator for workflows and steps (#10914)
* initial changes * docs-util: generate examples for workflows and steps
- Loading branch information
1 parent
e82645b
commit c591545
Showing
17 changed files
with
810 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
www/utils/packages/typedoc-plugin-markdown-medusa/src/resources/helpers/step-examples.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Handlebars from "handlebars" | ||
import { DeclarationReflection, SignatureReflection } from "typedoc" | ||
import { getReflectionTypeFakeValueStr, getStepInputType } from "utils" | ||
import pkg from "js-beautify" | ||
|
||
const { js_beautify } = pkg | ||
|
||
export default function () { | ||
Handlebars.registerHelper( | ||
"stepExamples", | ||
function (this: SignatureReflection): string { | ||
const stepReflection = this.parent | ||
|
||
const exampleTags = stepReflection.comment?.blockTags.filter( | ||
(tag) => tag.tag === "@example" | ||
) | ||
|
||
if (exampleTags?.length) { | ||
return Handlebars.helpers.example(stepReflection) | ||
} | ||
|
||
return generateStepExample(stepReflection) | ||
} | ||
) | ||
} | ||
|
||
function generateStepExample(stepReflection: DeclarationReflection): string { | ||
if (!stepReflection.signatures?.length) { | ||
return "" | ||
} | ||
const inputType = getStepInputType(stepReflection.signatures[0]) | ||
const inputStr = inputType | ||
? `${getReflectionTypeFakeValueStr({ | ||
reflectionType: inputType, | ||
name: "", | ||
})}` | ||
: "" | ||
|
||
// generate example | ||
return ` | ||
\`\`\`ts title="src/workflows/my-workflow.ts" | ||
${js_beautify( | ||
`import { createWorkflow } from "@medusajs/framework/workflows-sdk" | ||
import { ${stepReflection.name} } from "@medusajs/medusa/core-flows" | ||
const myWorkflow = createWorkflow( | ||
"my-workflow", | ||
() => { | ||
const data = ${stepReflection.name}(${inputStr}) | ||
} | ||
)`, | ||
{ | ||
indent_size: 2, | ||
brace_style: "preserve-inline", | ||
wrap_line_length: 80, | ||
} | ||
)} | ||
\`\`\` | ||
` | ||
} |
Oops, something went wrong.