2023-10-23 10:27:42 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2023-10-24 03:20:42 +00:00
|
|
|
check_imports() {
|
|
|
|
# 获取所有导入语句中的 service.* 文件
|
|
|
|
import_files=$(grep -E 'import ".*\.proto"' "$1" | awk -F'"' '{print $2}')
|
|
|
|
|
|
|
|
# 定义正则表达式匹配规则
|
|
|
|
pattern="^(\.\/)?([a-zA-Z_-]+\.proto)$"
|
|
|
|
|
|
|
|
# 声明数组变量
|
|
|
|
result=()
|
2023-10-23 10:36:55 +00:00
|
|
|
|
2023-10-24 03:20:42 +00:00
|
|
|
# 列出导入的 service.* 文件
|
|
|
|
for file in $import_files; do
|
|
|
|
if [[ $file =~ $pattern ]]; then
|
|
|
|
# 去除前缀 ./ 并添加到结果数组
|
|
|
|
result+=("${BASH_REMATCH[2]}")
|
|
|
|
fi
|
|
|
|
done
|
2023-10-23 10:36:55 +00:00
|
|
|
|
2023-10-24 03:20:42 +00:00
|
|
|
# 去重结果数组中的值
|
|
|
|
unique_result=($(echo "${result[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
|
2023-10-23 10:36:55 +00:00
|
|
|
|
2023-10-24 03:20:42 +00:00
|
|
|
# 返回去重后的结果数组
|
|
|
|
echo "${unique_result[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
PROTO_DIR=./proto
|
|
|
|
SERVICE_NAME=auth
|
|
|
|
GO_PB_PATH=./gen/go/service/$SERVICE_NAME
|
2023-10-23 10:36:55 +00:00
|
|
|
mkdir $GO_PB_PATH -p
|
2023-10-24 03:20:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|