Skip to content

Commit

Permalink
remove properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Jan 25, 2024
1 parent 61c7f97 commit 6e0d58d
Show file tree
Hide file tree
Showing 6 changed files with 49,734 additions and 68,576 deletions.

This file was deleted.

This file was deleted.

68 changes: 23 additions & 45 deletions packages/chain-registry/scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fs = require('fs');
const deepmerge = require('deepmerge');
const glob = require('glob').sync;
const path = require('path');
const fs = require("fs");
const deepmerge = require("deepmerge");
const glob = require("glob").sync;
const path = require("path");

const NON_INFO_DIRS = ['_memo_keys', '_scripts', '_template', '.github'];
const NON_INFO_DIRS = ["_memo_keys", "_scripts", "_template", ".github"];

const paths = glob(`${__dirname}/../chain-registry/**/*.json`).filter((a) => {
let dir = a.split('chain-registry/chain-registry')[1];
let dir = a.split("chain-registry/chain-registry")[1];
dir = path.basename(path.dirname(dir));
return !NON_INFO_DIRS.includes(dir);
});
Expand All @@ -15,56 +15,34 @@ const assets = [];
const chains = [];
const ibcs = [];
paths.forEach((file) => {
const data = JSON.parse(fs.readFileSync(file, 'utf-8'));
const data = JSON.parse(fs.readFileSync(file, "utf-8"));
if (!data.$schema) {
console.warn('problematic data:');
console.warn("problematic data:");
console.log(data);
return;
}
if (data.$schema.endsWith('assetlist.schema.json')) assets.push(data);
if (data.$schema.endsWith('chain.schema.json')) chains.push(data);
if (data.$schema.endsWith('ibc_data.schema.json')) ibcs.push(data);
});

const addPaths = glob(`${__dirname}/../chain-registry-additions/**/*.json`);
const addAssets = [];
const addChains = [];
addPaths.forEach((file) => {
const data = JSON.parse(fs.readFileSync(file, 'utf-8'));
if (data.$schema === '../assetlist.schema.json') addAssets.push(data);
if (data.$schema === '../chain.schema.json') addChains.push(data);
});

addChains.forEach((chain) => {
const existingChainIndex = chains.findIndex(
(c) => c.chain_name === chain.chain_name
);
if (existingChainIndex > -1) {
const existingChain = chains[existingChainIndex];
chains[existingChainIndex] = deepmerge(existingChain, chain);
} else {
chains.push(chain);
}
if (data.$schema.endsWith("assetlist.schema.json")) assets.push(data);
if (data.$schema.endsWith("chain.schema.json")) chains.push(data);
if (data.$schema.endsWith("ibc_data.schema.json")) ibcs.push(data);
});

chains.forEach((chain) => {
if (!chain.slip44) chain.slip44 = 118;
});

addAssets.forEach((asset) => {
const existingIndex = assets.findIndex(
(c) => c.chain_name === asset.chain_name
);
if (existingIndex > -1) {
assets[existingIndex] = deepmerge(assets[existingIndex], asset);
} else {
assets.push(asset);
if (chain.codebase) {
chain.codebase = {
cosmos_sdk_version: chain.codebase.cosmos_sdk_version,
cosmwasm_enabled: chain.codebase.cosmwasm_enabled,
cosmwasm_version: chain.codebase.cosmwasm_version,
};
}

delete chain.peers;
});

const write = (file, json, TypeName, isArray = false) => {
const strfy = JSON.stringify(json, null, 2);
const exportType = isArray ? TypeName + '[]' : TypeName;
const exportType = isArray ? TypeName + "[]" : TypeName;
fs.writeFileSync(
`${__dirname}/../src/${file}.ts`,
`import { ${TypeName} } from '@chain-registry/types';
Expand All @@ -74,6 +52,6 @@ export default ${file};
);
};

write(`assets`, assets, 'AssetList', true);
write(`chains`, chains, 'Chain', true);
write(`ibc`, ibcs, 'IBCInfo', true);
write(`assets`, assets, "AssetList", true);
write(`chains`, chains, "Chain", true);
write(`ibc`, ibcs, "IBCInfo", true);
Loading

0 comments on commit 6e0d58d

Please sign in to comment.