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
|
.env
|
||||||
node_modules
|
node_modules
|
||||||
.idea
|
.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 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(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user