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

feat: add support for ts satisfies operator #156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
120 changes: 56 additions & 64 deletions v1/packages/chain-registry/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const write = (filePath, json, TypeName, isArray = false) => {
fs.writeFileSync(
filePath,
`import { ${TypeName} } from '@chain-registry/types';
const info: ${exportType} = ${strfy};
const info = ${strfy} as const satisfies ${exportType};
export default info;`
);
};
Expand Down Expand Up @@ -54,16 +54,16 @@ ${
`
: ''
}${
chainObj.chain
? `export const chain = _chain;
chainObj.chain
? `export const chain = _chain;
`
: ''
}${
chainObj.ibc
? `export const ibc = _ibc;
: ''
}${
chainObj.ibc
? `export const ibc = _ibc;
`
: ''
}`
: ''
}`
);
};

Expand All @@ -87,15 +87,13 @@ const writeNetworkAssets = (filePath, networkObj) => {

fs.writeFileSync(
filePath,
`import { AssetList } from '@chain-registry/types';
`${importStat}

${importStat}

const assets: AssetList[] = [\n${validChain
.map((chain_name) => {
return ` _${chain_name}.assets`;
})
.join(',\n')}
const assets = [\n${validChain
.map((chain_name) => {
return ` _${chain_name}.assets`;
})
.join(',\n')}
];

export default assets;
Expand Down Expand Up @@ -126,15 +124,13 @@ const writeNetworkChains = (filePath, networkObj) => {

fs.writeFileSync(
filePath,
`import { Chain } from '@chain-registry/types';

${importStat}
`${importStat}

const chains: Chain[] = [\n${validChain
.map((chain_name) => {
return ` _${chain_name}.chain`;
})
.join(',\n')}
const chains = [\n${validChain
.map((chain_name) => {
return ` _${chain_name}.chain`;
})
.join(',\n')}
];

export default chains;
Expand Down Expand Up @@ -170,10 +166,10 @@ const writeNetworkIbc = (filePath, networkObj) => {
${importStat}

const ibc: IBCInfo[] = [\n${validChain
.map((chain_name) => {
return ` ..._${chain_name}.ibc`;
})
.join(',\n')}
.map((chain_name) => {
return ` ..._${chain_name}.ibc`;
})
.join(',\n')}
];

export default ibc;
Expand All @@ -200,17 +196,17 @@ const writeNamedIndex = (filePath, networkObj) => {
function createExports(isAssets: boolean, isChains: boolean, isIbc: boolean): string {
// Helper function to collect the export items based on conditions
function collectExports(items: { key: string, condition: boolean }[]): string {
return items
.filter(item => item.condition)
.map(item => item.key)
.join(', ');
return items
.filter(item => item.condition)
.map(item => item.key)
.join(', ');
}

// Define the items for export based on the input flags
const exportItems = [
{ key: 'assets', condition: isAssets },
{ key: 'chains', condition: isChains },
{ key: 'ibc', condition: isIbc }
{ key: 'assets', condition: isAssets },
{ key: 'chains', condition: isChains },
{ key: 'ibc', condition: isIbc }
];

// Collect the export strings
Expand Down Expand Up @@ -277,15 +273,13 @@ const writeRootAssets = (filePath, obj) => {

fs.writeFileSync(
filePath,
`import { AssetList } from '@chain-registry/types';

${importStat}
`${importStat}

const assets: AssetList[] = [\n${validNetwork
.map((network_type) => {
return ` ..._${network_type}.assets`;
})
.join(',\n')}
const assets = [\n${validNetwork
.map((network_type) => {
return ` ..._${network_type}.assets`;
})
.join(',\n')}
];

export default assets;
Expand Down Expand Up @@ -316,15 +310,13 @@ const writeRootChains = (filePath, obj) => {

fs.writeFileSync(
filePath,
`import { Chain } from '@chain-registry/types';

${importStat}
`${importStat}

const chains: Chain[] = [\n${validNetwork
.map((network_type) => {
return ` ..._${network_type}.chains`;
})
.join(',\n')}
const chains = [\n${validNetwork
.map((network_type) => {
return ` ..._${network_type}.chains`;
})
.join(',\n')}
];

export default chains;
Expand Down Expand Up @@ -360,10 +352,10 @@ const writeRootIbc = (filePath, obj) => {
${importStat}

const ibc: IBCInfo[] = [\n${validNetwork
.map((network_type) => {
return ` ..._${network_type}.ibc`;
})
.join(',\n')}
.map((network_type) => {
return ` ..._${network_type}.ibc`;
})
.join(',\n')}
];

export default ibc;
Expand Down Expand Up @@ -441,13 +433,13 @@ const paths = glob(`${registryDir}/**/*.json`)
.filter((a) => path.basename(a) !== 'package.json')
.filter((a) => path.basename(a) !== 'package-lock.json')
.filter((a) => {
const splitedDirs = a.split(registryDirInRepoPath);
const filePath = splitedDirs.pop();
const dir = path.basename(path.dirname(filePath));
return (
!NON_INFO_DIRS.includes(dir) && path.basename(filePath) !== 'chain.json'
);
});
const splitedDirs = a.split(registryDirInRepoPath);
const filePath = splitedDirs.pop();
const dir = path.basename(path.dirname(filePath));
return (
!NON_INFO_DIRS.includes(dir) && path.basename(filePath) !== 'chain.json'
);
});

const chainNetworkMap = {};

Expand Down Expand Up @@ -600,4 +592,4 @@ const indexFilePath = path.join(SRC_ROOT, 'index.ts');
writeRootIndex(indexFilePath);

const namedFilePath = path.join(SRC_ROOT, 'named.ts');
writeRootNamedFile(namedFilePath, result);
writeRootNamedFile(namedFilePath, result);
Loading