mirror of
https://github.com/revanced/revanced-patches
synced 2025-01-11 17:25:56 +01:00
docs: templated readme (#138)
This commit is contained in:
parent
dca6e6e73f
commit
8081a20285
8
README-template.md
Normal file
8
README-template.md
Normal file
@ -0,0 +1,8 @@
|
||||
# ReVanced Patches
|
||||
𧩠Official patches by ReVanced
|
||||
|
||||
# Patch list
|
||||
|
||||
| π Patch | π Description | π― Target Package | πΉ Target Version |
|
||||
|:--------:|:--------------:|:-----------------:|:-----------------:|
|
||||
{{ table }}
|
@ -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.
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
14
src/main/kotlin/app/revanced/meta/readme/Template.kt
Normal file
14
src/main/kotlin/app/revanced/meta/readme/Template.kt
Normal 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()
|
||||
}
|
Loadingβ¦
Reference in New Issue
Block a user