trustwallet-assets/script/gen_info.ts
Mykola f3ffd0b9ae
Update coin info structure (#1511)
* Remove data_source and change explorers for coin info list

* Remove explorers and data_soruce from info model

* Add new helper func getChainAssetInfoPath

* script

* Rename explorers => explorer

* Rename explorers => explorer

* Remove lowercased version

* Optimised images with calibre/image-actions

* remove

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-03-21 20:12:51 -07:00

85 lines
2.5 KiB
TypeScript

const bluebird = require("bluebird")
const nestedProperty = require("nested-property");
import {
chainsFolderPath,
getChainInfoPath,
isChainInfoExistSync,
writeFileSync,
readDirSync,
readFileSync,
getChainAssetInfoPath,
getChainAssetsPath,
isPathExistsSync
} from "../src/test/helpers"
import { InfoList } from "../src/test/models";
const dafaultInfoTemplate: InfoList =
{
"name": "",
"website": "",
"source_code": "",
"whitepaper": "",
"short_description": "",
"explorers": "",
"socials": [
{
"name": "Twitter",
"url": "",
"handle": ""
},
{
"name": "Reddit",
"url": "",
"handle": ""
}
],
"details": [
{
"language": "en",
"description": ""
}
]
}
bluebird.mapSeries(readDirSync(chainsFolderPath), (chain: string) => {
const chainInfoPath = getChainInfoPath(chain)
// Create intial info.json file base off template if doesn't exist
if (!isChainInfoExistSync(chain)) {
writeToInfo(chainInfoPath, dafaultInfoTemplate)
}
// const infoList: InfoList = JSON.parse(readFileSync(chainInfoPath))
// delete infoList["data_source"]
// const newExplorer = nestedProperty.get(infoList, "explorers")
// console.log({newExplorer}, chain)
// nestedProperty.set(infoList, "explorer", newExplorer)
// delete infoList["explorers"]
// writeToInfo(chainInfoPath, infoList)
// if (isPathExistsSync(getChainAssetsPath(chain))) {
// readDirSync(getChainAssetsPath(chain)).forEach(asset => {
// const assetInfoPath = getChainAssetInfoPath(chain, asset)
// if (isPathExistsSync(assetInfoPath)) {
// const assetInfoList = JSON.parse(readFileSync(assetInfoPath))
// delete assetInfoList["data_source"]
// const newExplorers = nestedProperty.get(assetInfoList, "explorers.0.url")
// delete assetInfoList["explorers"]
// nestedProperty.set(assetInfoList, "explorer", newExplorers)
// writeToInfo(assetInfoPath, assetInfoList)
// }
// })
// }
})
// Get handle from Twitter and Reddit url
export function getHandle(url: string): string {
if (!url) return ""
return url.slice(url.lastIndexOf("/") + 1, url.length)
}
function writeToInfo(path: string, info: InfoList) {
writeFileSync(path, JSON.stringify(info, null, 4))
}