2020-07-29 13:42:51 +00:00
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
import {
|
|
|
|
chainsPath,
|
|
|
|
getChainLogoPath,
|
|
|
|
getChainAssetsPath,
|
|
|
|
getChainAssetLogoPath,
|
|
|
|
getChainValidatorsListPath,
|
|
|
|
getChainValidatorAssetLogoPath
|
|
|
|
} from "../common/repo-structure";
|
|
|
|
import {
|
|
|
|
readDirSync,
|
|
|
|
readFileSync,
|
|
|
|
isPathExistsSync
|
|
|
|
} from "../common/filesystem";
|
2020-08-07 14:39:46 +00:00
|
|
|
import { checkResizeIfTooLarge } from "../common/image";
|
|
|
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
2020-07-29 13:42:51 +00:00
|
|
|
|
2020-08-07 14:39:46 +00:00
|
|
|
// return name of large logo, or empty
|
|
|
|
async function checkDownsize(chains, checkOnly: boolean): Promise<string> {
|
|
|
|
console.log(`Checking all logos for size ...`);
|
2020-07-29 13:42:51 +00:00
|
|
|
let totalCountChecked: number = 0;
|
2020-08-07 14:39:46 +00:00
|
|
|
let totalCountTooLarge: number = 0;
|
2020-07-29 13:42:51 +00:00
|
|
|
let totalCountUpdated: number = 0;
|
2020-08-07 14:39:46 +00:00
|
|
|
let largePath = "";
|
2020-07-29 13:42:51 +00:00
|
|
|
await bluebird.map(chains, async chain => {
|
|
|
|
let countChecked: number = 0;
|
2020-08-07 14:39:46 +00:00
|
|
|
let countTooLarge: number = 0;
|
2020-07-29 13:42:51 +00:00
|
|
|
let countUpdated: number = 0;
|
|
|
|
|
|
|
|
const path = getChainLogoPath(chain);
|
|
|
|
countChecked++;
|
2020-08-07 14:39:46 +00:00
|
|
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
|
|
|
if (tooLarge) { largePath = path; }
|
|
|
|
countTooLarge += tooLarge ? 1 : 0;
|
|
|
|
countUpdated += updated ? 1 : 0;
|
2020-07-29 13:42:51 +00:00
|
|
|
|
|
|
|
// Check and resize if needed chain assets
|
|
|
|
const assetsPath = getChainAssetsPath(chain);
|
|
|
|
if (isPathExistsSync(assetsPath)) {
|
|
|
|
await bluebird.mapSeries(readDirSync(assetsPath), async asset => {
|
|
|
|
const path = getChainAssetLogoPath(chain, asset);
|
|
|
|
countChecked++;
|
2020-08-07 14:39:46 +00:00
|
|
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
|
|
|
if (tooLarge) { largePath = path; }
|
|
|
|
countTooLarge += tooLarge ? 1 : 0;
|
|
|
|
countUpdated += updated ? 1 : 0;
|
2020-07-29 13:42:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check and resize if needed chain validators image
|
|
|
|
const chainValidatorsList = getChainValidatorsListPath(chain);
|
|
|
|
if (isPathExistsSync(chainValidatorsList)) {
|
|
|
|
const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain)));
|
|
|
|
await bluebird.mapSeries(validatorsList, async ({ id }) => {
|
|
|
|
const path = getChainValidatorAssetLogoPath(chain, id);
|
|
|
|
countChecked++;
|
2020-08-07 14:39:46 +00:00
|
|
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
|
|
|
if (tooLarge) { largePath = path; }
|
|
|
|
countTooLarge += tooLarge ? 1 : 0;
|
|
|
|
countUpdated += updated ? 1 : 0;
|
2020-07-29 13:42:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
totalCountChecked += countChecked;
|
2020-08-07 14:39:46 +00:00
|
|
|
totalCountTooLarge += countTooLarge;
|
2020-07-29 13:42:51 +00:00
|
|
|
totalCountUpdated += countUpdated;
|
2020-08-07 14:39:46 +00:00
|
|
|
if (countTooLarge > 0 || countUpdated > 0) {
|
|
|
|
console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countTooLarge} too large, ${largePath}, ${countUpdated} logos updated`);
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-07 14:39:46 +00:00
|
|
|
console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountTooLarge} too large, ${totalCountUpdated} logos updated`);
|
|
|
|
return largePath;
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
export class LogoSize implements ActionInterface {
|
|
|
|
getName(): string { return "Logo sizes"; }
|
2020-08-07 14:39:46 +00:00
|
|
|
|
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
async fix(): Promise<void> {
|
|
|
|
const foundChains = readDirSync(chainsPath);
|
2020-08-07 14:39:46 +00:00
|
|
|
await checkDownsize(foundChains, false);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-08-07 14:39:46 +00:00
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
update = null;
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|