Skip to content

Commit

Permalink
feat: implement ts code generation (#184) (#138)
Browse files Browse the repository at this point in the history
* feat(ts): adds bare project (#184)

* feat(ts): adds make targets to setup/clean ts package (#184)

* feat(ts): adds generation to make (#184)

* feat(ts): generates code based on protobuf (#184)

* refactor(ts): generates files without failing Exact type (#184)

---------

Co-authored-by: Artur Troian <[email protected]>
  • Loading branch information
ygrishajev and troian authored Apr 4, 2024
1 parent 5d4de1d commit 14b1f7d
Show file tree
Hide file tree
Showing 157 changed files with 61,420 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ AKASH_DEVCACHE_INCLUDE=${AKASH_DEVCACHE}/include
AKASH_DEVCACHE_VERSIONS=${AKASH_DEVCACHE}/versions
AKASH_DEVCACHE_NODE_MODULES=${AKASH_DEVCACHE}
AKASH_DEVCACHE_NODE_BIN=${AKASH_DEVCACHE_NODE_MODULES}/node_modules/.bin
AKASH_TS_ROOT=${AKASH_ROOT}/ts
AKASH_TS_PACKAGE_FILE=${AKASH_TS_ROOT}/package.json
AKASH_TS_NODE_BIN=${AKASH_TS_ROOT}/node_modules/.bin
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export AKASH_DIRENV_SET

PATH_add "$AKASH_DEVCACHE_NODE_BIN"
PATH_add "$AKASH_DEVCACHE_BIN"
PATH_add "$AKASH_TS_NODE_BIN"

make cache
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ include $(AKASH_ROOT)/make/mod.mk
include $(AKASH_ROOT)/make/test.mk
include $(AKASH_ROOT)/make/codegen.mk
include $(AKASH_ROOT)/make/lint.mk

.PHONY: clean
clean:
rm -rf $(AKASH_DEVCACHE)
rm -rf $(AKASH_TS_ROOT)/node_modules
rm -rf $(AKASH_TS_ROOT)/dist

.PHONY: clean-codegen
clean-codegen:
rm -rf $(AKASH_TS_ROOT)/src/generated
4 changes: 3 additions & 1 deletion make/codegen.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: proto-gen
ifeq ($(PROTO_LEGACY), true)
proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC)
proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC) $(AKASH_TS_PACKAGE_FILE) clean-codegen
mkdir -p $(AKASH_TS_ROOT)/src/generated
./script/protocgen-legacy.sh
else
proto-gen: modvendor gogoproto $(BUF) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_GO)
Expand All @@ -21,3 +22,4 @@ codegen: proto-gen proto-gen-swagger mocks
changelog: $(GIT_CHGLOG)
@echo "generating changelog to changelog"
./script/changelog.sh $(shell git describe --tags --abbrev=0) changelog.md

5 changes: 5 additions & 0 deletions make/setup-cache.mk
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,8 @@ ifeq (, $(shell which swagger-combine 2>/dev/null))
else
@echo "swagger-combine already installed; skipping..."
endif

$(AKASH_TS_PACKAGE_FILE): $(AKASH_DEVCACHE)
@echo "installing node modules..."
cd $(AKASH_TS_ROOT) && npm install
@echo "node modules installed."
21 changes: 21 additions & 0 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ for dir in $proto_dirs; do
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--grpc-gateway_out=logtostderr=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')

.cache/bin/protoc \
-I "proto/node" \
-I ".cache/include/google/protobuf" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

proto_dirs=$(find ./proto/provider -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
Expand All @@ -53,6 +63,17 @@ for dir in $proto_dirs; do
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--grpc-gateway_out=logtostderr=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')

.cache/bin/protoc \
-I "proto/provider" \
-I "proto/node" \
-I ".cache/include" \
-I "vendor/github.com/cosmos/cosmos-sdk/proto" \
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

# move proto files to the right places
Expand Down
2 changes: 1 addition & 1 deletion script/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

unset FAILED

FILES=$(find /shellcheck/ -type f -name "*.sh" ! -path "/shellcheck/vendor/*" ! -path "/shellcheck/.git/*")
FILES=$(find /shellcheck/ -type f -name "*.sh" ! -path "/shellcheck/vendor/*" ! -path "/shellcheck/.git/*" ! -path "/shellcheck/ts/.husky/*")

for file in $FILES; do
name="$(basename "$file")";
Expand Down
20 changes: 20 additions & 0 deletions ts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"ignorePatterns": ["node_modules/", "build/", "umd/"],
"env": {
"node": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "ignoreRestSiblings": true }
]
}
}
39 changes: 39 additions & 0 deletions ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# compiled output
/dist
/build
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

.env.local
.env.*.local
1 change: 1 addition & 0 deletions ts/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ts/node_modules/.bin/lint-staged --cwd ts
4 changes: 4 additions & 0 deletions ts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
Loading

0 comments on commit 14b1f7d

Please sign in to comment.