Skip to content

Commit

Permalink
Merge pull request #104 from cosmology-tech/types/codegen
Browse files Browse the repository at this point in the history
cli for typegen
  • Loading branch information
pyramation committed Apr 24, 2024
2 parents bef5516 + 3a6b06e commit 181a14b
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 52 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/codegen-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Generate Types

on:
workflow_dispatch:

jobs:
generate-types:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4
with:
submodules: 'recursive' # Ensures submodules are also checked out

- name: Setup Node.js 🌐
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'

- name: Update Git Submodules 🔄
run: |
git submodule update --remote
cd packages/chain-registry/chain-registry
- name: Types Generation
run: |
git submodule update --remote
CHANGES_DESC="build-$(date +%Y%m%d-%H%M%S)"
yarn
yarn build
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor}}@users.noreply.github.com"
cd v2/types
yarn types
yarn build
cd ../../
cd v2/interfaces
yarn types
yarn build
cd ../../
git add .
if ! git diff --staged --quiet; then
git commit -am "build 🛠 $CHANGES_DESC"
git push origin main
echo "GIT_RESULT=Published." >> $GITHUB_ENV
else
echo "GIT_RESULT=No changes to commit." >> $GITHUB_ENV
fi
- name: Git Ops
run: |
echo $GIT_RESULT
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_SECRET}}
GH_TOKEN: ${{ secrets.GH_LERNA_PUBLISH_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Workflow Tests 🧪
name: Run Registry Tests 🧪

on:
pull_request:
Expand Down Expand Up @@ -28,7 +28,9 @@ jobs:
git checkout 5b5b73004a1acf84ed65694121828ddb6cb34de4
- name: Install Dependencies 🧶
run: yarn install
run: |
yarn install
yarn symlink
- name: Build Project 🏗️
run: yarn build
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"lerna": "^6",
"mkdirp": "3.0.1",
"prettier": "^3.0.2",
"strfy-js": "^1.5.0",
"strfy-js": "^2.2.2",
"strip-ansi": "^6",
"symlink-workspace": "^1.1.0",
"ts-jest": "^29.1.1",
Expand Down
4 changes: 4 additions & 0 deletions v2/interfaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
"copy": "copyfiles -f LICENSE README.md package.json dist",
"clean": "del dist/**",
"prepare": "npm run build",
"types": "chain-registry codegen --outputDir ./src/ --no-useCamelCase --registryDir ../../packages/chain-registry/chain-registry",
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
"test": "jest",
"test:watch": "jest --watch"
},
"devDependencies": {
"@chain-registry/cli": "1.27.0"
},
"keywords": [
"chain-registry",
"web3",
Expand Down
6 changes: 4 additions & 2 deletions v2/interfaces/src/assetlist.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Pointer } from "./shared";

export interface Asset {
deprecated?: boolean;
description?: string;
Expand Down Expand Up @@ -43,6 +41,10 @@ export interface DenomUnit {
exponent: number;
aliases?: string[];
}
export interface Pointer {
chain_name: string;
base_denom?: string;
}
export interface IbcTransition {
type: "ibc";
counterparty: {
Expand Down
6 changes: 4 additions & 2 deletions v2/interfaces/src/chain.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Pointer } from "./shared";

export interface Peer {
id: string;
address: string;
Expand Down Expand Up @@ -30,6 +28,10 @@ export interface FeeToken {
export interface StakingToken {
denom: string;
}
export interface Pointer {
chain_name: string;
base_denom?: string;
}
export interface Chain {
$schema?: string;
chain_name: string;
Expand Down
11 changes: 5 additions & 6 deletions v2/interfaces/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './assetlist.schema';
export * from './chain.schema';
export * from './ibc_data.schema';
export * from './memo_keys.schema';
export * from './shared';
export * from './versions.schema';
export { Asset, AssetList } from './assetlist.schema';
export { Chain } from './chain.schema';
export { IBCData } from './ibc_data.schema';
export { MemoKeys } from './memo_keys.schema';
export { Versions } from './versions.schema';
5 changes: 0 additions & 5 deletions v2/interfaces/src/shared.ts

This file was deleted.

4 changes: 4 additions & 0 deletions v2/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
"copy": "copyfiles -f LICENSE README.md package.json dist",
"clean": "del dist/**",
"prepare": "npm run build",
"types": "chain-registry codegen --outputDir ./src/ --useCamelCase --registryDir ../../packages/chain-registry/chain-registry",
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
"test": "jest",
"test:watch": "jest --watch"
},
"devDependencies": {
"@chain-registry/cli": "1.27.0"
},
"keywords": [
"chain-registry",
"web3",
Expand Down
6 changes: 4 additions & 2 deletions v2/types/src/assetlist.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Pointer } from "./shared";

export interface Asset {
deprecated?: boolean;
description?: string;
Expand Down Expand Up @@ -43,6 +41,10 @@ export interface DenomUnit {
exponent: number;
aliases?: string[];
}
export interface Pointer {
chainName: string;
baseDenom?: string;
}
export interface IbcTransition {
type: "ibc";
counterparty: {
Expand Down
6 changes: 4 additions & 2 deletions v2/types/src/chain.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Pointer } from "./shared";

export interface Peer {
id: string;
address: string;
Expand Down Expand Up @@ -30,6 +28,10 @@ export interface FeeToken {
export interface StakingToken {
denom: string;
}
export interface Pointer {
chainName: string;
baseDenom?: string;
}
export interface Chain {
schema?: string;
chainName: string;
Expand Down
11 changes: 5 additions & 6 deletions v2/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './assetlist.schema';
export * from './chain.schema';
export * from './ibc_data.schema';
export * from './memo_keys.schema';
export * from './shared';
export * from './versions.schema';
export { Asset, AssetList } from './assetlist.schema';
export { Chain } from './chain.schema';
export { IBCData } from './ibc_data.schema';
export { MemoKeys } from './memo_keys.schema';
export { Versions } from './versions.schema';
5 changes: 0 additions & 5 deletions v2/types/src/shared.ts

This file was deleted.

83 changes: 79 additions & 4 deletions workflows/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,89 @@
</p>

<p align="center" width="100%">
<a href="https://github.com/cosmology-tech/chain-registry/actions/cli/run-tests.yml">
<img height="20" src="https://github.com/cosmology-tech/chain-registry/actions/cli/run-tests.yml/badge.svg" />
<a href="https://github.com/cosmology-tech/chain-registry/actions/workflows/run-tests.yml">
<img height="20" src="https://github.com/cosmology-tech/chain-registry/actions/workflows/run-tests.yml/badge.svg" />
</a>
<a href="https://github.com/cosmology-tech/chain-registry/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
<a href="https://www.npmjs.com/package/@chain-registry/cli"><img height="20" src="https://img.shields.io/github/package-json/v/cosmology-tech/chain-registry?filename=packages%2Fcli%2Fpackage.json"></a>
<a href="https://www.npmjs.com/package/@chain-registry/cli"><img height="20" src="https://img.shields.io/github/package-json/v/cosmology-tech/chain-registry?filename=workflows%2Fcli%2Fpackage.json"></a>
</p>

TODO
The `@chain-registry/cli` is a powerful command-line interface designed to interact with the Chain Registry, allowing users to fetch information, validate data, and generate TypeScript interfaces directly from JSON schemas.

## Features

🔍 **Info**: Retrieve detailed information about chains, assets, and asset lists.

**Validate**: Check the integrity and validity of the registry data against its schemas.

🛠️ **Codegen**: Generate TypeScript definitions for use in development, ensuring type safety and adherence to the schema definitions.

## Installation

To get started with `@chain-registry/cli`, install it via npm or yarn:

```js
npm install @chain-registry/cli
# or
yarn add @chain-registry/cli
```

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Command Details](#command-details)
- [Info](#info)
- [Validate](#validate)
- [Codegen](#codegen)
- [Related Projects](#related)
- [Credits](#credits)
- [Disclaimer](#disclaimer)

## Command Details

### Info

Fetch and display information about entities in the chain registry:

```sh
chain-registry info
```

Options:

- `chain`: Fetch information specific to a chain.
- `asset-list`: Fetch asset lists associated with a specific chain.
- `asset`: Fetch detailed information about a specific asset.
- `--registryDir`: Path to the chain registry directory.

### Validate

Validate the data in the registry against the provided JSON schemas:

```sh
chain-registry validate
```

Options:

- `--outputDir`: Directory to output the generated TypeScript files.
- `--registryDir`: Path to the chain registry directory.

### Codegen

Generate TypeScript interfaces for the registry:

```sh
chain-registry codegen --outputDir ./src --registryDir /path/to/registry
```

Options:

- `--outputDir`: Directory to output the generated TypeScript files.
- `--registryDir`: Path to the chain registry directory.
- `--strictTypeSafety`: Enables strict TypeScript type definitions.
- `--useCamelCase`: Converts JSON schema properties to camelCase in the generated TypeScript files.

## Related

Expand Down
8 changes: 6 additions & 2 deletions workflows/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"module": "esm/index.js",
"types": "index.d.ts",
"bin": {
"registry": "cli.js"
"registry": "cli.js",
"chain-registry": "cli.js"
},
"publishConfig": {
"access": "public",
Expand Down Expand Up @@ -45,5 +46,8 @@
"web3",
"cosmos",
"interchain"
]
],
"devDependencies": {
"strfy-js": "^2.2.2"
}
}
Loading

0 comments on commit 181a14b

Please sign in to comment.