Skip to content

Commit

Permalink
Create a doc with Moderne recipes (#149)
Browse files Browse the repository at this point in the history
* Create a doc with Moderne recipes

* Sort by display name

* Add link to Moderne stuff

---------

Co-authored-by: Mike Solomon <[email protected]>
  • Loading branch information
mike-solomon and mike-solomon authored Dec 18, 2024
1 parent 4800b5c commit a9d28b1
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class RecipeMarkdownGenerator : Runnable {
// Write latest-versions-of-every-openrewrite-module.md
createLatestVersionsJs(outputPath, recipeOrigins)
createLatestVersionsMarkdown(outputPath, recipeOrigins)

if (recipeClasspath.isEmpty()) {
return
}
Expand Down Expand Up @@ -163,8 +164,8 @@ class RecipeMarkdownGenerator : Runnable {
val recipeDescriptors: Collection<RecipeDescriptor> = env.listRecipeDescriptors()
val categoryDescriptors = ArrayList(env.listCategoryDescriptors())
val markdownArtifacts = TreeMap<String, MarkdownRecipeArtifact>()

val recipesWithDataTables = ArrayList<RecipeDescriptor>();
val moderneProprietaryRecipes = TreeMap<String, MutableList<RecipeDescriptor>>()

// Create the recipe docs
for (recipeDescriptor in recipeDescriptors) {
Expand Down Expand Up @@ -193,6 +194,10 @@ class RecipeMarkdownGenerator : Runnable {
recipesWithDataTables.add(recipeDescriptor);
}

if (getLicense(origin) == License.Proprietary) {
moderneProprietaryRecipes.computeIfAbsent(origin.artifactId) { mutableListOf() }.add(recipeDescriptor)
}

val recipeOptions = TreeSet<RecipeOption>()
for (recipeOption in recipeDescriptor.options) {
val name = recipeOption.name as String
Expand Down Expand Up @@ -260,6 +265,9 @@ class RecipeMarkdownGenerator : Runnable {
markdownArtifact.markdownRecipeDescriptors[recipeDescriptor.name] = markdownRecipeDescriptor
}

// Create moderne-recipes.md
createModerneRecipes(outputPath, moderneProprietaryRecipes)

val mapper = ObjectMapper(YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER))
mapper.registerKotlinModule()

Expand Down Expand Up @@ -434,6 +442,49 @@ class RecipeMarkdownGenerator : Runnable {
}
}

private fun createModerneRecipes(
outputPath: Path,
moderneProprietaryRecipesMap: TreeMap<String, MutableList<RecipeDescriptor>>
) {
val moderneRecipesPath = outputPath.resolve("moderne-recipes.md")

Files.newBufferedWriter(moderneRecipesPath, StandardOpenOption.CREATE).useAndApply {
writeln("# Moderne Recipes\n")

writeln("This doc includes every recipe that is exclusive to Moderne customers. " +
"For a full list of all recipes, check out our [recipe catalog](https://docs.openrewrite.org/recipes). " +
"For more information about how to use Moderne for automating code refactoring and analysis at scale, " +
"[contact us](https://www.moderne.ai/contact-us).\n")

for (entry in moderneProprietaryRecipesMap) {
// Artifact ID
writeln("## ${entry.key}\n")

val sortedEntries = entry.value.sortedBy { it.displayName }

for (recipe in sortedEntries) {
var recipePath = ""

if (recipe.name.count { it == '.' } == 2 &&
recipe.name.contains("org.openrewrite.")) {
recipePath = "recipes/core/" + recipe.name.removePrefix("org.openrewrite.").lowercase()
} else if (recipe.name.contains("io.moderne.ai")) {
recipePath = "recipes/ai/" + recipe.name.removePrefix("io.moderne.ai.").replace(".", "/").lowercase()
} else {
recipePath = "recipes/" + recipe.name.removePrefix("org.openrewrite.").replace(".", "/").lowercase()
}

val formattedDisplayName = recipe.displayName
.replace("<script>", "`<script>`")

writeln("* [${formattedDisplayName}](../${recipePath})")
}

writeln("")
}
}
}

private fun getNewArtifacts(
markdownArtifacts: TreeMap<String, MarkdownRecipeArtifact>,
oldArtifacts: TreeMap<String, MarkdownRecipeArtifact>,
Expand Down

0 comments on commit a9d28b1

Please sign in to comment.