protoc generate grpc code code example

Example 1: protoc-gen-grpc

## Makefile Script

PROTO_DIR := ./proto
PROTO_GEN_GRPC := protoc-gen-grpc
PROTOC_GEN_GRPC_TS := protoc-gen-grpc-ts

protogen: cleanup.o generate.o

cleanup.o:
	rm ${PROTO_DIR}/*.{ts,js}

generate.o:
	# generate js codes
	${PROTO_GEN_GRPC} \
	--js_out=import_style=commonjs,binary:${PROTO_DIR} \
	--grpc_out=${PROTO_DIR} \
	--proto_path ${PROTO_DIR} \
	${PROTO_DIR}/*.proto

	# generate d.ts codes
	${PROTOC_GEN_GRPC_TS} \
	--ts_out=service=true:${PROTO_DIR} \
	--proto_path ${PROTO_DIR} \
	${PROTO_DIR}/*.proto

Example 2: grpc protoc gen

follow my repository for generate .protofile to javascript and typescript config

https://github.com/restuwahyu13/grpc-typescript-config

Tags:

Misc Example