trustwallet-assets/script-old/arrange_files.ts
Adam R 102f2b88d4
[Internal] New infra for runnig checks (not as jest tests) (#2938)
* CMC mapping update.

* New check infrastructure, move root folder test to new infra.

* Move list of allowed files to config.

* Include new check in other tests.

* More generic way to call checks.

* Organize fix and update actions behind interfaces.

* Organize checks into steps, multiple steps per action.

* Simplify checkStep class/instance creation.

* Migrate chain logo checks.

* Migrate asset folder check.

* Migrate further chain checks.

* Migrate eth fork folder checks.

* Migrate binance chain check.

* Extra output.

* Output improvements.

* Async fix.

* Migrate Tron check.

* Add Tron check.

* Remove Tron check from old.

* White/blacklist check in new intra, combined with fix.

* Refine ETH checks.

* Remove from old infra.

* Migrate CMC check to new infra.

* Migrate validator tests to new check infra.

* Migrate Json files validity check to new check infra.

* Whitelist check fix.

* Cleanup helpers.ts.

* Move helpers.ts.

* Cleanup of models.ts.

* Move models.ts.

* Move index.test.ts.

* Update with BEP8 support.

* Descriptive names for jobs within the builds.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
2020-08-06 21:17:38 +02:00

84 lines
2.9 KiB
TypeScript

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,
isChecksum,
isEthereumAddress,
isPathDir,
logo,
logoExtension,
makeDirIfDoestExist,
readDirSync,
toChecksum,
isDirContainLogo
} from "./helpers"
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)
}
})