mirror of
				https://github.com/Instadapp/trustwallet-assets.git
				synced 2024-07-29 22:37:31 +00:00 
			
		
		
		
	 e5cc13e032
			
		
	
	
		e5cc13e032
		
			
		
	
	
	
	
		
			
			* 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>
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import {
 | |
|     readFileSync,
 | |
|     writeFileSync
 | |
| } from "./filesystem";
 | |
| import { sortElements } from "./types";
 | |
| 
 | |
| export function isValidJSON(path: string): boolean {
 | |
|     try {
 | |
|         const rawdata = readFileSync(path);
 | |
|         JSON.parse(rawdata);
 | |
|         return true;
 | |
|     } catch {
 | |
|         return false;
 | |
|     }
 | |
| }
 | |
| 
 | |
| export function formatJson(content: unknown): string {
 | |
|     return JSON.stringify(content, null, 4);
 | |
| }
 | |
| 
 | |
| export function formatSortJson(content: unknown[]): string {
 | |
|     return JSON.stringify(sortElements(content), null, 4);
 | |
| }
 | |
| 
 | |
| // 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 {
 | |
|     writeFileSync(filename, formatSortJson(JSON.parse(readFileSync(filename))));
 | |
|     console.log(`Formatted json file ${filename}`);
 | |
| }
 | |
| 
 | |
| export function readJsonFile(path: string): unknown {
 | |
|     return JSON.parse(readFileSync(path));
 | |
| }
 | |
| 
 | |
| export function writeJsonFile(path: string, data: unknown): void {
 | |
|     writeFileSync(path, JSON.stringify(data, null, 4));
 | |
| }
 |