forked from trustwallet/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_info.ts
85 lines (76 loc) · 2.49 KB
/
gen_info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const bluebird = require("bluebird")
const nestedProperty = require("nested-property");
import {
chainsFolderPath,
getChainInfoPath,
isChainInfoExistSync,
writeFileSync,
readDirSync,
readFileSync,
getChainAssetInfoPath,
getChainAssetsPath,
isPathExistsSync
} from "../src/test/helpers"
import { CoinInfoList } from "../src/test/models";
const dafaultInfoTemplate: CoinInfoList =
{
"name": "",
"website": "",
"source_code": "",
"whitepaper": "",
"short_description": "",
"explorer": "",
"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: CoinInfoList) {
writeFileSync(path, JSON.stringify(info, null, 4))
}