diff --git a/README.md b/README.md index cffb484..38e3346 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,11 @@ Quickstart: ./gradlew run ``` +### Create only latest versions files in `build/docs` +```shell +./gradlew latestVersionsMarkdown +``` + ### Create Markdown files in a specific directory ```shell ./gradlew run --args="desired/output/path" @@ -77,6 +82,7 @@ Assumes you have `rewrite-docs` checked out in the same directory as `rewrite-re rm -rf ../rewrite-docs/docs/recipes/ cp -r build/docs/recipes ../rewrite-docs/docs/recipes cp -r build/docs/*.md ../rewrite-docs/docs/reference/ +cp -r build/docs/*.js ../rewrite-docs/src/plugins/ cp src/main/resources/8-*-Release.md ../rewrite-docs/docs/changelog/ ``` diff --git a/build.gradle.kts b/build.gradle.kts index 157bc6f..6b24035 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -73,6 +73,7 @@ dependencies { "recipe"("org.openrewrite:rewrite-kotlin") // "recipe"("org.openrewrite:rewrite-python") // Removed based on Olga request // "recipe"("org.openrewrite:rewrite-ruby") + "recipe"("org.openrewrite:rewrite-templating") // To show in latest versions "recipe"("org.openrewrite.recipe:rewrite-all") "recipe"("org.openrewrite.meta:rewrite-analysis") diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index 37df920..347554a 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -118,7 +118,8 @@ class RecipeMarkdownGenerator : Runnable { recipeOrigins = RecipeOrigin.parse(recipeSources) // Write latest-versions-of-every-openrewrite-module.md - createLatestVersionsFile(outputPath, recipeOrigins) + createLatestVersionsJs(outputPath, recipeOrigins) + createLatestVersionsMarkdown(outputPath, recipeOrigins) if (recipeClasspath.isEmpty()) { return } @@ -349,7 +350,7 @@ class RecipeMarkdownGenerator : Runnable { } } - private fun createLatestVersionsFile( + private fun createLatestVersionsMarkdown( outputPath: Path, recipeOrigins: Map ) { @@ -404,6 +405,32 @@ class RecipeMarkdownGenerator : Runnable { } } + private fun createLatestVersionsJs( + outputPath: Path, + recipeOrigins: Map + ) { + val versionsSnippetPath = outputPath.resolve("latest-versions.js") + Files.newBufferedWriter(versionsSnippetPath, StandardOpenOption.CREATE).useAndApply { + var recipeModuleVersions = "" + for (origin in recipeOrigins.values) { + val key = origin.artifactId.uppercase().replace('-', '_') + recipeModuleVersions += " \"{{VERSION_$key}}\": \"${origin.version}\",\n" + } + writeln( + //language=ts + """ + const latestVersions = { + "{{VERSION_REWRITE_RECIPE_BOM}}": "${rewriteRecipeBomVersion}", + "{{VERSION_REWRITE_GRADLE_PLUGIN}}": "${gradlePluginVersion}", + "{{VERSION_REWRITE_MAVEN_PLUGIN}}": "${mavenPluginVersion}", + ${recipeModuleVersions.trim()} + }; + export default latestVersions; + """.trimIndent() + ) + } + } + private fun getNewArtifacts( markdownArtifacts: TreeMap, oldArtifacts: TreeMap, @@ -934,7 +961,7 @@ class RecipeMarkdownGenerator : Runnable { Files.createDirectories(recipeMarkdownPath.parent) Files.newBufferedWriter(recipeMarkdownPath, StandardOpenOption.CREATE).useAndApply { write( -""" + """ --- sidebar_label: "$sidebarFormattedName" --- @@ -1985,8 +2012,8 @@ $cliSnippet ) private fun getRecipePath(recipe: RecipeDescriptor): String = - // Docusaurus expects that if a file is called "assertj" inside of the folder "assertj" that it's the - // README for said folder. Due to how generic we've made this recipe name, we need to change it for the + // Docusaurus expects that if a file is called "assertj" inside of the folder "assertj" that it's the + // README for said folder. Due to how generic we've made this recipe name, we need to change it for the // docs so that they parse correctly. if (recipePathToDocusaurusRenamedPath.containsKey(recipe.name)) { recipePathToDocusaurusRenamedPath[recipe.name]!!