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 buf proto generation #82

Merged
merged 1 commit into from
Oct 19, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion common/types/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,6 @@ FodyWeavers.xsd
### VisualStudio Patch ###
# Additional files built by Visual Studio

# End of https://www.toptal.com/developers/gitignore/api/visualstudio,macos,windows,node,webstorm+all
# End of https://www.toptal.com/developers/gitignore/api/visualstudio,macos,windows,node,webstorm+all

tmp
11 changes: 11 additions & 0 deletions common/types/buf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM bufbuild/buf:latest as BUILDER

RUN apk add --no-cache \
nodejs \
npm \
git \
make

RUN npm install -g ts-proto

COPY --from=BUILDER /usr/local/bin /usr/local/bin
6 changes: 6 additions & 0 deletions common/types/buf/buf.gen.client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v1
plugins:
- name: ts_proto
out: ../client
strategy: all
opt: esModuleInterop=true,forceLong=string,useOptionals=messages,snakeToCamel=false
6 changes: 6 additions & 0 deletions common/types/buf/buf.gen.lcd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v1
plugins:
- name: ts_proto
out: ../lcd
strategy: all
opt: esModuleInterop=true,forceLong=string,useOptionals=messages,snakeToCamel=false,stringEnums=true
3 changes: 3 additions & 0 deletions common/types/buf/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd proto
buf generate
cd ..
6 changes: 6 additions & 0 deletions common/types/buf/proto/import.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";

// Add imports here to generate the types from cosmos-sdk or any other proto files that you need

import "cosmos/gov/v1/tx.proto";

9 changes: 1 addition & 8 deletions common/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kyvejs/types",
"version": "1.0.3",
"version": "1.0.4",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": {
Expand All @@ -21,13 +21,6 @@
"lcd/",
"client/"
],
"dependencies": {
"@protobufs/cosmos": "^0.0.11",
"@protobufs/gogoproto": "^0.0.10",
"@protobufs/google": "^0.0.10",
"nx": "^14.4.3",
"ts-proto": "^1.115.4"
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^4.7.3"
Expand Down
73 changes: 42 additions & 31 deletions common/types/scripts/proto-gen.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
#!/bin/bash
rm -rf temp
mkdir temp

# Variables
KYVE_CHAIN_REPO="git@github.com:KYVENetwork/chain.git"
KYVE_CHAIN_VERSION="v1.3.0"
git -C ./temp clone -b ${KYVE_CHAIN_VERSION} --single-branch ${KYVE_CHAIN_REPO}
rm -rf ./src/client
rm -rf ./src/lcd
mkdir ./src/client
mkdir ./src/lcd
# generate TypeScript proto
PROTO_DIR="../../node_modules/@protobufs"
PROTOC_GEN_TS_PROTO_PATH="./node_modules/.bin/protoc-gen-ts_proto"
OUT_DIR="./src/client"
KYVE_PROTO='./temp/chain/proto'
protoc --plugin="protoc-gen-ts_proto=${PROTOC_GEN_TS_PROTO_PATH}" \
--ts_proto_out="${OUT_DIR}" \
--ts_proto_opt="esModuleInterop=true,forceLong=string,useOptionals=messages,snakeToCamel=false" \
--proto_path="$PROTO_DIR" \
--proto_path="$KYVE_PROTO" \
$(find ${PROTO_DIR} -path -prune -o -name '*.proto' -print0 | xargs -0) \
$(find ${KYVE_PROTO} -path -prune -o -name '*.proto' -print0 | xargs -0)

OUT_DIR_RES="./src/lcd"

protoc --plugin="protoc-gen-ts_proto=${PROTOC_GEN_TS_PROTO_PATH}" \
--ts_proto_out="${OUT_DIR_RES}" \
--ts_proto_opt="esModuleInterop=true,forceLong=string,useOptionals=messages,snakeToCamel=false,stringEnums=true" \
--proto_path="$PROTO_DIR" \
--proto_path="$KYVE_PROTO" \
$(find ${PROTO_DIR} -path -prune -o -name '*.proto' -print0 | xargs -0) \
$(find ${KYVE_PROTO} -path -prune -o -name '*.proto' -print0 | xargs -0)
rm -rf temp

echo "Cloning chain repo version ${KYVE_CHAIN_VERSION}"
mkdir -p ./tmp
git -C ./tmp clone -b ${KYVE_CHAIN_VERSION} --single-branch ${KYVE_CHAIN_REPO}

# Setup protobuf docker image and build proto files
cd tmp/chain
cp ../../buf/Dockerfile ./proto/Dockerfile
cp ../../buf/generate.sh ./proto/generate.sh
cp ../../buf/proto/import.proto ./proto/kyve/import.proto
make proto-setup

# Generate lcd proto files
echo "Generating proto files for lcd"
cp ../../buf/buf.gen.lcd.yaml ./proto/buf.gen.yaml
docker run --rm --volume "$(pwd)":/workspace --workdir /workspace kyve-proto sh ./proto/generate.sh

# Generate client proto files
echo "Generating proto files for client"
cp ../../buf/buf.gen.client.yaml ./proto/buf.gen.yaml
docker run --rm --volume "$(pwd)":/workspace --workdir /workspace kyve-proto sh ./proto/generate.sh

# Cleanup src folder
cd ../../
rm -rf ./src/*

# Copy generated files to src folder
cp -r tmp/chain/lcd ./src
cp -r tmp/chain/client ./src

# Delete some files that cause problems (we don't need them anyway)
rm -rf ./src/lcd/google/protobuf/descriptor.ts
rm -rf ./src/lcd/kyve/import.ts
rm -rf ./src/client/google/protobuf/descriptor.ts
rm -rf ./src/client/kyve/import.ts

# Set version
echo "export const version = \"${KYVE_CHAIN_VERSION}\"" > ./src/version.ts
git add ./src

# Cleanup
rm -rf ./tmp

git add ./src
167 changes: 0 additions & 167 deletions common/types/src/client/cosmos/app/v1alpha1/config.ts

This file was deleted.

Loading