diff --git a/build.gradle.kts b/build.gradle.kts index 8978489aa..ae1de6cb2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,7 @@ tasks { dependsOn(build) classpath = sourceSets["main"].runtimeClasspath - mainClass.set("app.revanced.meta.Meta") + mainClass.set("app.revanced.meta.PatchesFileGenerator") } // Dummy task to fix the Gradle semantic-release plugin. // Remove this if you forked it to support building only. diff --git a/src/main/kotlin/app/revanced/meta/JsonGenerator.kt b/src/main/kotlin/app/revanced/meta/JsonGenerator.kt new file mode 100644 index 000000000..49c7a2c92 --- /dev/null +++ b/src/main/kotlin/app/revanced/meta/JsonGenerator.kt @@ -0,0 +1,70 @@ +package app.revanced.meta + +import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages +import app.revanced.patcher.extensions.PatchExtensions.dependencies +import app.revanced.patcher.extensions.PatchExtensions.description +import app.revanced.patcher.extensions.PatchExtensions.include +import app.revanced.patcher.extensions.PatchExtensions.options +import app.revanced.patcher.extensions.PatchExtensions.patchName +import app.revanced.patcher.extensions.PatchExtensions.version +import app.revanced.patcher.patch.PatchOption +import com.google.gson.GsonBuilder +import java.io.File + +internal class JsonGenerator : PatchesFileGenerator { + override fun generate(bundle: PatchBundlePatches) { + val patches = bundle.map { + JsonPatch( + it.patchName, + it.description ?: "This patch has no description.", + it.version ?: "0.0.0", + !it.include, + it.options?.map { option -> + Option( + option.key, + option.title, + option.description, + option.required, + option.let { lo -> + if (lo is PatchOption.ListOption<*>) { + lo.options.toMutableList().toTypedArray() + } else null + } + ) + }?.toTypedArray() ?: emptyArray(), + it.dependencies?.map { dep -> + dep.java.patchName + }?.toTypedArray() ?: emptyArray(), + it.compatiblePackages?.map { pkg -> + CompatiblePackage(pkg.name, pkg.versions) + }?.toTypedArray() ?: emptyArray() + ) + } + + val json = File("patches.json") + json.writeText(GsonBuilder().serializeNulls().create().toJson(patches)) + } + + data class JsonPatch( + val name: String, + val description: String, + val version: String, + val excluded: Boolean, + val options: Array