docs: templated readme (#138)

This commit is contained in:
bogadana 2022-07-10 15:28:18 +02:00 committed by GitHub
parent dca6e6e73f
commit 8081a20285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 26 deletions

8
README-template.md Normal file
View File

@ -0,0 +1,8 @@
# ReVanced Patches
🧩 Official patches by ReVanced
# Patch list
| πŸ’Š Patch | πŸ“œ Description | 🎯 Target Package | 🏹 Target Version |
|:--------:|:--------------:|:-----------------:|:-----------------:|
{{ table }}

View File

@ -54,7 +54,7 @@ tasks {
dependsOn(build)
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("app.revanced.patches.meta.ReadmeGenerator")
mainClass.set("app.revanced.patches.meta.readme.Generator")
}
// Dummy task to fix the Gradle semantic-release plugin.
// Remove this if you forked it to support building only.

View File

@ -1,4 +1,4 @@
package app.revanced.patches.meta
package app.revanced.patches.meta.readme
import java.io.File
import kotlin.io.writeText
@ -8,36 +8,16 @@ import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.extensions.PatchExtensions.description
class ReadmeGenerator {
class Generator {
companion object {
@JvmStatic
fun main(args: Array<String>) {
//should be moved to a file?
val generalReadme =
"""
# ReVanced Patches
🧩 Official patches by ReVanced
# Patch list
""".trimIndent()
val tableHeader =
"""
| πŸ’Š Patch | πŸ“œ Description | 🎯 Target Package | 🏹 Target Version |
|:-----:|:-----------:|:--------------:|:----------------------:|
""".trimIndent()
val readmeFile = File("README.md")
val buildDir = File("build/libs/")
val buildJar = buildDir.listFiles().first { it.name.startsWith("revanced-patches-") && it.name.endsWith(".jar") }
val bundle = JarPatchBundle(buildJar.absolutePath).loadPatches()
val builder = StringBuilder()
builder.appendLine(generalReadme)
builder.appendLine(tableHeader)
val table = StringBuilder()
for (patch in bundle) {
val humanName =
@ -46,10 +26,16 @@ class ReadmeGenerator {
val compatiblePackage = patch.compatiblePackages?.first()
val latestVersion = compatiblePackage?.versions?.maxByOrNull { it.replace(".", "").toInt() } ?: "all"
builder.appendLine("|$humanName|${patch.description}|`${compatiblePackage?.name}`|$latestVersion|")
table.appendLine("|$humanName|${patch.description}|`${compatiblePackage?.name}`|$latestVersion|")
}
readmeFile.writeText(builder.toString())
val readMeTemplateFile = File("README-template.md")
val readMeTemplate = Template(readMeTemplateFile.readText())
readMeTemplate.replaceVariable("table", table.toString())
val readMeFile = File("README.md")
readMeFile.writeText(readMeTemplate.toString())
}
}
}

View File

@ -0,0 +1,14 @@
package app.revanced.patches.meta.readme
class Template(val template: String) {
val result: StringBuilder = StringBuilder(template)
fun replaceVariable(name: String, value: String) {
val regex = Regex("\\{\\{\\s?$name\\s?\\}\\}")
val range = regex.find(result)!!.range
result.replace(range.start, range.endInclusive + 1, value)
}
override fun toString(): String = result.toString()
}