mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
[Internal] Assets fix script: format all JSON files, not only eth-fork info files (#5853)
* Assets fix script: format all JSON files, not only eth-fork info files. * More debug message * Cleanup Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
f2739b230f
commit
e5cc13e032
|
@ -3,15 +3,12 @@ import {
|
|||
getChainAssetsPath,
|
||||
getChainAssetsList,
|
||||
getChainAssetPath,
|
||||
getChainAssetInfoPath,
|
||||
getChainAssetFilesList,
|
||||
isChainAssetInfoExistSync,
|
||||
logoName,
|
||||
logoExtension,
|
||||
logoFullName,
|
||||
getChainAssetLogoPath
|
||||
} from "../generic/repo-structure";
|
||||
import { formatJsonFile } from "../generic/json";
|
||||
import {
|
||||
getFileName,
|
||||
getFileExt,
|
||||
|
@ -23,22 +20,6 @@ import { toChecksum } from "../generic/eth-address";
|
|||
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
||||
import * as bluebird from "bluebird";
|
||||
|
||||
async function formatInfos() {
|
||||
console.log(`Formatting info files...`);
|
||||
await bluebird.each(ethForkChains, async (chain) => {
|
||||
let count = 0;
|
||||
const chainAssets = getChainAssetsList(chain);
|
||||
await bluebird.each(chainAssets, async (address) => {
|
||||
if (isChainAssetInfoExistSync(chain, address)) {
|
||||
const chainAssetInfoPath = getChainAssetInfoPath(chain, address);
|
||||
formatJsonFile(chainAssetInfoPath);
|
||||
++count;
|
||||
}
|
||||
})
|
||||
console.log(`Formatted ${count} info files for chain ${chain} (total ${chainAssets.length})`);
|
||||
})
|
||||
}
|
||||
|
||||
function checkAddressChecksum(assetsFolderPath: string, address: string, chain: string) {
|
||||
const checksumAddress = toChecksum(address, chain);
|
||||
if (checksumAddress !== address) {
|
||||
|
@ -101,7 +82,6 @@ export class EthForks implements ActionInterface {
|
|||
}
|
||||
|
||||
async sanityFix(): Promise<void> {
|
||||
await formatInfos();
|
||||
await checkAddressChecksums();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,26 @@
|
|||
import { chainsPath } from "../generic/repo-structure";
|
||||
import { findFiles } from "../generic/filesystem";
|
||||
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
||||
import { isValidJSON } from "../generic/json";
|
||||
import { formatJsonFile, isValidJSON } from "../generic/json";
|
||||
import * as bluebird from "bluebird";
|
||||
|
||||
async function formatInfos(): Promise<void> {
|
||||
console.log(`Formatting json files...`);
|
||||
|
||||
const files = [
|
||||
...findFiles(chainsPath, 'json'),
|
||||
];
|
||||
let count1 = 0;
|
||||
let count2 = 0;
|
||||
await bluebird.each(files, async (file) => {
|
||||
if (formatJsonFile(file)) {
|
||||
++count2;
|
||||
}
|
||||
++count1;
|
||||
});
|
||||
console.log(`Formatted ${count2} json files (total ${count1})`);
|
||||
}
|
||||
|
||||
export class JsonAction implements ActionInterface {
|
||||
getName(): string { return "Json files"; }
|
||||
|
||||
|
@ -27,4 +44,8 @@ export class JsonAction implements ActionInterface {
|
|||
},
|
||||
];
|
||||
}
|
||||
|
||||
async sanityFix(): Promise<void> {
|
||||
await formatInfos();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,16 @@ export function formatSortJson(content: unknown[]): string {
|
|||
return JSON.stringify(sortElements(content), null, 4);
|
||||
}
|
||||
|
||||
export function formatJsonFile(filename: string): void {
|
||||
writeFileSync(filename, formatJson(JSON.parse(readFileSync(filename))));
|
||||
// Return if updated
|
||||
export function formatJsonFile(filename: string): boolean {
|
||||
const origText: string = readFileSync(filename);
|
||||
const newText: string = formatJson(JSON.parse(origText));
|
||||
if (newText == origText) {
|
||||
return false;
|
||||
}
|
||||
writeFileSync(filename, newText);
|
||||
console.log(`Formatted json file ${filename}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function formatSortJsonFile(filename: string): void {
|
||||
|
|
Loading…
Reference in New Issue
Block a user