Generate Icon list JSON in build (#1524)

This commit is contained in:
Ashutosh Kumar 2022-08-31 05:28:16 +05:30 committed by GitHub
parent 16bc050927
commit 7020019ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

6
.gitignore vendored
View File

@ -5,3 +5,9 @@ _site
.env
node_modules
.idea
output
.gradle
model/bin
model/build
processor/bin
processor/build

View File

@ -22,6 +22,9 @@ val chainsPath = File(dataPath, "chains")
private val allFiles = chainsPath.listFiles() ?: error("${chainsPath.absolutePath} must contain the chain json files - but it does not")
private val allChainFiles = allFiles.filter { !it.isDirectory }
private val allIconFilesList = iconsPath.listFiles() ?: error("${iconsPath.absolutePath} must contain the icon json files - but it does not")
private val allIconFiles = allIconFilesList.filter { !it.isDirectory }
fun main(args: Array<String>) {
doChecks(doRPCConnect = args.contains("rpcConnect"), doIconDownload = args.contains("iconDownload"))
@ -33,6 +36,10 @@ private fun createOutputFiles() {
val chainJSONArray = JsonArray<JsonObject>()
val miniChainJSONArray = JsonArray<JsonObject>()
val chainIconJSONArray = JsonArray<JsonObject>()
val miniChainIconJSONArray = JsonArray<JsonObject>()
val shortNameMapping = JsonObject()
// copy raw data so e.g. icons are available - SKIP errors
@ -43,7 +50,6 @@ private fun createOutputFiles() {
.forEach { jsonObject ->
chainJSONArray.add(jsonObject)
val miniJSON = JsonObject()
listOf("name", "chainId", "shortName", "networkId", "nativeCurrency", "rpc", "faucets", "infoURL").forEach { field ->
jsonObject[field]?.let { content ->
@ -55,6 +61,21 @@ private fun createOutputFiles() {
shortNameMapping[jsonObject["shortName"] as String] = "eip155:" + jsonObject["chainId"]
}
allIconFiles
.forEach { iconLocation ->
val jsonData = Klaxon().parseJsonArray(iconLocation.reader())
val iconName = iconLocation.toString().replace("../_data/icons/","").replace(".json","")
val iconJson = JsonObject()
iconJson["name"] = iconName
iconJson["icons"] = jsonData
chainIconJSONArray.add(iconJson)
}
File(buildPath, "chains.json").writeText(chainJSONArray.toJsonString())
File(buildPath, "chains.json").writeText(chainJSONArray.toJsonString())
File(buildPath, "chains_pretty.json").writeText(chainJSONArray.toJsonString(prettyPrint = true))
@ -62,6 +83,9 @@ private fun createOutputFiles() {
File(buildPath, "chains_mini.json").writeText(miniChainJSONArray.toJsonString())
File(buildPath, "chains_mini_pretty.json").writeText(miniChainJSONArray.toJsonString(prettyPrint = true))
File(buildPath, "chain_icons_mini.json").writeText(chainIconJSONArray.toJsonString())
File(buildPath, "chain_icons.json").writeText(chainIconJSONArray.toJsonString(prettyPrint = true))
File(buildPath, "shortNameMapping.json").writeText(shortNameMapping.toJsonString(prettyPrint = true))
File(buildPath, "index.html").writeText(
"""