diff --git a/blockchains/xdai/assets/0x1e16aa4Df73d29C029d94CeDa3e3114EC191E25A/logo.png b/blockchains/xdai/assets/0x1e16aa4Df73d29C029d94CeDa3e3114EC191E25A/logo.png index 8c692b360..5d31c07b2 100644 Binary files a/blockchains/xdai/assets/0x1e16aa4Df73d29C029d94CeDa3e3114EC191E25A/logo.png and b/blockchains/xdai/assets/0x1e16aa4Df73d29C029d94CeDa3e3114EC191E25A/logo.png differ diff --git a/script/action/eth-forks.ts b/script/action/eth-forks.ts index b31cd6816..1e7773de4 100644 --- a/script/action/eth-forks.ts +++ b/script/action/eth-forks.ts @@ -21,16 +21,15 @@ import { } from "../common/filesystem"; import { isChecksum, toChecksum } from "../common/eth-web3"; import { ActionInterface, CheckStepInterface } from "./interface"; -import { isLogoOK } from "../common/image"; import { isAssetInfoOK } from "../common/asset-info"; import * as bluebird from "bluebird"; -function formatInfos() { +async function formatInfos() { console.log(`Formatting info files...`); - ethForkChains.forEach(chain => { + await bluebird.each(ethForkChains, async (chain) => { let count: number = 0; const chainAssets = getChainAssetsList(chain); - chainAssets.forEach(address => { + await bluebird.each(chainAssets, async (address) => { if (isChainAssetInfoExistSync(chain, address)) { const chainAssetInfoPath = getChainAssetInfoPath(chain, address); formatJsonFile(chainAssetInfoPath, true); @@ -49,13 +48,13 @@ function checkAddressChecksum(assetsFolderPath: string, address: string) { } } -function checkAddressChecksums() { +async function checkAddressChecksums() { console.log(`Checking for checksum formats ...`); - ethForkChains.forEach(chain => { + await bluebird.each(ethForkChains, async (chain) => { const assetsPath = getChainAssetsPath(chain); - readDirSync(assetsPath).forEach(address => { - getChainAssetFilesList(chain, address).forEach(file => { + await bluebird.each(readDirSync(assetsPath), async (address) => { + await bluebird.each(getChainAssetFilesList(chain, address), async (file) => { if (getFileName(file) == logoName && getFileExt(file) !== logoExtension) { console.log(`Renaming incorrect asset logo extension ${file} ...`); gitMove(getChainAssetPath(chain, address), file, logoFullName); @@ -92,10 +91,6 @@ export class EthForks implements ActionInterface { if (!isPathExistsSync(assetLogoPath)) { error += `Missing file at path '${assetLogoPath}'\n`; } - const [isOK, dimensionMsg] = await isLogoOK(assetLogoPath); - if (!isOK) { - error += dimensionMsg + "\n"; - } const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address); if (!isInfoOK) { error += infoMsg + "\n"; @@ -110,8 +105,8 @@ export class EthForks implements ActionInterface { } async fix(): Promise { - formatInfos(); - checkAddressChecksums(); + await formatInfos(); + await checkAddressChecksums(); } update = null; diff --git a/script/action/logo-size.ts b/script/action/logo-size.ts index e12cd06bb..9879350d0 100644 --- a/script/action/logo-size.ts +++ b/script/action/logo-size.ts @@ -12,20 +12,27 @@ import { readFileSync, isPathExistsSync } from "../common/filesystem"; -import { resizeIfTooLarge } from "../common/image"; -import { ActionInterface } from "./interface"; +import { checkResizeIfTooLarge } from "../common/image"; +import { ActionInterface, CheckStepInterface } from "./interface"; -async function downsize(chains) { - console.log(`Checking all logos for downsizing ...`); +// return name of large logo, or empty +async function checkDownsize(chains, checkOnly: boolean): Promise { + console.log(`Checking all logos for size ...`); let totalCountChecked: number = 0; + let totalCountTooLarge: number = 0; let totalCountUpdated: number = 0; + let largePath = ""; await bluebird.map(chains, async chain => { let countChecked: number = 0; + let countTooLarge: number = 0; let countUpdated: number = 0; const path = getChainLogoPath(chain); countChecked++; - countUpdated += await resizeIfTooLarge(path) ? 1 : 0; + const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly); + if (tooLarge) { largePath = path; } + countTooLarge += tooLarge ? 1 : 0; + countUpdated += updated ? 1 : 0; // Check and resize if needed chain assets const assetsPath = getChainAssetsPath(chain); @@ -33,7 +40,10 @@ async function downsize(chains) { await bluebird.mapSeries(readDirSync(assetsPath), async asset => { const path = getChainAssetLogoPath(chain, asset); countChecked++; - countUpdated += await resizeIfTooLarge(path) ? 1 : 0; + const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly); + if (tooLarge) { largePath = path; } + countTooLarge += tooLarge ? 1 : 0; + countUpdated += updated ? 1 : 0; }) } @@ -44,25 +54,47 @@ async function downsize(chains) { await bluebird.mapSeries(validatorsList, async ({ id }) => { const path = getChainValidatorAssetLogoPath(chain, id); countChecked++; - countUpdated += await resizeIfTooLarge(path) ? 1 : 0; + const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly); + if (tooLarge) { largePath = path; } + countTooLarge += tooLarge ? 1 : 0; + countUpdated += updated ? 1 : 0; }) } totalCountChecked += countChecked; + totalCountTooLarge += countTooLarge; totalCountUpdated += countUpdated; - if (countUpdated > 0) { - console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countUpdated} logos updated`); + if (countTooLarge > 0 || countUpdated > 0) { + console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countTooLarge} too large, ${largePath}, ${countUpdated} logos updated`); } }); - console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountUpdated} logos updated`); + console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountTooLarge} too large, ${totalCountUpdated} logos updated`); + return largePath; } export class LogoSize implements ActionInterface { getName(): string { return "Logo sizes"; } - getChecks = null; + + getChecks(): CheckStepInterface[] { + return [ + { + getName: () => { return "Check that logos are not too large"}, + check: async () => { + const foundChains = readDirSync(chainsPath); + var largePath = await checkDownsize(foundChains, true); + if (largePath.length > 0) { + return `Found at least one logo that is too large: ${largePath}`; + } + return ""; + } + }, + ]; + } + async fix(): Promise { const foundChains = readDirSync(chainsPath); - await downsize(foundChains); + await checkDownsize(foundChains, false); } + update = null; } diff --git a/script/action/tron.ts b/script/action/tron.ts index fb900d4b8..fb863cb69 100644 --- a/script/action/tron.ts +++ b/script/action/tron.ts @@ -4,7 +4,6 @@ import { Tron } from "../common/blockchains"; import { readDirSync, isPathExistsSync } from "../common/filesystem"; import { getChainAssetLogoPath, getChainValidatorsAssets } from "../common/repo-structure"; import { isLowerCase, isUpperCase } from "../common/types"; -import { isLogoOK } from "../common/image"; import * as bluebird from "bluebird"; export function isTRC10(str: string): boolean { @@ -37,10 +36,6 @@ export class TronAction implements ActionInterface { if (!isPathExistsSync(assetsLogoPath)) { error += `Missing file at path '${assetsLogoPath}'\n`; } - const [isOk, sizeMsg] = await isLogoOK(assetsLogoPath); - if (!isOk) { - error += sizeMsg + "\n"; - } }); return error; } diff --git a/script/common/image.ts b/script/common/image.ts index b158e43f5..e82bab81d 100644 --- a/script/common/image.ts +++ b/script/common/image.ts @@ -71,37 +71,50 @@ async function isLogoSizeOK(path: string): Promise<[boolean, string]> { return [true, '']; } -// return true if image updated -export async function resizeIfTooLarge(path: string): Promise { +// return if image if too large, and if image has been updated +export async function checkResizeIfTooLarge(path: string, checkOnly: boolean): Promise<[boolean, boolean]> { + let tooLarge = false; let updated: boolean = false; - + const { width: srcWidth, height: srcHeight } = getImageDimensions(path); + + if (!isDimensionOK(srcWidth, srcHeight)) { + tooLarge = true; // may be too small as well + } + if (isDimensionTooLarge(srcWidth, srcHeight)) { - const { width, height } = calculateTargetSize(srcWidth, srcHeight, maxLogoWidth, maxLogoHeight); - console.log(`Resizing image at ${path} from ${srcWidth}x${srcHeight} => ${width}x${height}`) - await sharp(path).resize(width, height).toBuffer() - .then(data => { - writeFileSync(path, data); - updated = true; - }) - .catch(e => { - console.log(chalk.red(e.message)); - }); + tooLarge = true; + if (!checkOnly) { + // resize + const { width, height } = calculateTargetSize(srcWidth, srcHeight, maxLogoWidth, maxLogoHeight); + console.log(`Resizing image at ${path} from ${srcWidth}x${srcHeight} => ${width}x${height}`) + await sharp(path).resize(width, height).toBuffer() + .then(data => { + writeFileSync(path, data); + updated = true; + }) + .catch(e => { + console.log(chalk.red(e.message)); + }); + } } // If file size > max limit, compress with tinypng const sizeKilobyte = getFileSizeInKilobyte(path); if (sizeKilobyte > maxLogoSizeInKilobyte) { - console.log(`Resizing image at path ${path} from ${sizeKilobyte} kB`); - await compressTinyPNG(path) - .then(() => { - updated = true; - console.log(`Resized image at path ${path} from ${sizeKilobyte} kB => ${getFileSizeInKilobyte(path)} kB`); - }) - .catch(e => { - console.log(chalk.red(e.message)); - }); + tooLarge = true; + if (!checkOnly) { + console.log(`Resizing image at path ${path} from ${sizeKilobyte} kB`); + await compressTinyPNG(path) + .then(() => { + updated = true; + console.log(`Resized image at path ${path} from ${sizeKilobyte} kB => ${getFileSizeInKilobyte(path)} kB`); + }) + .catch(e => { + console.log(chalk.red(e.message)); + }); + } } - return updated; + return [tooLarge, updated]; }