From a9d28b1f091ee2c5b8c7ad0087496b6ac6c82b11 Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Wed, 18 Dec 2024 12:11:15 -0800 Subject: [PATCH] Create a doc with Moderne recipes (#149) * Create a doc with Moderne recipes * Sort by display name * Add link to Moderne stuff --------- Co-authored-by: Mike Solomon --- .../openrewrite/RecipeMarkdownGenerator.kt | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index 16cc1c0..cb01b27 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -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 } @@ -163,8 +164,8 @@ class RecipeMarkdownGenerator : Runnable { val recipeDescriptors: Collection = env.listRecipeDescriptors() val categoryDescriptors = ArrayList(env.listCategoryDescriptors()) val markdownArtifacts = TreeMap() - val recipesWithDataTables = ArrayList(); + val moderneProprietaryRecipes = TreeMap>() // Create the recipe docs for (recipeDescriptor in recipeDescriptors) { @@ -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() for (recipeOption in recipeDescriptor.options) { val name = recipeOption.name as String @@ -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() @@ -434,6 +442,49 @@ class RecipeMarkdownGenerator : Runnable { } } + private fun createModerneRecipes( + outputPath: Path, + moderneProprietaryRecipesMap: TreeMap> + ) { + 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("