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 .env
node_modules node_modules
.idea .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 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 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>) { fun main(args: Array<String>) {
doChecks(doRPCConnect = args.contains("rpcConnect"), doIconDownload = args.contains("iconDownload")) doChecks(doRPCConnect = args.contains("rpcConnect"), doIconDownload = args.contains("iconDownload"))
@ -33,6 +36,10 @@ private fun createOutputFiles() {
val chainJSONArray = JsonArray<JsonObject>() val chainJSONArray = JsonArray<JsonObject>()
val miniChainJSONArray = JsonArray<JsonObject>() val miniChainJSONArray = JsonArray<JsonObject>()
val chainIconJSONArray = JsonArray<JsonObject>()
val miniChainIconJSONArray = JsonArray<JsonObject>()
val shortNameMapping = JsonObject() val shortNameMapping = JsonObject()
// copy raw data so e.g. icons are available - SKIP errors // copy raw data so e.g. icons are available - SKIP errors
@ -43,7 +50,6 @@ private fun createOutputFiles() {
.forEach { jsonObject -> .forEach { jsonObject ->
chainJSONArray.add(jsonObject) chainJSONArray.add(jsonObject)
val miniJSON = JsonObject() val miniJSON = JsonObject()
listOf("name", "chainId", "shortName", "networkId", "nativeCurrency", "rpc", "faucets", "infoURL").forEach { field -> listOf("name", "chainId", "shortName", "networkId", "nativeCurrency", "rpc", "faucets", "infoURL").forEach { field ->
jsonObject[field]?.let { content -> jsonObject[field]?.let { content ->
@ -56,12 +62,30 @@ private fun createOutputFiles() {
} }
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.json").writeText(chainJSONArray.toJsonString())
File(buildPath, "chains_pretty.json").writeText(chainJSONArray.toJsonString(prettyPrint = true)) File(buildPath, "chains_pretty.json").writeText(chainJSONArray.toJsonString(prettyPrint = true))
File(buildPath, "chains_mini.json").writeText(miniChainJSONArray.toJsonString()) File(buildPath, "chains_mini.json").writeText(miniChainJSONArray.toJsonString())
File(buildPath, "chains_mini_pretty.json").writeText(miniChainJSONArray.toJsonString(prettyPrint = true)) 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, "shortNameMapping.json").writeText(shortNameMapping.toJsonString(prettyPrint = true))
File(buildPath, "index.html").writeText( File(buildPath, "index.html").writeText(
""" """