-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs-util: generate examples for workflows and steps
- Loading branch information
1 parent
feb9810
commit a311b0d
Showing
14 changed files
with
531 additions
and
136 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
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, | ||
} | ||
)} | ||
\`\`\` | ||
` | ||
} |
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
Oops, something went wrong.