Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove properties #62

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading