mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
chore: ReadMeFileGenerator
no longer uses a hardcoded version of README-template.md
This commit is contained in:
@ -20,30 +20,7 @@ Example:
|
|||||||
"compatiblePackages":[
|
"compatiblePackages":[
|
||||||
{
|
{
|
||||||
"name":"com.google.android.youtube",
|
"name":"com.google.android.youtube",
|
||||||
"versions":[
|
"versions": COMPATIBLE_PACKAGE_YOUTUBE
|
||||||
"18.29.38",
|
|
||||||
"18.30.37",
|
|
||||||
"18.31.40",
|
|
||||||
"18.32.39",
|
|
||||||
"18.33.40",
|
|
||||||
"18.34.38",
|
|
||||||
"18.35.36",
|
|
||||||
"18.36.39",
|
|
||||||
"18.37.36",
|
|
||||||
"18.38.44",
|
|
||||||
"18.39.41",
|
|
||||||
"18.40.34",
|
|
||||||
"18.41.39",
|
|
||||||
"18.42.41",
|
|
||||||
"18.43.45",
|
|
||||||
"18.44.41",
|
|
||||||
"18.45.43",
|
|
||||||
"18.46.45",
|
|
||||||
"18.48.39",
|
|
||||||
"18.49.37",
|
|
||||||
"19.01.34",
|
|
||||||
"19.02.39"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"use":true,
|
"use":true,
|
||||||
@ -56,18 +33,7 @@ Example:
|
|||||||
"compatiblePackages": [
|
"compatiblePackages": [
|
||||||
{
|
{
|
||||||
"name": "com.google.android.apps.youtube.music",
|
"name": "com.google.android.apps.youtube.music",
|
||||||
"versions": [
|
"versions": COMPATIBLE_PACKAGE_MUSIC
|
||||||
"6.21.52",
|
|
||||||
"6.22.52",
|
|
||||||
"6.23.56",
|
|
||||||
"6.25.53",
|
|
||||||
"6.26.51",
|
|
||||||
"6.27.54",
|
|
||||||
"6.28.53",
|
|
||||||
"6.29.58",
|
|
||||||
"6.31.55",
|
|
||||||
"6.33.52"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"use":true,
|
"use":true,
|
||||||
@ -80,10 +46,7 @@ Example:
|
|||||||
"compatiblePackages": [
|
"compatiblePackages": [
|
||||||
{
|
{
|
||||||
"name": "com.reddit.frontpage",
|
"name": "com.reddit.frontpage",
|
||||||
"versions": [
|
"versions": COMPATIBLE_PACKAGE_REDDIT
|
||||||
"2023.12.0",
|
|
||||||
"2024.04.0"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"use":true,
|
"use":true,
|
||||||
|
@ -2,18 +2,61 @@ package app.revanced.generator
|
|||||||
|
|
||||||
import app.revanced.patcher.PatchSet
|
import app.revanced.patcher.PatchSet
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.Patch.CompatiblePackage
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
internal class ReadMeFileGenerator : PatchesFileGenerator {
|
internal class ReadMeFileGenerator : PatchesFileGenerator {
|
||||||
private companion object {
|
// For this exception to apply to [README.md],
|
||||||
private const val TABLE_HEADER =
|
// Supported version of [app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE] should be empty.
|
||||||
"| \uD83D\uDC8A Patch | \uD83D\uDCDC Description | \uD83C\uDFF9 Target Version |\n" +
|
private val exception = mapOf(
|
||||||
"|:--------:|:--------------:|:-----------------:|"
|
"com.google.android.apps.youtube.music" to "6.21.52"
|
||||||
}
|
)
|
||||||
|
|
||||||
|
private val readMeFile = File("README.md")
|
||||||
|
private val readMeTemplateFile = File("README-template.md")
|
||||||
|
|
||||||
|
private val tableHeader =
|
||||||
|
"| \uD83D\uDC8A Patch | \uD83D\uDCDC Description | \uD83C\uDFF9 Target Version |\n" +
|
||||||
|
"|:--------:|:--------------:|:-----------------:|"
|
||||||
|
|
||||||
override fun generate(patches: PatchSet) {
|
override fun generate(patches: PatchSet) {
|
||||||
val output = StringBuilder()
|
val output = StringBuilder()
|
||||||
|
|
||||||
|
// create a temp file
|
||||||
|
val readMeTemplateTempFile = File.createTempFile("README", ".md", File(Paths.get("").toAbsolutePath().toString()))
|
||||||
|
|
||||||
|
// copy the contents of 'README-template.md' to the temp file
|
||||||
|
StringBuilder(readMeTemplateFile.readText())
|
||||||
|
.toString()
|
||||||
|
.let(readMeTemplateTempFile::writeText)
|
||||||
|
|
||||||
|
// add a list of supported versions to a temp file
|
||||||
|
mapOf(
|
||||||
|
app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE to "COMPATIBLE_PACKAGE_MUSIC",
|
||||||
|
app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKAGE to "COMPATIBLE_PACKAGE_REDDIT",
|
||||||
|
app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE to "COMPATIBLE_PACKAGE_YOUTUBE"
|
||||||
|
).forEach { (compatiblePackage, replaceString) ->
|
||||||
|
compatiblePackage.map { CompatiblePackage(it.name, it.versions?.toSet()?.ifEmpty { null }) }
|
||||||
|
.forEach { compatiblePackages ->
|
||||||
|
val pkgName = compatiblePackages.name
|
||||||
|
val supportedVersion = if (compatiblePackages.versions == null && exception.containsKey(pkgName)) {
|
||||||
|
exception[pkgName] + "+"
|
||||||
|
} else {
|
||||||
|
compatiblePackages.versions
|
||||||
|
?.toString()
|
||||||
|
?.replace("[", "[\n \"")
|
||||||
|
?.replace("]", "\"\n ]")
|
||||||
|
?.replace(", ", "\",\n \"")
|
||||||
|
?: "all"
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder(readMeTemplateTempFile.readText())
|
||||||
|
.replace(Regex(replaceString), supportedVersion)
|
||||||
|
.let(readMeTemplateTempFile::writeText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mutableMapOf<String, MutableSet<Patch<*>>>()
|
mutableMapOf<String, MutableSet<Patch<*>>>()
|
||||||
.apply {
|
.apply {
|
||||||
for (patch in patches) {
|
for (patch in patches) {
|
||||||
@ -29,7 +72,7 @@ internal class ReadMeFileGenerator : PatchesFileGenerator {
|
|||||||
output.apply {
|
output.apply {
|
||||||
appendLine("### [\uD83D\uDCE6 `$pkg`](https://play.google.com/store/apps/details?id=$pkg)")
|
appendLine("### [\uD83D\uDCE6 `$pkg`](https://play.google.com/store/apps/details?id=$pkg)")
|
||||||
appendLine("<details>\n")
|
appendLine("<details>\n")
|
||||||
appendLine(TABLE_HEADER)
|
appendLine(tableHeader)
|
||||||
patches.sortedBy { it.name }.forEach { patch ->
|
patches.sortedBy { it.name }.forEach { patch ->
|
||||||
val supportedVersionArray =
|
val supportedVersionArray =
|
||||||
patch.compatiblePackages?.single { it.name == pkg }?.versions
|
patch.compatiblePackages?.single { it.name == pkg }?.versions
|
||||||
@ -42,7 +85,9 @@ internal class ReadMeFileGenerator : PatchesFileGenerator {
|
|||||||
maxVersion
|
maxVersion
|
||||||
else
|
else
|
||||||
"$minVersion ~ $maxVersion"
|
"$minVersion ~ $maxVersion"
|
||||||
} else
|
} else if (exception.containsKey(pkg))
|
||||||
|
exception[pkg] + "+"
|
||||||
|
else
|
||||||
"all"
|
"all"
|
||||||
|
|
||||||
appendLine(
|
appendLine(
|
||||||
@ -55,8 +100,12 @@ internal class ReadMeFileGenerator : PatchesFileGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder(File("README-template.md").readText())
|
// copy the contents of the temp file to 'README.md'
|
||||||
|
StringBuilder(readMeTemplateTempFile.readText())
|
||||||
.replace(Regex("\\{\\{\\s?table\\s?}}"), output.toString())
|
.replace(Regex("\\{\\{\\s?table\\s?}}"), output.toString())
|
||||||
.let(File("README.md")::writeText)
|
.let(readMeFile::writeText)
|
||||||
|
|
||||||
|
// delete temp file
|
||||||
|
readMeTemplateTempFile.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user