From 8fb1dc002805cda7bc36bfa93ae4fddf3238badb Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Wed, 25 Sep 2024 09:11:27 -0700 Subject: [PATCH 01/17] Replace {% stuff with Docusaurus stuff --- .../openrewrite/RecipeMarkdownGenerator.kt | 642 ++++++++---------- 1 file changed, 300 insertions(+), 342 deletions(-) diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index 9034fff..3706571 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -490,15 +490,15 @@ class RecipeMarkdownGenerator : Runnable { if (deployType == "snapshot") { changelog.appendText("# Snapshot ($formatted)") - changelog.appendText("\n\n{% hint style=\"info\" %}") + changelog.appendText("\n\n:::info") changelog.appendText("\nWant to learn how to use snapshot versions in your project? Check out our [snapshot version guide](/reference/snapshot-instructions.md).") - changelog.appendText("\n{% endhint %}\n\n") + changelog.appendText("\n:::\n\n") } else { changelog.appendText("# $rewriteBomVersion release ($formatted)") - changelog.appendText("\n\n{% hint style=\"info\" %}") + changelog.appendText("\n\n:::info") changelog.appendText("\nThis changelog only shows what recipes have been added, removed, or changed. OpenRewrite may do releases that do not include these types of changes. To see these changes, please go to the [releases page](https://github.com/openrewrite/rewrite/releases).") - changelog.appendText("\n{% endhint %}\n\n") + changelog.appendText("\n:::\n\n") } // An example of what the changelog could look like after the below statements can be found here: @@ -936,9 +936,9 @@ class RecipeMarkdownGenerator : Runnable { if (recipeDescriptor.recipeList.size > 1) { writeln( """ - {% hint style="info" %} + :::info This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above. - {% endhint %} + ::: """.trimIndent() ) } @@ -1092,8 +1092,8 @@ class RecipeMarkdownGenerator : Runnable { if (hasChange && source.before != null) { newLine() val tabName = source.path ?: (source.language ?: "Before / After") - writeln("{% tabs %}") - writeln("{% tab title=\"${tabName}\" %}") + writeln("") + writeln(" ") } newLine() @@ -1102,19 +1102,16 @@ class RecipeMarkdownGenerator : Runnable { writeln("###### $beforeTitle") if (source.path != null) { - writeln("{% code title=\"${source.path}\" %}") + writeln("```${source.language} title=\"${source.path}\"") } else { - writeln("{% code %}") + writeln("```${source.language}") } - writeln("```${source.language}") write(source.before) if (source.before != null && !source.before.endsWith("\n")) { newLine() } writeln("```") - - writeln("{% endcode %}") } if (hasChange) { @@ -1122,38 +1119,34 @@ class RecipeMarkdownGenerator : Runnable { writeln("###### $afterTile") if (source.path != null) { - writeln("{% code title=\"${source.path}\" %}") + writeln("```${source.language} title=\"${source.path}\"") } else { - writeln("{% code %}") + writeln("```${source.language}") } - writeln("```${source.language}") write(source.after) if (source.after != null && !source.after.endsWith("\n")) { newLine() } writeln("```") - writeln("{% endcode %}") newLine() // diff if (source.before != null) { - writeln("{% endtab %}") - writeln("{% tab title=\"Diff\" %}") + writeln(" ") + writeln("") val diff = generateDiff(source.path, source.before, source.after) - writeln("{% code %}") writeln( """ |```diff |${diff}``` """.trimMargin() ) - writeln("{% endcode %}") - writeln("{% endtab %}") - writeln("{% endtabs %}") + writeln(" ") + writeln("") } } } @@ -1197,9 +1190,7 @@ class RecipeMarkdownGenerator : Runnable { writeln("Here's how you can define and customize such a recipe within your rewrite.yml:") write( """ - - {% code title="rewrite.yml" %} - ```yaml + ```yaml title="rewrite.yml" --- type: specs.openrewrite.org/v1beta/recipe name: $exampleRecipeName @@ -1226,7 +1217,6 @@ class RecipeMarkdownGenerator : Runnable { writeln(" ${option.name}: $ex") } writeln("```") - writeln("{% endcode %}") newLine() if (requiresDependency) { @@ -1286,8 +1276,8 @@ class RecipeMarkdownGenerator : Runnable { ## Definition - {% tabs %} - {% tab title="Recipe List" %} + + """.trimIndent() ) val recipeDepth = getRecipePath(recipeDescriptor).chars().filter { ch: Int -> ch == '/'.code }.count() @@ -1314,9 +1304,9 @@ class RecipeMarkdownGenerator : Runnable { newLine() writeln( """ - {% endtab %} + - {% tab title="Yaml Recipe List" %} + ```yaml """.trimIndent() ) @@ -1324,8 +1314,8 @@ class RecipeMarkdownGenerator : Runnable { writeln( """ ``` - {% endtab %} - {% endtabs %} + + """.trimIndent() ) } @@ -1420,15 +1410,13 @@ class RecipeMarkdownGenerator : Runnable { } return """ - {% tab title="Moderne CLI" %} - You will need to have configured the [Moderne CLI](https://docs.moderne.io/moderne-cli/cli-intro) on your machine before you can run the following command. - - {% code title="shell" %} - ```shell - mod run . --recipe $trimmedRecipeName - ``` - {% endcode %} - {% endtab %} + + You will need to have configured the [Moderne CLI](https://docs.moderne.io/moderne-cli/cli-intro) on your machine before you can run the following command. + + ```shell title="shell" + mod run . --recipe $trimmedRecipeName + ``` + """.trimIndent() } @@ -1442,64 +1430,60 @@ class RecipeMarkdownGenerator : Runnable { dataTableSnippet: String, ) { val gradleSnippet = if (suppressGradle) "" else """ - {% tab title="Gradle" %} - 1. Add the following to your `build.gradle` file: - {% code title="build.gradle" %} - ```groovy - plugins { - id("org.openrewrite.rewrite") version("$gradlePluginVersion") - } - - rewrite { - activeRecipe("$exampleRecipeName") - exportDatatables = true - } - - repositories { - mavenCentral() - } - ``` - {% endcode %} - 2. Run `gradle rewriteRun` to run the recipe. - {% endtab %} + + 1. Add the following to your `build.gradle` file: + ```groovy title="build.gradle" + plugins { + id("org.openrewrite.rewrite") version("$gradlePluginVersion") + } + + rewrite { + activeRecipe("$exampleRecipeName") + exportDatatables = true + } + + repositories { + mavenCentral() + } + ``` + 2. Run `gradle rewriteRun` to run the recipe. + """.trimIndent() val mavenSnippet = if (suppressMaven) "" else """ - {% tab title="Maven" %} - 1. Add the following to your `pom.xml` file: - {% code title="pom.xml" %} - ```xml - - - - - org.openrewrite.maven - rewrite-maven-plugin - $mavenPluginVersion - - $dataTableSnippet - - $exampleRecipeName - - - - - - - ``` - {% endcode %} - 2. Run `mvn rewrite:run` to run the recipe. - {% endtab %} + + 1. Add the following to your `pom.xml` file: + ```xml title="pom.xml" + + + + + org.openrewrite.maven + rewrite-maven-plugin + $mavenPluginVersion + + $dataTableSnippet + + $exampleRecipeName + + + + + + + ``` + 2. Run `mvn rewrite:run` to run the recipe. + """.trimIndent() writeln( """ Now that `$exampleRecipeName` has been defined, activate it in your build file: -{% tabs %} -$gradleSnippet -$mavenSnippet -$cliSnippet -{% endtabs %} + + $gradleSnippet + $mavenSnippet + $cliSnippet + """.trimIndent() ) } @@ -1515,75 +1499,71 @@ $cliSnippet dataTableSnippet: String, ) { val gradleSnippet = if (suppressGradle) "" else """ - {% tab title="Gradle" %} - 1. Add the following to your `build.gradle` file: - {% code title="build.gradle" %} - ```groovy - plugins { - id("org.openrewrite.rewrite") version("$gradlePluginVersion") - } - - rewrite { - activeRecipe("$exampleRecipeName") - exportDatatables = true - } - - repositories { - mavenCentral() - } - - dependencies { - rewrite("${origin.groupId}:${origin.artifactId}:${origin.version}") - } - ``` - {% endcode %} - 2. Run `gradle rewriteRun` to run the recipe. - {% endtab %} + + 1. Add the following to your `build.gradle` file: + ```groovy title="build.gradle" + plugins { + id("org.openrewrite.rewrite") version("$gradlePluginVersion") + } + + rewrite { + activeRecipe("$exampleRecipeName") + exportDatatables = true + } + + repositories { + mavenCentral() + } + + dependencies { + rewrite("${origin.groupId}:${origin.artifactId}:${origin.version}") + } + ``` + 2. Run `gradle rewriteRun` to run the recipe. + """.trimIndent() val mavenSnippet = if (suppressMaven) "" else """ - {% tab title="Maven" %} - 1. Add the following to your `pom.xml` file: - {% code title="pom.xml" %} - ```xml - - - - - org.openrewrite.maven - rewrite-maven-plugin - $mavenPluginVersion - - $dataTableSnippet - - $exampleRecipeName - - - - - ${origin.groupId} - ${origin.artifactId} - ${origin.version} - - - - - - - ``` - {% endcode %} - 2. Run `mvn rewrite:run` to run the recipe. - {% endtab %} + + 1. Add the following to your `pom.xml` file: + ```xml title="pom.xml" + + + + + org.openrewrite.maven + rewrite-maven-plugin + $mavenPluginVersion + + $dataTableSnippet + + $exampleRecipeName + + + + + ${origin.groupId} + ${origin.artifactId} + ${origin.version} + + + + + + + ``` + 2. Run `mvn rewrite:run` to run the recipe. + """.trimIndent() writeln( """ Now that `$exampleRecipeName` has been defined, activate it and take a dependency on ${origin.groupId}:${origin.artifactId}:${origin.version} in your build file: -{% tabs %} -$gradleSnippet -$mavenSnippet -$cliSnippet -{% endtabs %} + + $gradleSnippet + $mavenSnippet + $cliSnippet + """.trimIndent() ) } @@ -1604,111 +1584,100 @@ $cliSnippet ) val gradleSnippet = if (suppressGradle) "" else """ - {% tab title="Gradle" %} - 1. Add the following to your `build.gradle` file: - {% code title="build.gradle" %} - ```groovy - plugins { - id("org.openrewrite.rewrite") version("$gradlePluginVersion") - } - - rewrite { - activeRecipe("${recipeDescriptor.name}") - exportDatatables = true - } - - repositories { - mavenCentral() - } - - ``` - {% endcode %} - 2. Run `gradle rewriteRun` to run the recipe. - {% endtab %} - - {% tab title="Gradle init script" %} - 1. Create a file named `init.gradle` in the root of your project. - {% code title="init.gradle" %} - ```groovy - initscript { - repositories { - maven { url "https://plugins.gradle.org/m2" } - } - dependencies { classpath("org.openrewrite:plugin:latest.release") } - } - rootProject { - plugins.apply(org.openrewrite.gradle.RewritePlugin) - dependencies { - rewrite("org.openrewrite:rewrite-java") + + 1. Add the following to your `build.gradle` file: + ```groovy title="build.gradle" + plugins { + id("org.openrewrite.rewrite") version("$gradlePluginVersion") } + rewrite { activeRecipe("${recipeDescriptor.name}") exportDatatables = true } - afterEvaluate { - if (repositories.isEmpty()) { - repositories { - mavenCentral() + + repositories { + mavenCentral() + } + + ``` + 2. Run `gradle rewriteRun` to run the recipe. + + + + 1. Create a file named `init.gradle` in the root of your project. + ```groovy title="init.gradle" + initscript { + repositories { + maven { url "https://plugins.gradle.org/m2" } + } + dependencies { classpath("org.openrewrite:plugin:latest.release") } + } + rootProject { + plugins.apply(org.openrewrite.gradle.RewritePlugin) + dependencies { + rewrite("org.openrewrite:rewrite-java") + } + rewrite { + activeRecipe("${recipeDescriptor.name}") + exportDatatables = true + } + afterEvaluate { + if (repositories.isEmpty()) { + repositories { + mavenCentral() + } } } } - } - ``` - {% endcode %} - 2. Run the recipe. - {% code title="shell" overflow="wrap"%} - ```shell - gradle --init-script init.gradle rewriteRun - ``` - {% endcode %} - {% endtab %} + ``` + 2. Run the recipe. + ```shell title="shell" + gradle --init-script init.gradle rewriteRun + ``` + """.trimIndent() val mavenSnippet = if (suppressMaven) "" else """ - {% tab title="Maven POM" %} - 1. Add the following to your `pom.xml` file: - {% code title="pom.xml" %} - ```xml - - - - - org.openrewrite.maven - rewrite-maven-plugin - $mavenPluginVersion - - $dataTableSnippet - - ${recipeDescriptor.name} - - - - - - - ``` - {% endcode %} - 2. Run `mvn rewrite:run` to run the recipe. - {% endtab %} + + 1. Add the following to your `pom.xml` file: + ```xml title="pom.xml" + + + + + org.openrewrite.maven + rewrite-maven-plugin + $mavenPluginVersion + + $dataTableSnippet + + ${recipeDescriptor.name} + + + + + + + ``` + 2. Run `mvn rewrite:run` to run the recipe. + - {% tab title="Maven Command Line" %} - - You will need to have [Maven](https://maven.apache.org/download.cgi) installed on your machine before you can run the following command. - - {% code title="shell" overflow="wrap"%} - ```shell - mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=${recipeDescriptor.name} $dataTableCommandLineSnippet - ``` - {% endcode %} - {% endtab %} + + You will need to have [Maven](https://maven.apache.org/download.cgi) installed on your machine before you can run the following command. + + ```shell title="shell" + mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=${recipeDescriptor.name} $dataTableCommandLineSnippet + ``` + """.trimIndent() writeln( """ -{% tabs %} -$gradleSnippet -$mavenSnippet -$cliSnippet -{% endtabs %} + + $gradleSnippet + $mavenSnippet + $cliSnippet + """.trimIndent() ) } @@ -1731,122 +1700,111 @@ $cliSnippet ) val gradleSnippet = if (suppressGradle) "" else """ - {% tab title="Gradle" %} - 1. Add the following to your `build.gradle` file: - {% code title="build.gradle" %} - ```groovy - plugins { - id("org.openrewrite.rewrite") version("$gradlePluginVersion") - } - - rewrite { - activeRecipe("${recipeDescriptor.name}") - exportDatatables = true - } - - repositories { - mavenCentral() - } - - dependencies { - rewrite("${origin.groupId}:${origin.artifactId}:${origin.version}") - } - ``` - {% endcode %} - 2. Run `gradle rewriteRun` to run the recipe. - {% endtab %} - - {% tab title="Gradle init script" %} - 1. Create a file named `init.gradle` in the root of your project. - {% code title="init.gradle" %} - ```groovy - initscript { + + 1. Add the following to your `build.gradle` file: + ```groovy title="build.gradle" + plugins { + id("org.openrewrite.rewrite") version("$gradlePluginVersion") + } + + rewrite { + activeRecipe("${recipeDescriptor.name}") + exportDatatables = true + } + repositories { - maven { url "https://plugins.gradle.org/m2" } + mavenCentral() } - dependencies { classpath("org.openrewrite:plugin:${gradlePluginVersion}") } - } - rootProject { - plugins.apply(org.openrewrite.gradle.RewritePlugin) + dependencies { rewrite("${origin.groupId}:${origin.artifactId}:${origin.version}") } - rewrite { - activeRecipe("${recipeDescriptor.name}") - exportDatatables = true + ``` + 2. Run `gradle rewriteRun` to run the recipe. + + + + 1. Create a file named `init.gradle` in the root of your project. + ```groovy title="init.gradle" + initscript { + repositories { + maven { url "https://plugins.gradle.org/m2" } + } + dependencies { classpath("org.openrewrite:plugin:${gradlePluginVersion}") } } - afterEvaluate { - if (repositories.isEmpty()) { - repositories { - mavenCentral() + rootProject { + plugins.apply(org.openrewrite.gradle.RewritePlugin) + dependencies { + rewrite("${origin.groupId}:${origin.artifactId}:${origin.version}") + } + rewrite { + activeRecipe("${recipeDescriptor.name}") + exportDatatables = true + } + afterEvaluate { + if (repositories.isEmpty()) { + repositories { + mavenCentral() + } } } } - } - ``` - {% endcode %} - 2. Run the recipe. - {% code title="shell" overflow="wrap"%} - ```shell - gradle --init-script init.gradle rewriteRun - ``` - {% endcode %} - {% endtab %} + ``` + 2. Run the recipe. + ```shell title="shell" + gradle --init-script init.gradle rewriteRun + ``` + """.trimIndent() val mavenSnippet = if (suppressMaven) "" else """ - {% tab title="Maven POM" %} - 1. Add the following to your `pom.xml` file: - {% code title="pom.xml" %} - ```xml - - - - - org.openrewrite.maven - rewrite-maven-plugin - $mavenPluginVersion - - $dataTableSnippet - - ${recipeDescriptor.name} - - - - - ${origin.groupId} - ${origin.artifactId} - ${origin.version} - - - - - - - ``` - {% endcode %} - 2. Run `mvn rewrite:run` to run the recipe. - {% endtab %} + + 1. Add the following to your `pom.xml` file: + ```xml title="pom.xml" + + + + + org.openrewrite.maven + rewrite-maven-plugin + $mavenPluginVersion + + $dataTableSnippet + + ${recipeDescriptor.name} + + + + + ${origin.groupId} + ${origin.artifactId} + ${origin.version} + + + + + + + ``` + 2. Run `mvn rewrite:run` to run the recipe. + - {% tab title="Maven Command Line" %} - - You will need to have [Maven](https://maven.apache.org/download.cgi) installed on your machine before you can run the following command. - - {% code title="shell" overflow="wrap" %} - ```shell - mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=${origin.groupId}:${origin.artifactId}:RELEASE -Drewrite.activeRecipes=${recipeDescriptor.name} $dataTableCommandLineSnippet - ``` - {% endcode %} - {% endtab %} + + You will need to have [Maven](https://maven.apache.org/download.cgi) installed on your machine before you can run the following command. + + ```shell title="shell" + mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=${origin.groupId}:${origin.artifactId}:RELEASE -Drewrite.activeRecipes=${recipeDescriptor.name} $dataTableCommandLineSnippet + ``` + """.trimIndent() writeln( """ -{% tabs %} -$gradleSnippet -$mavenSnippet -$cliSnippet -{% endtabs %} + + $gradleSnippet + $mavenSnippet + $cliSnippet + """.trimIndent() ) } From 4787c38c2d8335fb082edc5d6df8403f91244cab Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Thu, 26 Sep 2024 09:04:36 -0700 Subject: [PATCH 02/17] Saving fixes --- .../openrewrite/RecipeMarkdownGenerator.kt | 180 ++++++------------ 1 file changed, 62 insertions(+), 118 deletions(-) diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index 3706571..8790563 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -104,7 +104,7 @@ class RecipeMarkdownGenerator : Runnable { override fun run() { val outputPath = Paths.get(destinationDirectoryName) - val recipesPath = outputPath.resolve("reference/recipes") + val recipesPath = outputPath.resolve("recipes") try { Files.createDirectories(recipesPath) } catch (e: IOException) { @@ -321,18 +321,6 @@ class RecipeMarkdownGenerator : Runnable { val categories = Category.fromDescriptors(recipeDescriptors, categoryDescriptors).sortedBy { it.simpleName } - // Write SUMMARY_snippet.md - val summarySnippetPath = outputPath.resolve("SUMMARY_snippet.md") - Files.newBufferedWriter(summarySnippetPath, StandardOpenOption.CREATE).useAndApply { - for (category in categories) { - write(category.summarySnippet(0)) - } - write(""" - * [Changelog](changelog/changelog.md) - * [$rewriteBomVersion Release (${getDateFormattedYYYYMMDD()})](/changelog/${rewriteBomVersion.replace('.','-')}-Release.md) - """.trimIndent()) - } - // Write recipes-with-data-tables.md val recipesWithDataTablesPath = outputPath.resolve("recipes-with-data-tables.md") Files.newBufferedWriter(recipesWithDataTablesPath, StandardOpenOption.CREATE).useAndApply { @@ -361,7 +349,7 @@ class RecipeMarkdownGenerator : Runnable { // Write the README.md for each category for (category in categories) { - val categoryIndexPath = outputPath.resolve("reference/recipes/") + val categoryIndexPath = outputPath.resolve("/recipes/") category.writeCategoryIndex(categoryIndexPath) } } @@ -706,49 +694,6 @@ class RecipeMarkdownGenerator : Runnable { descriptor.displayName.replace("`", "") } - /** - * Produce the snippet for this category to be fitted into Gitbook's SUMMARY.md, which provides the index - * that makes markdown documents accessible through gitbook's interface - */ - fun summarySnippet(indentationDepth: Int): String { - val indentBuilder = StringBuilder(" ") - for (i in 0 until indentationDepth) { - indentBuilder.append(" ") - } - val indent = indentBuilder.toString() - val result = StringBuilder() - - if (path == "") { - // Recipes that don't have a path are part of the "core" set of recipes - result.appendLine("$indent* [Core](reference/recipes/core.md)") - } else { - // Some nested recipes have a `github` path which gets converted into `Github` when it should be `GitHub`. - if (displayName == "Github") { - displayName = "GitHub" - } - - result.appendLine("$indent* [$displayName](reference/recipes/$path/README.md)") - } - - for (recipe in recipes) { - // Section headings will display backticks, rather than rendering as code. Omit them so it doesn't look terrible - result.appendLine( - "$indent * [${ - recipe.displayName.replace( - "`", - "" - ) - }](${getRecipeRelativePath(recipe)}.md)" - ) - } - - for (category in subcategories.sortedBy { it.simpleName }) { - result.append(category.summarySnippet(indentationDepth + 1)) - } - - return result.toString() - } - /** * Produce the contents of the README.md file for this category. */ @@ -771,7 +716,7 @@ class RecipeMarkdownGenerator : Runnable { appendLine("## Categories") appendLine() for (subcategory in subcategories) { - appendLine("* [${subcategory.displayName}](/reference/recipes/${subcategory.path})") + appendLine("* [${subcategory.displayName}](/recipes/${subcategory.path})") } appendLine() } @@ -844,13 +789,6 @@ class RecipeMarkdownGenerator : Runnable { } } - // Also need to make an empty README for GitBook linking - val emptyReadmePath = outputRoot.resolve("README.md") - - Files.newBufferedWriter(emptyReadmePath, StandardOpenOption.CREATE).useAndApply { - writeln("# Recipes") - } - return } val outputPath = outputRoot.resolve("$path/README.md") @@ -875,9 +813,16 @@ class RecipeMarkdownGenerator : Runnable { Files.newBufferedWriter(recipeMarkdownPath, StandardOpenOption.CREATE).useAndApply { write( """ - # ${recipeDescriptor.displayName} + --- + sidebar_label: "${recipeDescriptor.displayName.replace("`","").replace("\"", "\\\"").replace("