2020-01-18 22:21:09 +00:00
|
|
|
const bluebird = require("bluebird")
|
2020-01-28 20:55:19 +00:00
|
|
|
const nestedProperty = require("nested-property");
|
2020-01-18 22:21:09 +00:00
|
|
|
import {
|
|
|
|
chainsFolderPath,
|
|
|
|
getChainInfoPath,
|
|
|
|
isChainInfoExistSync,
|
|
|
|
writeFileSync,
|
2020-01-28 20:55:19 +00:00
|
|
|
readDirSync,
|
|
|
|
readFileSync
|
2020-01-18 22:21:09 +00:00
|
|
|
} from "../src/test/helpers"
|
2020-01-28 20:55:19 +00:00
|
|
|
import { InfoList } from "../src/test/models";
|
2020-01-18 22:21:09 +00:00
|
|
|
|
2020-01-28 20:55:19 +00:00
|
|
|
const dafaultInfoTemplate: InfoList =
|
2020-01-18 22:21:09 +00:00
|
|
|
{
|
|
|
|
"name": "",
|
|
|
|
"website": "",
|
|
|
|
"source_code": "",
|
|
|
|
"whitepaper": "",
|
2020-02-17 03:52:14 +00:00
|
|
|
"short_description": "",
|
2020-01-18 22:21:09 +00:00
|
|
|
"explorers": [
|
|
|
|
{
|
|
|
|
"name": "",
|
|
|
|
"url": ""
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"socials": [
|
|
|
|
{
|
|
|
|
"name": "Twitter",
|
2020-01-28 20:55:19 +00:00
|
|
|
"url": "",
|
|
|
|
"handle": ""
|
2020-01-18 22:21:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Reddit",
|
2020-01-28 20:55:19 +00:00
|
|
|
"url": "",
|
|
|
|
"handle": ""
|
2020-01-18 22:21:09 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"language": "en",
|
|
|
|
"description": ""
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"data_source": "crowd"
|
|
|
|
}
|
|
|
|
|
|
|
|
bluebird.mapSeries(readDirSync(chainsFolderPath), (chain: string) => {
|
|
|
|
const chainInfoPath = getChainInfoPath(chain)
|
|
|
|
|
2020-01-28 20:55:19 +00:00
|
|
|
// Create intial info.json file base off template if doesn't exist
|
|
|
|
if (!isChainInfoExistSync(chain)) {
|
|
|
|
writeToInfo(chainInfoPath, dafaultInfoTemplate)
|
2020-01-18 22:21:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 20:55:19 +00:00
|
|
|
const infoList: InfoList = JSON.parse(readFileSync(chainInfoPath))
|
|
|
|
// Add "handle" property to each social element
|
|
|
|
let newSocials = []
|
2020-02-21 22:01:03 +00:00
|
|
|
if ("socials" in infoList) {
|
|
|
|
infoList.socials.forEach(social => {
|
|
|
|
const handle = "handle"
|
|
|
|
if (nestedProperty.hasOwn(social, handle)) {
|
|
|
|
nestedProperty.set(social, handle, getHandle(social.url))
|
|
|
|
newSocials.push(social)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-01-28 20:55:19 +00:00
|
|
|
nestedProperty.set(infoList, "socials", newSocials)
|
|
|
|
writeToInfo(chainInfoPath, infoList)
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|