From 5562d9f985482b266cb7645f8843b977728b1ba2 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Sun, 17 Sep 2023 12:41:48 +0800 Subject: [PATCH] combine proto scripts --- scripts/create-proto-files.sh | 12 ----------- scripts/proto-gen.sh | 39 +++++++++++++++++++++++++++++++++++ scripts/remove-grpc.sh | 16 -------------- 3 files changed, 39 insertions(+), 28 deletions(-) delete mode 100755 scripts/create-proto-files.sh create mode 100755 scripts/proto-gen.sh delete mode 100755 scripts/remove-grpc.sh diff --git a/scripts/create-proto-files.sh b/scripts/create-proto-files.sh deleted file mode 100755 index ee3922e..0000000 --- a/scripts/create-proto-files.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# NOTE: protoc is required - -I=$(pwd)/proto -DEST_TS=$(pwd)/src/proto/ -mkdir -p $DEST_TS - -protoc \ - --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \ - --ts_out=$DEST_TS \ - --proto_path=$I \ - $(find $(pwd)/proto/vulcanize -iname "*.proto") diff --git a/scripts/proto-gen.sh b/scripts/proto-gen.sh new file mode 100755 index 0000000..d3c9060 --- /dev/null +++ b/scripts/proto-gen.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# NOTE: protoc is required + +set -e + +REPO_ROOT=$(pwd) +I=$REPO_ROOT/proto +DEST_TS=$REPO_ROOT/src/proto/ + +echo "Generating protobuf files" + +mkdir -p $DEST_TS + +protoc \ + --plugin=protoc-gen-ts=$REPO_ROOT/node_modules/.bin/protoc-gen-ts \ + --ts_out=$DEST_TS \ + --proto_path=$I \ + $(find $REPO_ROOT/proto/vulcanize -iname "*.proto") + +SED='sed -i' +if [[ "$OSTYPE" == "darwin"* ]]; then + SED='sed -i ""' +fi + +echo "Removing gRPC references..." + +for file in $(find $REPO_ROOT/src/proto -type f) +do + line=$(grep -n '@grpc/grpc-js' $file | cut -f1 -d':') + if [[ -n "$line" ]] && [[ "$line" -gt 0 ]]; then + echo "Processing file: $file" + $SED "${line}d" ${file} + functions=$(grep -n 'interface GrpcUnaryServiceInterface' $file | cut -f1 -d':') + $SED "${functions},\$d" ${file} + echo '}' >> $file + fi + $SED '1s#^#/* eslint-disable */\n#' $file + $SED '1s#^#// @ts-nocheck\n#' $file +done diff --git a/scripts/remove-grpc.sh b/scripts/remove-grpc.sh deleted file mode 100755 index c92ca12..0000000 --- a/scripts/remove-grpc.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -echo $PWD -for file in $(find src/proto -type f) -do - line=$(grep -n '@grpc/grpc-js' $file | cut -f1 -d':') - if [[ $line -gt 0 ]]; - then - echo "Processing file... $file" - sed -i "${line}d" ${file} - functions=$(grep -n 'interface GrpcUnaryServiceInterface' $file | cut -f1 -d':') - sed -i "${functions},\$d" ${file} - echo '}' >> $file - fi - sed -i '1s#^#/* eslint-disable */\n#' $file - sed -i '1s#^#// @ts-nocheck\n#' $file -done