convert proto to ts file using grpc ts tools

652 views Asked by At

I have a monorepo that is built using nxCloud. I have created a proto file in root directory inside a folder. The proto file is fine but since i need to import it in order to use its functions and for that purpose I need to convert it into ts file and I am trying to convert it by writing an sh script and i will execute it using git bash for now. But right now i ma getting errors related to path of my src and destination folders and i do not know where exactly the issue since i am no expert with .sh files. I need help to execute this script

Here is my sh code

#!/bin/bash

BASEDIR=$(dirname "$0")

cd ${BASEDIR}/../

PROTO_DEST=./src/proto

mkdir -p ${PROTO_DEST}

# JavaScript code generation
yarn run grpc_tools_node_protoc \
    --js_out=import_style=commonjs,binary:${PROTO_DEST} \
    --grpc_out=${PROTO_DEST} \
    --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin.cmd \
    -I ./proto \
    proto/*.proto
echo issueOccuredHere
# TypeScript code generation
yarn run grpc_tools_node_protoc \
    --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts.cmd \
    --ts_out=${PROTO_DEST} \
    -I ./proto \
    proto/*.proto

Errors

enter image description here

File levels

enter image description here

1

There are 1 answers

0
GryzLi On

In my opinion the issue could be related to directory try this

#!/bin/bash

BASEDIR=$(dirname "$0")

cd ${BASEDIR}/../

PROTO_DEST=./src/proto
PROTO_DIR=./protos/download-center
mkdir -p ${PROTO_DEST}

# JavaScript code generation
yarn run grpc_tools_node_protoc \
    --js_out=import_style=commonjs,binary:${PROTO_DEST} \
    --grpc_out=${PROTO_DEST} \
    --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin \
    -I ${PROTO_DIR} \
    ${PROTO_DIR}/*.proto
echo issueOccuredHere
# TypeScript code generation
yarn run grpc_tools_node_protoc \
    --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
    --ts_out=${PROTO_DEST} \
    -I ${PROTO_DIR} \
    ${PROTO_DIR}/*.proto