mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Cleanup script-old. (#3992)
Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
92adaaf07e
commit
281a1cef7d
script-old
|
@ -1,99 +0,0 @@
|
|||
import * as fs from "fs"
|
||||
const isImage = require("is-image");
|
||||
import { rootDirAllowedFiles } from "../script/common/repo-structure";
|
||||
import { ethForkChains, Ethereum } from "../script/common/blockchains";
|
||||
import {
|
||||
getFileExt,
|
||||
getFileName
|
||||
} from "../script/common/filesystem";
|
||||
import {
|
||||
chainsFolderPath,
|
||||
getChainAssetPath,
|
||||
getChainAssetsPath,
|
||||
getChainPath,
|
||||
getRootDirFilesList,
|
||||
logo,
|
||||
logoExtension,
|
||||
readDirSync,
|
||||
isDirContainLogo
|
||||
} from "./helpers"
|
||||
import { isEthereumAddress, toChecksum, isChecksum } from "../script/common/eth-web3";
|
||||
|
||||
async function makeDirIfDoestExist(dirPath: string, dirName: string) {
|
||||
const path = `${dirPath}/${dirName}`
|
||||
await fs.mkdir(path, {recursive: true}, (err) => {
|
||||
if (err) {
|
||||
console.error(`Error creating dir at path ${path} with result ${err}`)
|
||||
} else {
|
||||
console.log(`Created direcotry at ${path}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function isPathDir(path: string): boolean {
|
||||
try {
|
||||
return fs.lstatSync(path).isDirectory()
|
||||
} catch (e) {
|
||||
console.log(`Path: ${path} is not a directory with error: ${e.message}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
ethForkChains.forEach(chain => {
|
||||
const chainAssetsPath = getChainAssetsPath(chain)
|
||||
|
||||
readDirSync(chainAssetsPath).forEach(async asset => {
|
||||
const assetPath = getChainAssetPath(chain, asset)
|
||||
const isDir = await isPathDir(assetPath)
|
||||
|
||||
if (!isDir) {
|
||||
const checksum = toChecksum(getFileName(asset))
|
||||
|
||||
if (isChecksum(checksum) && getFileExt(asset).toLocaleLowerCase() === logoExtension) {
|
||||
// Moves file like blockchains/<chain>/assets/0x..XX.png => blockchains/<chain>/asstes/0x..XX/logo.png
|
||||
await makeDirIfDoestExist(chainAssetsPath, checksum)
|
||||
const newPath = `${chainAssetsPath}/${checksum}/${logo}`
|
||||
fs.renameSync(assetPath, newPath)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// Moves assets/0xXX...XX.png => assets/blockchains/assets/0xXX...XX/logo.png
|
||||
getRootDirFilesList().forEach(async file => {
|
||||
const fileName = getFileName(file)
|
||||
if(isImage(file) && !rootDirAllowedFiles.includes(file) && isEthereumAddress(fileName)) {
|
||||
console.log({file})
|
||||
const checksum = toChecksum(fileName)
|
||||
const ethreumAssetsPath = getChainAssetsPath("ethereum")
|
||||
await makeDirIfDoestExist(ethreumAssetsPath, checksum)
|
||||
fs.renameSync(`./${file}`, `${ethreumAssetsPath}/${checksum}/${logo}`)
|
||||
}
|
||||
});
|
||||
|
||||
readDirSync(chainsFolderPath).forEach(async chainDir => {
|
||||
const chainPath = getChainPath(chainDir)
|
||||
const isDir = isPathDir(chainPath)
|
||||
const ethereumAssetsPath = getChainAssetsPath(Ethereum)
|
||||
|
||||
// Moves blockchains/0xXX...XX.png => assets/blockchains/ethereum/0xXX...XX/logo.png
|
||||
if (!isDir) {
|
||||
const checksum = toChecksum(getFileName(chainDir))
|
||||
|
||||
if (isChecksum(checksum) && getFileExt(chainDir).toLocaleLowerCase() === logoExtension) {
|
||||
await makeDirIfDoestExist(ethereumAssetsPath, checksum)
|
||||
const newPath = `${ethereumAssetsPath}/${checksum}/${logo}`
|
||||
fs.renameSync(chainPath, newPath)
|
||||
}
|
||||
}
|
||||
|
||||
// Moves blockchains/0xXX...XX/logo.png => assets/blockchains/ethereum/0xXX...XX/logo.png
|
||||
if (isDir && isDirContainLogo(chainPath)) {
|
||||
const checksum = toChecksum(getFileName(chainDir))
|
||||
await makeDirIfDoestExist(ethereumAssetsPath, checksum)
|
||||
const newPath = `${ethereumAssetsPath}/${checksum}`
|
||||
fs.renameSync(chainPath, newPath)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
const bluebird = require("bluebird")
|
||||
import { writeFileSync, readDirSync } from "../script/common/filesystem";
|
||||
import {
|
||||
chainsFolderPath,
|
||||
getChainInfoPath,
|
||||
isChainInfoExistSync,
|
||||
} from "./helpers"
|
||||
import { CoinInfoList } from "./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))
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
|
||||
export const logoName = `logo`
|
||||
export const infoName = `info`
|
||||
|
||||
export const logoExtension = "png"
|
||||
export const jsonExtension = "json"
|
||||
|
||||
export const logo = `${logoName}.${logoExtension}`
|
||||
export const info = `${infoName}.${jsonExtension}`
|
||||
|
||||
export const root = './'
|
||||
export const chainsFolderPath = path.join(process.cwd(), '/blockchains')
|
||||
export const getChainInfoPath = (chain: string): string => `${chainsFolderPath}/${chain}/info/${info}`
|
||||
export const getChainAssetsPath = (chain: string): string => `${chainsFolderPath}/${chain}/assets`
|
||||
export const getChainPath = (chain: string): string => `${chainsFolderPath}/${chain}`
|
||||
|
||||
export const getChainAssetPath = (chain: string, address: string) => `${getChainAssetsPath(chain)}/${address}`
|
||||
export const getRootDirFilesList = (): string[] => readDirSync(root)
|
||||
|
||||
export const readDirSync = (path: string): string[] => fs.readdirSync(path)
|
||||
export const isPathExistsSync = (path: string): boolean => fs.existsSync(path)
|
||||
export const isDirContainLogo = (path: string): boolean => fs.existsSync(`${path}/${logo}`)
|
||||
export const isChainInfoExistSync = (chain: string): boolean => isPathExistsSync(getChainInfoPath(chain))
|
||||
export const readFileSync = (path: string) => fs.readFileSync(path, 'utf8')
|
Loading…
Reference in New Issue
Block a user