Skip to content

Commit

Permalink
Refactor Types Generation Process (#769)
Browse files Browse the repository at this point in the history
* refactor: refactor: Simplify and correct the type generation process

* chore: rerun yarn install

* feat: automate version bumping and type release process

* feat: Bring metadata back for type automation

* chore: Try repo ci option

* chore: passing ci flag on the workflow

* feat: Add script to automate TS types generation

* docs: update README with new process for generating TS types

* fix: correct the link in README

* refactor: improve generate-ts-types script for local execution

* Merge `main` branch

* chore: run update types

* chore: update types

* feat: add github release
  • Loading branch information
AtelyPham authored Sep 25, 2024
1 parent c60215c commit 7fa3d6e
Show file tree
Hide file tree
Showing 36 changed files with 2,775 additions and 7,951 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/publish-types.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Publish Types

# If changes are made to the types package.json,
# If changes are made to the types/src/** files
# Issue a new release to npm for the types package.
on:
push:
branches:
- main
paths:
- "types/package.json"
- 'types/src/**'

jobs:
build:
Expand All @@ -21,17 +21,16 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Install npm dependencies
run: cd types && yarn install
- name: Configure Github Actions user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
- name: Run a build
run: cd types && yarn build
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
- name: Publish the package
run: cd types && yarn publish-types
run: cd types && yarn publish-types --ci
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions types/.release-it.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Config } from 'release-it'

export default {
hooks: {
'after:bump': 'yarn run build',
},
git: {
commitMessage: 'Release `tangle-substrate-types` v${version}',
tagName: '${npm.name}/v${version}',
tagAnnotation: 'Release ${npm.name} v${version}',
},
github: {
release: true,
releaseName: 'Release ${npm.name} v${version}',
},
npm: {
publish: true,
},
} satisfies Config
32 changes: 15 additions & 17 deletions types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ This package is meant to be updated alongside changes to the tangle runtime.

The package builds the types against the tangle standalone runtime.

### Update Types
### Updating Types

In order to update types after making changes to the Tangle APIs, do the following:
To update the types after modifying the Tangle APIs, follow these steps:

- Run a local instance of the appropriate runtime. The types in this package correspond to the tangle standalone runtime.
- Change your working directory into the `/types` folder (`cd types`).
- Install dependencies using `yarn`.
- Run the following yarn scripts:
```
yarn update:metadata
yarn build:interfaces
```
1. Build the `tangle` project with the testnet feature:

### Building the types package
```bash
cargo build --release --package tangle --features testnet
```

After updating the types, run a build for the package with
```
yarn build
```
2. Ensure you have [Node.js](https://nodejs.org/) version 18 or higher installed.

Note that you may run into some errors of missing imports while building. To resolve this, manually add the missing imports on the files with errors. If using VSCode, you can also use its `Add all missing imports` feature to speed up the process.
3. Generate the updated TypeScript types by running the `generate-ts-types.js` script:

```bash
node types/scripts/generate-ts-types.js
```

This process will automatically update the TypeScript types to reflect the latest changes in the Tangle APIs.

### Publishing and consuming types package

Once the types have been updated, open a new PR on this repository to submit your changes. Remember to update the types package's version. Once the PR is merged into the `master`, a GitHub Actions workflow will automatically publish them to NPM.

In case that you need to use or prototype the types before they are officially published to NPM, consider installing the package locally and using the local package until its updated version is published to NPM.
In case that you need to use or prototype the types before they are officially published to NPM, consider installing the package locally and using the local package until its updated version is published to NPM.
10 changes: 0 additions & 10 deletions types/babel-config-cjs.cjs

This file was deleted.

85 changes: 34 additions & 51 deletions types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,56 @@
"name": "@webb-tools/tangle-substrate-types",
"version": "0.5.12",
"description": "Polkadot.js type definitions required for interacting with Webb's tangle network",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"typings": "./build/index.d.ts",
"author": "Webb Developers <[email protected]>",
"license": "Apache-2.0",
"type": "commonjs",
"repository": "https://github.com/webb-tools/tangle.git",
"homepage": "https://github.com/webb-tools/tangle",
"files": [
"build"
],
"main": "./build/index.cjs",
"module": "./build/index.mjs",
"types": "./build/index.d.ts",
"exports": {
".": {
"types": "./build/index.d.ts",
"require": "./build/index.cjs",
"import": "./build/index.mjs",
"module": "./build/index.mjs"
}
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"repository": "https://github.com/webb-tools/tangle.git",
"bugs": {
"url": "https://github.com/webb-tools/tangle/issues"
},
"homepage": "https://github.com/webb-tools/tangle",
"scripts": {
"build": "bunchee",
"build:interfaces": "yarn build:interfaces:defs && yarn build:interfaces:chain",
"build:interfaces:defs": "tsx node_modules/.bin/polkadot-types-from-defs --input ./src/interfaces --package @webb-tools/tangle-substrate-types --endpoint ws://127.0.0.1:9944",
"build:interfaces:chain": "tsx node_modules/.bin/polkadot-types-from-chain --output ./src/interfaces --package @webb-tools/tangle-substrate-types --endpoint ws://127.0.0.1:9944",
"clean": "rm -rf build",
"publish-types": "release-it patch",
"update:metadata": "tsx ./scripts/updateMetadata.ts"
},
"dependencies": {
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-assertions": "^7.23.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-syntax-top-level-await": "^7.14.5",
"@babel/plugin-transform-regenerator": "^7.23.3",
"@babel/plugin-transform-runtime": "^7.24.0",
"@babel/preset-env": "^7.24.0",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/register": "^7.23.7",
"@babel/runtime": "^7.24.0",
"@open-web3/orml-types": "^2.0.1",
"@polkadot/api": "^11.0.2",
"@polkadot/dev": "^0.78.11",
"@polkadot/typegen": "^11.0.2",
"@polkadot/types": "^11.0.2",
"babel-jest": "^29.7.0",
"babel-plugin-module-extension-resolver": "^1.0.0",
"babel-plugin-module-resolver": "^5.0.0",
"babel-plugin-styled-components": "^2.1.4",
"@polkadot/api": "^13.2.1",
"@polkadot/typegen": "^13.2.1",
"@polkadot/types": "^13.2.1",
"ecpair": "^2.1.0",
"elliptic": "^6.5.5",
"fs-extra": "^11.2.0",
"glob2base": "^0.0.12",
"minimatch": "^9.0.3",
"mkdirp": "^3.0.1",
"tiny-secp256k1": "^2.2.3"
},
"devDependencies": {
"@types/websocket": "^1.0.10",
"@types/node": "^22.6.1",
"@types/ws": "^8.5.12",
"bunchee": "^5.4.0",
"prettier": "3.2.5",
"rimraf": "5.0.5",
"ts-node": "10.9.2",
"tsconfig-paths": "^4.2.0",
"release-it": "^17.6.0",
"tsx": "^4.19.1",
"typescript": "5.4.2",
"websocket": "^1.0.34"
},
"scripts": {
"build": "node ./scripts/build.js",
"build:interfaces": "yarn build:interfaces:defs && yarn build:interfaces:chain && rm ./src/interfaces/index.ts && rm ./src/interfaces/types.ts",
"build:interfaces:defs": "npx ts-node node_modules/.bin/polkadot-types-from-defs --input ./src/interfaces --package @webb-tools/tangle-substrate-types --endpoint ./src/metadata/metadata.json",
"build:interfaces:chain": "npx ts-node node_modules/.bin/polkadot-types-from-chain --endpoint ./src/metadata/metadata.json --output ./src/interfaces",
"clean": "rm -rf build && rm -rf ts-types",
"publish-types": "node ./scripts/publish-types.js",
"update:metadata": "npx ts-node ./scripts/updateMetadata.ts"
"ws": "^8.18.0"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
12 changes: 0 additions & 12 deletions types/polkadot-dev-configs/babel-config-cjs.cjs

This file was deleted.

15 changes: 0 additions & 15 deletions types/polkadot-dev-configs/babel-general.cjs

This file was deleted.

21 changes: 0 additions & 21 deletions types/polkadot-dev-configs/babel-plugins.cjs

This file was deleted.

33 changes: 0 additions & 33 deletions types/polkadot-dev-configs/babel-presets.cjs

This file was deleted.

14 changes: 0 additions & 14 deletions types/polkadot-dev-configs/babel-resolver.cjs

This file was deleted.

Loading

0 comments on commit 7fa3d6e

Please sign in to comment.