-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rebase nerve/typescriptDefinitions v14
- Loading branch information
Showing
3 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
name: Protobuf CI | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**/*.proto' | ||
branches: | ||
- '**' | ||
pull_request: | ||
paths: | ||
- '**/*.proto' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
generate_protobuf: | ||
name: Generate Protobuf Definitions | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Cache Protobuf Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-protobuf-cache-${{ hashFiles('**/package-lock.json') }} | ||
|
||
- name: Install Dependencies | ||
run: | | ||
npm ci | ||
- name: Generate Protobuf Definitions | ||
run: | | ||
npx protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \ | ||
--ts_out=./generated \ | ||
--proto_path=./proto \ | ||
$(find ./proto -name '*.proto') | ||
- name: Verify TypeScript Compilation | ||
run: | | ||
tsc --noEmit | ||
- name: Upload Protobuf Artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: protobuf-definitions | ||
path: ./generated | ||
|
||
publish_types: | ||
name: Publish TypeScript Definitions | ||
needs: generate_protobuf | ||
runs-on: ubuntu-latest | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Install Dependencies | ||
run: npm ci | ||
|
||
- name: Download Protobuf Artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: protobuf-definitions | ||
|
||
- name: Prepare TypeScript Definitions Package | ||
run: | | ||
mkdir -p ./dist | ||
cp -r ./generated ./dist/types | ||
cp ./typescript/package.json ./dist/package.json | ||
cp ./typescript/README.md ./dist/ | ||
- name: Publish TypeScript Definitions Package | ||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') | ||
run: | | ||
cd ./dist && npm publish --access public | ||
build_package: | ||
name: Build and Publish NPM Package | ||
needs: generate_protobuf | ||
runs-on: ubuntu-latest | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Ensure the token has minimal permissions and is stored securely | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Install Dependencies | ||
run: | | ||
npm ci | ||
- name: Download Protobuf Artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: protobuf-definitions | ||
|
||
- name: Prepare NPM Package | ||
run: | | ||
mkdir -p ./dist | ||
cp -r ./generated ./dist/protobuf | ||
cp package.json ./dist/ | ||
cp README.md ./dist/ | ||
- name: Build Package | ||
run: | | ||
cd ./dist && npm pack | ||
- name: Publish Package to NPM | ||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') | ||
run: | | ||
cd ./dist && npm publish --access public | ||
validate_compatibility: | ||
name: Validate Compatibility | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Install Dependencies | ||
run: | | ||
npm ci | ||
- name: Run Compatibility Tests | ||
run: | | ||
npm run test:compatibility | ||
release: | ||
name: Tag Release | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/tags/') | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Cache Protobuf Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-protobuf-cache-${{ hashFiles('**/package-lock.json') }} | ||
|
||
- name: Install Dependencies | ||
run: | | ||
npm ci | ||
- name: Generate Protobuf Definitions for Release | ||
run: | | ||
npx protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \ | ||
--ts_out=./generated \ | ||
--proto_path=./proto \ | ||
$(find ./proto -name '*.proto') | ||
- name: Package and Publish Release to NPM | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Ensure the token has minimal permissions and is stored securely | ||
run: | | ||
mkdir -p ./dist | ||
cp -r ./generated ./dist/protobuf | ||
cp package.json ./dist/ | ||
cp README.md ./dist/ | ||
cd ./dist && npm publish --access public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# @burnt-labs/xion-types | ||
|
||
TypeScript definitions for Xion Protobuf files. This package provides TypeScript type definitions generated from the Protobuf files used in the Xion project, enabling developers to work with Xion-related data structures in a type-safe way. | ||
|
||
## Table of Contents | ||
|
||
- [@burnt-labs/xion-types](#burnt-labsxion-types) | ||
- [Table of Contents](#table-of-contents) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Example](#example) | ||
- [Development](#development) | ||
- [License](#license) | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
Install the **@burnt-labs/xion-types** package via npm or yarn: | ||
|
||
```bash | ||
# Using npm | ||
npm install @burnt-labs/xion-types | ||
|
||
# Using yarn | ||
yarn add @burnt-labs/xion-types | ||
``` | ||
|
||
--- | ||
|
||
## Usage | ||
|
||
Once installed, you can import the type definitions in your TypeScript project. The types are generated from the Protobuf files used in the Xion project. | ||
|
||
```typescript | ||
import { MyProtobufType } from '@burnt-labs/xion-types/types/filename'; | ||
|
||
const myData: MyProtobufType = { | ||
field1: 'value', | ||
field2: 42 | ||
}; | ||
``` | ||
|
||
> **Note:** Replace `filename` with the appropriate file name where the type is defined. | ||
--- | ||
|
||
## Example | ||
|
||
Here is a full example of how you might use the **@burnt-labs/xion-types** package in a TypeScript project: | ||
|
||
```typescript | ||
import { MyProtobufType } from '@burnt-labs/xion-types/types/filename'; | ||
|
||
function processData(data: MyProtobufType): void { | ||
console.log(`Field 1: ${data.field1}`); | ||
console.log(`Field 2: ${data.field2}`); | ||
} | ||
|
||
const sampleData: MyProtobufType = { | ||
field1: 'Hello, Xion!', | ||
field2: 100 | ||
}; | ||
|
||
processData(sampleData); | ||
``` | ||
|
||
> This simple example illustrates how you can work with the types generated from Xion's Protobuf definitions. | ||
--- | ||
|
||
## Development | ||
|
||
If you want to modify or regenerate the TypeScript definitions from Protobuf files, follow these steps: | ||
|
||
1. **Clone the Repository** | ||
```bash | ||
git clone https://github.com/burnt-labs/xion.git | ||
cd xion | ||
``` | ||
|
||
2. **Install Dependencies** | ||
```bash | ||
npm install | ||
``` | ||
|
||
3. **Generate TypeScript Definitions** | ||
```bash | ||
npx protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \ | ||
--ts_out=./generated \ | ||
--proto_path=./proto \ | ||
$(find ./proto -name '*.proto') | ||
``` | ||
|
||
4. **Compile TypeScript Files** | ||
```bash | ||
tsc --noEmit | ||
``` | ||
|
||
> These steps will generate the TypeScript definitions from the Protobuf files located in the `proto` directory. | ||
--- | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the LICENSE file for details. | ||
|
||
--- | ||
|
||
For more information, check out [Xion's GitHub repository](https://github.com/burnt-labs/xion). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@burnt-labs/xion-types", | ||
"version": "1.0.0", | ||
"description": "TypeScript definitions for Xion Protobuf files", | ||
"main": "index.js", | ||
"types": "types/index.d.ts", | ||
"files": ["types/"], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest" | ||
}, | ||
"license": "MIT" | ||
} |