trustwallet-assets/script/arrange_files.ts
CHALLENG-CLG 20bb9c155c
Add CHALLENGE-CLG Logo (#2316)
* Add CHALLENGE-CLG Logo

* Add script that moves file to correct location

Co-authored-by: Mykola <kolya182@gmail.com>
2020-06-10 15:43:17 -07:00

72 lines
2.4 KiB
TypeScript

import * as fs from "fs"
const isImage = require("is-image");
import {
Ethereum,
chainsFolderPath,
ethSidechains,
getChainAssetPath,
getChainAssetsPath,
getChainPath,
getFileExt,
getFileName,
getRootDirFilesList,
isChecksum,
isEthereumAddress,
isPathDir,
logo,
logoExtension,
makeDirIfDoestExist,
readDirSync,
rootDirAllowedFiles,
toChecksum,
} from "../src/test/helpers"
ethSidechains.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}`)
}
});
// Moves blockchains/0xXX...XX.png => assets/blockchains/ethereum/0xXX...XX/logo.png
readDirSync(chainsFolderPath).forEach(async chainFile => {
const chainPath = getChainPath(chainFile)
const isDir = isPathDir(chainPath)
if (!isDir) {
const checksum = toChecksum(getFileName(chainFile))
const chainAssetsPath = getChainAssetsPath(Ethereum)
if (isChecksum(checksum) && getFileExt(chainFile).toLocaleLowerCase() === logoExtension) {
await makeDirIfDoestExist(chainAssetsPath, checksum)
const newPath = `${chainAssetsPath}/${checksum}/${logo}`
fs.renameSync(chainPath, newPath)
}
}
})