2020-07-29 13:42:51 +00:00
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
import {
|
2020-10-19 22:51:47 +00:00
|
|
|
allChains,
|
2020-07-29 13:42:51 +00:00
|
|
|
getChainLogoPath,
|
|
|
|
getChainAssetsPath,
|
|
|
|
getChainAssetLogoPath,
|
|
|
|
getChainValidatorsListPath,
|
2021-02-26 11:39:39 +00:00
|
|
|
getChainValidatorAssetLogoPath,
|
|
|
|
dappsPath
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/repo-structure";
|
2020-07-29 13:42:51 +00:00
|
|
|
import {
|
|
|
|
readDirSync,
|
|
|
|
readFileSync,
|
|
|
|
isPathExistsSync
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/filesystem";
|
|
|
|
import { checkResizeIfTooLarge } from "../generic/image";
|
|
|
|
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
2020-07-29 13:42:51 +00:00
|
|
|
|
2020-08-07 14:39:46 +00:00
|
|
|
// return name of large logo, or empty
|
2021-02-26 11:39:39 +00:00
|
|
|
async function checkDownsize(chains: string[], checkOnly: boolean): Promise<string[]> {
|
2020-08-07 14:39:46 +00:00
|
|
|
console.log(`Checking all logos for size ...`);
|
2020-09-18 14:39:31 +00:00
|
|
|
let totalCountChecked = 0;
|
|
|
|
let totalCountTooLarge = 0;
|
|
|
|
let totalCountUpdated = 0;
|
|
|
|
const largePaths: string[] = [];
|
2021-02-26 11:39:39 +00:00
|
|
|
|
|
|
|
// Check asset logos, under given chains
|
2020-07-29 13:42:51 +00:00
|
|
|
await bluebird.map(chains, async chain => {
|
2020-09-18 14:39:31 +00:00
|
|
|
let countChecked = 0;
|
|
|
|
let countTooLarge = 0;
|
|
|
|
let countUpdated = 0;
|
2020-07-29 13:42:51 +00:00
|
|
|
|
|
|
|
const path = getChainLogoPath(chain);
|
|
|
|
countChecked++;
|
2020-08-07 14:39:46 +00:00
|
|
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
2020-09-16 12:52:10 +00:00
|
|
|
if (tooLarge) { largePaths.push(path); }
|
2020-08-07 14:39:46 +00:00
|
|
|
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);
|
2020-09-16 12:52:10 +00:00
|
|
|
if (tooLarge) { largePaths.push(path); }
|
2020-08-07 14:39:46 +00:00
|
|
|
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);
|
2020-09-16 12:52:10 +00:00
|
|
|
if (tooLarge) { largePaths.push(path); }
|
2020-08-07 14:39:46 +00:00
|
|
|
countTooLarge += tooLarge ? 1 : 0;
|
|
|
|
countUpdated += updated ? 1 : 0;
|
2021-02-26 11:39:39 +00:00
|
|
|
});
|
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) {
|
2020-09-16 12:52:10 +00:00
|
|
|
console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countTooLarge} too large, ${largePaths}, ${countUpdated} logos updated`);
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|
|
|
|
});
|
2021-02-26 11:39:39 +00:00
|
|
|
|
|
|
|
// Check dapps logos
|
|
|
|
if (isPathExistsSync(dappsPath)) {
|
|
|
|
let countChecked = 0;
|
|
|
|
let countTooLarge = 0;
|
|
|
|
let countUpdated = 0;
|
|
|
|
|
|
|
|
await bluebird.mapSeries(readDirSync(dappsPath), async filename => {
|
|
|
|
const path = dappsPath + `/` + filename;
|
|
|
|
countChecked++;
|
|
|
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
|
|
|
if (tooLarge) { largePaths.push(path); }
|
|
|
|
countTooLarge += tooLarge ? 1 : 0;
|
|
|
|
countUpdated += updated ? 1 : 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
totalCountChecked += countChecked;
|
|
|
|
totalCountTooLarge += countTooLarge;
|
|
|
|
totalCountUpdated += countUpdated;
|
|
|
|
if (countTooLarge > 0 || countUpdated > 0) {
|
|
|
|
console.log(`Checking dapps logos completed, ${countChecked} checked, ${countTooLarge} too large, ${largePaths}, ${countUpdated} logos updated`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 14:39:46 +00:00
|
|
|
console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountTooLarge} too large, ${totalCountUpdated} logos updated`);
|
2020-09-16 12:52:10 +00:00
|
|
|
return largePaths;
|
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
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getSanityChecks(): CheckStepInterface[] {
|
2020-08-07 14:39:46 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
getName: () => { return "Check that logos are not too large"},
|
|
|
|
check: async () => {
|
2020-10-19 22:51:47 +00:00
|
|
|
const largePaths = await checkDownsize(allChains, true);
|
2020-09-16 12:52:10 +00:00
|
|
|
const errors: string[] = largePaths.map(p => `Logo too large: ${p}`);
|
|
|
|
return [errors, []];
|
2020-08-07 14:39:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
async sanityFix(): Promise<void> {
|
2020-10-19 22:51:47 +00:00
|
|
|
await checkDownsize(allChains, false);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|