Skip to content

Commit

Permalink
Also create a latest-versions.js
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 28, 2024
1 parent 68da4ce commit 2651736
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/
```

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
37 changes: 32 additions & 5 deletions src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -349,7 +350,7 @@ class RecipeMarkdownGenerator : Runnable {
}
}

private fun createLatestVersionsFile(
private fun createLatestVersionsMarkdown(
outputPath: Path,
recipeOrigins: Map<URI, RecipeOrigin>
) {
Expand Down Expand Up @@ -404,6 +405,32 @@ class RecipeMarkdownGenerator : Runnable {
}
}

private fun createLatestVersionsJs(
outputPath: Path,
recipeOrigins: Map<URI, RecipeOrigin>
) {
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<String, MarkdownRecipeArtifact>,
oldArtifacts: TreeMap<String, MarkdownRecipeArtifact>,
Expand Down Expand Up @@ -934,7 +961,7 @@ class RecipeMarkdownGenerator : Runnable {
Files.createDirectories(recipeMarkdownPath.parent)
Files.newBufferedWriter(recipeMarkdownPath, StandardOpenOption.CREATE).useAndApply {
write(
"""
"""
---
sidebar_label: "$sidebarFormattedName"
---
Expand Down Expand Up @@ -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]!!
Expand Down

0 comments on commit 2651736

Please sign in to comment.