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

Auto generate protos on start/build #13

Merged
merged 1 commit into from
Oct 29, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions gen_protos.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

EXEC_PATH=${EXEC_PATH-.}

# Add the names of any services that have proto definitions to auto-genetate
#
# NOTE: The proto project's subdirectory MUST match the directory name of the
Expand All @@ -8,15 +10,15 @@ PROTO_SERVICE_NAMES=("auth-service" "db-service")

for service in ${PROTO_SERVICE_NAMES[@]}; do

mkdir -p ./packages/${service}/src/gen
mkdir -p ${EXEC_PATH}/packages/${service}/src/gen

protoc \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=./packages/${service}/src/gen \
--plugin=${EXEC_PATH}/node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=${EXEC_PATH}/packages/${service}/src/gen \
--ts_proto_opt=nestJs=true \
--ts_proto_opt=returnObservable=false \
-I ./packages/proto/${service}/ \
./packages/proto/${service}/*.proto
-I ${EXEC_PATH}/packages/proto/${service}/ \
${EXEC_PATH}/packages/proto/${service}/*.proto
done

# Add the names of any services that have proto definitions to auto-genetate that
Expand All @@ -27,15 +29,15 @@ PROTO_GW_SERVICES=("auth-service" "db-service")

for service in ${PROTO_GW_SERVICES[@]}; do

mkdir -p ./packages/api-gateway/src/${service}/gen
mkdir -p ${EXEC_PATH}/packages/api-gateway/src/${service}/gen

protoc \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=./packages/api-gateway/src/${service}/gen \
--plugin=${EXEC_PATH}/node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=${EXEC_PATH}/packages/api-gateway/src/${service}/gen \
--ts_proto_opt=nestJs=true \
--ts_proto_opt=returnObservable=false \
-I ./packages/proto/${service}/ \
./packages/proto/${service}/*.proto
-I ${EXEC_PATH}/packages/proto/${service}/ \
${EXEC_PATH}/packages/proto/${service}/*.proto
done

# Add the names of any services that have proto definitions to auto-genetate that
Expand All @@ -46,14 +48,14 @@ PROTO_AUTH_USED_SERVICES=()

for service in ${PROTO_AUTH_USED_SERVICES[@]}; do

mkdir -p ./packages/auth-service/src/${service}/gen
mkdir -p ${EXEC_PATH}/packages/auth-service/src/${service}/gen

protoc \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=./packages/auth-service/src/${service}/gen \
--plugin=${EXEC_PATH}/node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=${EXEC_PATH}/packages/auth-service/src/${service}/gen \
--ts_proto_opt=nestJs=true \
--ts_proto_opt=returnObservable=false \
-I ./packages/proto/${service}/ \
./packages/proto/${service}/*.proto
-I ${EXEC_PATH}/packages/proto/${service}/ \
${EXEC_PATH}/packages/proto/${service}/*.proto
done

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"format:write": "yarn prettier --write .",
"tsc": "nx run-many --target=tsc",
"lint": "nx run-many --target=lint",
"gen-proto": "./gen_protos.sh"
"gen-proto": "./gen_protos.sh && yarn format:write"
},
"devDependencies": {
"nx": "17.0.0",
Expand Down
11 changes: 6 additions & 5 deletions packages/api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"build": "yarn gen-proto && nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"gen-proto": "EXEC_PATH=../.. ../../gen_protos.sh && prettier --write ../",
"start": "yarn gen-proto && nest start",
"start:dev": "yarn start --watch",
"start:debug": "yarn start --debug --watch",
"start:prod": "yarn gen-proto && node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand Down
11 changes: 6 additions & 5 deletions packages/auth-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"build": "yarn gen-proto && nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"gen-proto": "EXEC_PATH=../.. ../../gen_protos.sh && prettier --write ../",
"start": "yarn gen-proto && nest start",
"start:dev": "yarn start --watch",
"start:debug": "yarn start --debug --watch",
"start:prod": "yarn gen-proto && node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand Down
11 changes: 6 additions & 5 deletions packages/db-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"build": "yarn gen-proto && nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"gen-proto": "EXEC_PATH=../.. ../../gen_protos.sh && prettier --write ../",
"start": "yarn gen-proto && nest start",
"start:dev": "yarn start --watch",
"start:debug": "yarn start --debug --watch",
"start:prod": "yarn gen-proto && node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand Down