Commit f360430
authored
Emit component-based recipe MDX for Moderne docs (forModerneDocs path) (#344)
* Emit component-based recipe MDX for Moderne docs (forModerneDocs path)
When forModerneDocs is true, RecipeMarkdownWriter now emits MDX that renders the
new moderne-docs recipe-detail React components instead of raw markdown:
hide_title frontmatter (no H1), a component import, <RecipeMeta>/<RecipeHeader>,
and <RecipeList>/<OptionsTable>/<ExampleList>/<UsageList>/<DataTableList> with
each section's `## ` heading passed as a blank-line-wrapped children slot (so the
native Docusaurus TOC + anchor IDs are preserved). Section data is serialized to
inline JSON props via Jackson, matching the components' TypeScript prop shapes.
The OpenRewrite docs path (forModerneDocs = false) is untouched.
Adds RecipeMarkdownWriterModerneDocsTest covering both paths (constructs
descriptors directly, so it doesn't require recipe loading).
Implements #343.
* Simplify component-MDX emitter (output-preserving)
- Collapse the five repetitive section blocks into an emitSection() helper.
- Build each section's JSON prop lazily, only when that section is emitted.
- Extract the per-option CLI example formatting shared by writeUsage and
buildUsageJson into cliOptionExample(); compile its regexes once as constants.
- Minor: inline the one-line license helper, drop the fqName/language aliases
and a redundant guard, hoist the duplicated getRecipePath call.
- Test: extract a shared descriptor() fixture builder.
Verified byte-identical emitted MDX (both the Moderne and OpenRewrite paths)
before and after; full test suite passes.
* Emit preconditions on RecipeList (match moderne-docs component change)
moderne-docs PR #794 (Jayd's feedback iteration) gave RecipeList a `preconditions`
prop and folded preconditions into the Definition section. Feed them through:
- Emit `<RecipeList recipes={…} preconditions={…}>` using the recipe's
`preconditions` (mapped to {name, href} like the sub-recipe list).
- Emit the Definition section when there are preconditions OR a recipe list (a
single recipe can have preconditions without a recipe list).
- Refactor the {name, href} mapping into a shared `subRecipeJson(recipes)` used
for both props.
Verified end-to-end: generator-emitted MDX renders through the merged moderne-docs
components — preconditions show with their violet count badge, TOC + copy button intact.
* Simplify component-MDX emitter (output-preserving)
- Move the Jackson mapper to the companion object (one stateless instance).
- subRecipeJson: single recipeToSource lookup instead of containsKey + get.
- Build the RecipeList preconditions attribute with takeIf/let instead of a
boolean + conditional concat.
- buildUsageJson: build cliOptions with filter+joinToString instead of a
mutating loop.
- Delete the now-dead canonicalHead block in writeRecipeToPath (always "" after
the forModerneDocs early-return; the Moderne canonical link is emitted by
writeModerneComponentRecipe).
- Note why Definition isn't license-gated for Moderne docs.
- Test: inline the single-use writer() helper.
Verified: full test suite passes; emitted MDX + the OpenRewrite path are unchanged.
* Address review: bellwether filter + JS/Python/C# usage
- Filter internal "Precondition bellwether" recipes out of the RecipeList
recipes/preconditions JSON, matching the markdown path (rewrite-docs#250).
- Emit a UsageList for JS/Python/C# recipes with the right package manager
(npm/pip/nuget) instead of skipping them; buildUsageJson now branches per
ecosystem like the markdown path's <RunRecipe>.
- Reword the buildExamplesJson comment; document that per-example descriptions
are intentionally omitted (the redesigned ExampleList has no description field).
- Tests: assert bellwethers are filtered and JS recipes get an npm UsageList.1 parent e0e1b19 commit f360430
2 files changed
Lines changed: 504 additions & 25 deletions
File tree
- src
- main/kotlin/org/openrewrite
- test/kotlin/org/openrewrite
0 commit comments