50 lines
1.5 KiB
Bash
Executable File
50 lines
1.5 KiB
Bash
Executable File
#! /bin/bash
|
|
|
|
check_imports() {
|
|
# 获取所有导入语句中的 service.* 文件
|
|
import_files=$(grep -E 'import ".*\.proto"' "$1" | awk -F'"' '{print $2}')
|
|
|
|
# 定义正则表达式匹配规则
|
|
pattern="^(\.\/)?([a-zA-Z_-]+\.proto)$"
|
|
|
|
# 声明数组变量
|
|
result=()
|
|
|
|
# 列出导入的 service.* 文件
|
|
for file in $import_files; do
|
|
if [[ $file =~ $pattern ]]; then
|
|
# 去除前缀 ./ 并添加到结果数组
|
|
result+=("${BASH_REMATCH[2]}")
|
|
fi
|
|
done
|
|
|
|
# 去重结果数组中的值
|
|
unique_result=($(echo "${result[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
|
|
|
|
# 返回去重后的结果数组
|
|
echo "${unique_result[@]}"
|
|
}
|
|
|
|
PROTO_DIR=./proto
|
|
SERVICE_NAME=auth
|
|
GO_PB_PATH=./gen/go/service/$SERVICE_NAME
|
|
mkdir $GO_PB_PATH -p
|
|
|
|
|
|
|
|
protoc -I $PROTO_DIR --go_out $GO_PB_PATH --go_opt paths=source_relative --go-grpc_out $GO_PB_PATH --go-grpc_opt paths=source_relative --grpc-gateway_out $GO_PB_PATH --grpc-gateway_opt paths=source_relative $SERVICE_NAME.proto
|
|
|
|
|
|
imports=$(check_imports $PROTO_DIR/$SERVICE_NAME.proto)
|
|
|
|
# $imports=(basic aa bb)
|
|
|
|
for import_file in $imports; do
|
|
SERVICE_NAME="${import_file%%.*}"
|
|
echo $SERVICE_NAME
|
|
GO_PB_PATH=./gen/go/service/$SERVICE_NAME
|
|
mkdir $GO_PB_PATH -p
|
|
protoc -I $PROTO_DIR --go_out $GO_PB_PATH --go_opt paths=source_relative --go-grpc_out $GO_PB_PATH --go-grpc_opt paths=source_relative --grpc-gateway_out $GO_PB_PATH --grpc-gateway_opt paths=source_relative $SERVICE_NAME.proto
|
|
done
|
|
|