Check if all files have valid json (#1026)
* Check if all files have valid json * Optimised images with calibre/image-actions Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
| Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 40 KiB | 
| Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 15 KiB | 
| Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 24 KiB | 
| Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 33 KiB | 
| Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 6.4 KiB | 
| Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 30 KiB | 
| Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 5.0 KiB | 
| Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 22 KiB | 
| Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 55 KiB | 
| Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.5 KiB | 
| Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 41 KiB | 
| Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 22 KiB | 
| Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 15 KiB | 
| Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 62 KiB | 
| Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 33 KiB | 
| Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 5.1 KiB | 
| Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 15 KiB | 
| Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 1.7 KiB | 
| Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.7 KiB | 
| Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.8 KiB | 
| Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 1.7 KiB | 
| Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 7.2 KiB | 
| Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.1 KiB | 
| Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 4.7 KiB | 
|  | @ -1,4 +1,6 @@ | |||
| import * as fs from "fs" | ||||
| import * as path from "path" | ||||
| 
 | ||||
| const axios = require('axios') | ||||
| const Web3 = require('web3') | ||||
| const web3 = new Web3('ws://localhost:8546'); | ||||
|  | @ -25,7 +27,9 @@ const whiteList = 'whitelist.json' | |||
| const blackList = 'blacklist.json' | ||||
| 
 | ||||
| export const logo = `logo.png` | ||||
| export const root = './' | ||||
| export const chainsFolderPath = './blockchains' | ||||
| export const pricingFolderPath = './pricing' | ||||
| export const getChainLogoPath = chain => `${chainsFolderPath}/${chain}/info/${logo}` | ||||
| export const getChainAssetsPath = (chain: string): string => `${chainsFolderPath}/${chain}/assets` | ||||
| 
 | ||||
|  | @ -88,4 +92,32 @@ export const calculateAspectRatioFit = (srcWidth: number, srcHeight: number, max | |||
|     const ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight) | ||||
|     return { width: Math.round(srcWidth * ratio), height: Math.round(srcHeight * ratio) } | ||||
|  } | ||||
|   | ||||
|   | ||||
|  export const findFiles = (base: string, ext: string, files: string[] = [], result: string[] = []) => { | ||||
|     files = fs.readdirSync(base) || files | ||||
|     result = result || result | ||||
| 
 | ||||
|     files.forEach(  | ||||
|         function (file) { | ||||
|             var newbase = path.join(base, file) | ||||
|             if ( fs.statSync(newbase).isDirectory()) { | ||||
|                 result = findFiles(newbase, ext, fs.readdirSync(newbase), result) | ||||
|             } else { | ||||
|                 if ( file.substr(-1*(ext.length+1)) == '.' + ext) { | ||||
|                     result.push(newbase) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     ) | ||||
|     return result | ||||
|  } | ||||
| 
 | ||||
|  export const isValidJSON = (path: string) => { | ||||
|     let rawdata = fs.readFileSync(path, 'utf8') | ||||
|     try { | ||||
|         JSON.parse(rawdata) | ||||
|         return true | ||||
|     } catch { | ||||
|         return false | ||||
|     } | ||||
|  } | ||||
|  | @ -3,6 +3,7 @@ const eztz = require('eztz-lib') | |||
| import { | ||||
|     Ethereum, Binance, Cosmos, Tezos, Tron, IoTeX, Waves, Classic, POA, TomoChain, GoChain, Wanchain, ThunderCore, | ||||
|     chainsFolderPath, | ||||
|     pricingFolderPath, | ||||
|     getChainLogoPath, | ||||
|     getChainAssetsPath, | ||||
|     getChainAssetLogoPath, | ||||
|  | @ -19,7 +20,9 @@ import { | |||
|     isLogoOK, | ||||
|     getChainWhitelistPath, | ||||
|     getChainBlacklistPath, | ||||
|     mapList | ||||
|     mapList, | ||||
|     findFiles, | ||||
|     isValidJSON | ||||
| } from "./helpers" | ||||
| 
 | ||||
| enum TickerType { | ||||
|  | @ -326,3 +329,15 @@ describe.skip("Test blacklist and whitelist", () => { | |||
|     }) | ||||
| }) | ||||
| 
 | ||||
| describe("Test all JSON files to have valid content", () => { | ||||
| 
 | ||||
|     const files = [ | ||||
|         ...findFiles(chainsFolderPath, 'json'), | ||||
|         ...findFiles(pricingFolderPath, 'json') | ||||
|     ] | ||||
| 
 | ||||
|     files.forEach(file => {  | ||||
|         expect(isValidJSON(file), `${file} path contains invalid JSON`).toBe(true) | ||||
|     }); | ||||
| }) | ||||
| 
 | ||||
|  |  | |||
 Viktor Radchenko
						Viktor Radchenko