mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Generate Icon list JSON in build (#1524)
This commit is contained in:
parent
16bc050927
commit
7020019ca9
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -5,3 +5,9 @@ _site
|
|||
.env
|
||||
node_modules
|
||||
.idea
|
||||
output
|
||||
.gradle
|
||||
model/bin
|
||||
model/build
|
||||
processor/bin
|
||||
processor/build
|
|
@ -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(
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user