mirror of
				https://github.com/Instadapp/trustwallet-assets.git
				synced 2024-07-29 22:37:31 +00:00 
			
		
		
		
	* 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>
		
			
				
	
	
		
			69 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import * as bluebird from "bluebird";
 | 
						|
import {
 | 
						|
    chainsPath,
 | 
						|
    getChainLogoPath,
 | 
						|
    getChainAssetsPath,
 | 
						|
    getChainAssetLogoPath,
 | 
						|
    getChainValidatorsListPath,
 | 
						|
    getChainValidatorAssetLogoPath
 | 
						|
} from "../common/repo-structure";
 | 
						|
import {
 | 
						|
    readDirSync,
 | 
						|
    readFileSync,
 | 
						|
    isPathExistsSync
 | 
						|
} from "../common/filesystem";
 | 
						|
import { resizeIfTooLarge } from "../common/image";
 | 
						|
import { ActionInterface } from "./interface";
 | 
						|
 | 
						|
async function downsize(chains) {
 | 
						|
    console.log(`Checking all logos for downsizing ...`);
 | 
						|
    let totalCountChecked: number = 0;
 | 
						|
    let totalCountUpdated: number = 0;
 | 
						|
    await bluebird.map(chains, async chain => {
 | 
						|
        let countChecked: number = 0;
 | 
						|
        let countUpdated: number = 0;
 | 
						|
 | 
						|
        const path = getChainLogoPath(chain);
 | 
						|
        countChecked++;
 | 
						|
        countUpdated += await resizeIfTooLarge(path) ? 1 : 0;
 | 
						|
                
 | 
						|
        // 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++;
 | 
						|
                countUpdated += await resizeIfTooLarge(path) ? 1 : 0;
 | 
						|
            })
 | 
						|
        }
 | 
						|
 | 
						|
        // 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++;
 | 
						|
                countUpdated += await resizeIfTooLarge(path) ? 1 : 0;
 | 
						|
            })
 | 
						|
        }
 | 
						|
 | 
						|
        totalCountChecked += countChecked;
 | 
						|
        totalCountUpdated += countUpdated;
 | 
						|
        if (countUpdated > 0) {
 | 
						|
            console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countUpdated} logos updated`);
 | 
						|
        }
 | 
						|
    });
 | 
						|
    console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountUpdated} logos updated`);
 | 
						|
}
 | 
						|
 | 
						|
export class LogoSize implements ActionInterface {
 | 
						|
    getName(): string { return "Logo sizes"; }
 | 
						|
    getChecks = null;
 | 
						|
    async fix(): Promise<void> {
 | 
						|
        const foundChains = readDirSync(chainsPath);
 | 
						|
        await downsize(foundChains);
 | 
						|
    }
 | 
						|
    update = null;
 | 
						|
}
 |