2020-03-20 22:16:45 +00:00
|
|
|
import * as fs from "fs"
|
2020-04-18 03:33:50 +00:00
|
|
|
const isImage = require("is-image");
|
2020-03-20 22:16:45 +00:00
|
|
|
import {
|
|
|
|
ethSidechains,
|
|
|
|
getChainAssetPath,
|
|
|
|
getChainAssetsPath,
|
|
|
|
getFileExt,
|
|
|
|
getFileName,
|
|
|
|
isChecksum,
|
|
|
|
isPathDir,
|
|
|
|
logo,
|
|
|
|
logoExtension,
|
|
|
|
makeDirIfDoestExist,
|
|
|
|
readDirSync,
|
|
|
|
toChecksum,
|
2020-04-18 03:33:50 +00:00
|
|
|
getRootDirFilesList,
|
|
|
|
rootDirAllowedFiles,
|
|
|
|
isEthereumAddress
|
2020-03-20 22:16:45 +00:00
|
|
|
} from "../src/test/helpers"
|
|
|
|
|
|
|
|
ethSidechains.forEach(chain => {
|
2020-04-18 03:33:50 +00:00
|
|
|
const chainAssetsPath = getChainAssetsPath(chain)
|
2020-03-20 22:16:45 +00:00
|
|
|
|
2020-04-18 03:33:50 +00:00
|
|
|
readDirSync(chainAssetsPath).forEach(async asset => {
|
2020-03-20 22:16:45 +00:00
|
|
|
const assetPath = getChainAssetPath(chain, asset)
|
|
|
|
const isDir = await isPathDir(assetPath)
|
|
|
|
|
|
|
|
if (!isDir) {
|
2020-04-18 03:33:50 +00:00
|
|
|
const checksum = toChecksum(getFileName(asset))
|
2020-03-20 22:16:45 +00:00
|
|
|
|
|
|
|
if (isChecksum(checksum) && getFileExt(asset).toLocaleLowerCase() === logoExtension) {
|
2020-04-18 03:33:50 +00:00
|
|
|
// 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}`
|
2020-03-20 22:16:45 +00:00
|
|
|
fs.renameSync(assetPath, newPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-04-18 03:33:50 +00:00
|
|
|
// Moves asset/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}`)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|