-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
17,798 additions
and
403 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
rootProject.name = "buildSrc" | ||
|
||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import kotlinx.serialization.encodeToString | ||
import me.alllex.tbot.apigen.BotApi | ||
import me.alllex.tbot.apigen.BotApiArgLists | ||
import me.alllex.tbot.apigen.BotApiElementArgs | ||
import me.alllex.tbot.apigen.jsonSerialization | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.* | ||
|
||
@CacheableTask | ||
abstract class BotApiArgListExtract : DefaultTask() { | ||
|
||
@get:[InputFile PathSensitive(PathSensitivity.RELATIVE)] | ||
abstract val apiJsonFile: RegularFileProperty | ||
|
||
@get:OutputFile | ||
abstract val outputFile: RegularFileProperty | ||
|
||
@TaskAction | ||
fun execute() { | ||
val apiJsonText = apiJsonFile.get().asFile.readText(Charsets.UTF_8) | ||
val botApi = jsonSerialization.decodeFromString<BotApi>(apiJsonText) | ||
|
||
val argLists = BotApiArgLists( | ||
types = botApi.types.map { | ||
BotApiElementArgs(name = it.name.value, args = it.fields?.map { it.name }.orEmpty()) | ||
}, | ||
methods = botApi.methods.map { | ||
BotApiElementArgs(name = it.name.value, args = it.parameters.map { it.name }) | ||
} | ||
) | ||
|
||
outputFile.get().asFile.writeText(jsonSerialization.encodeToString(argLists)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import kotlinx.serialization.encodeToString | ||
import me.alllex.tbot.apigen.BotApiDefinitionParser | ||
import me.alllex.tbot.apigen.jsonSerialization | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.* | ||
|
||
@CacheableTask | ||
abstract class BotApiExtract : DefaultTask() { | ||
|
||
@get:[InputFile PathSensitive(PathSensitivity.RELATIVE)] | ||
abstract val apiSpecFile: RegularFileProperty | ||
|
||
@get:OutputFile | ||
abstract val outputFile: RegularFileProperty | ||
|
||
@TaskAction | ||
fun execute() { | ||
val html = apiSpecFile.get().asFile.readText() | ||
val parser = BotApiDefinitionParser() | ||
val botApi = parser.run(html) | ||
|
||
val outputJson = jsonSerialization.encodeToString(botApi) | ||
outputFile.get().asFile.writeText(outputJson) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
buildSrc/src/main/kotlin/me/alllex/tbot/apigen/BotApiArgLists.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.alllex.tbot.apigen | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
|
||
@Serializable | ||
data class BotApiElementArgs( | ||
val name: String, | ||
val args: List<String>, | ||
) | ||
|
||
@Serializable | ||
data class BotApiArgLists( | ||
val types: List<BotApiElementArgs>, | ||
val methods: List<BotApiElementArgs>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.