Files
yatm/dev/generate.sh
T
Samuel Cui 4fef653b71 Prepare YATM v1.0.0-alpha.2
Unify file queries and Scan execution, retain indexed Identical results,
improve Job and Preview workflows, and verify release packaging.
2026-10-05 19:08:49 +08:00

56 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
REPO_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
(cd "$REPO_DIR" && go run ./dev/check-idl.go)
CURDIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../entity" && pwd);
cd "${CURDIR}";
SRC_DIR=${CURDIR};
GO_DST_DIR=${CURDIR};
# Retired protobuf sources must not leave callable generated services behind.
for artifact in "$CURDIR"/*.pb.go; do
[[ "$artifact" == *_grpc.pb.go ]] && continue
base=$(basename "$artifact" .pb.go)
[[ -f "$CURDIR/$base.proto" ]] && continue
for output in "$artifact" "$CURDIR/${base}_grpc.pb.go" "$CURDIR/../frontend/src/entity/${base}.ts" "$CURDIR/../frontend/src/entity/${base}.client.ts"; do
if [[ -f "$output" ]] && rg -q '@generated|Code generated' "$output"; then
rm -f -- "$output"
fi
done
for output in "$CURDIR/${base}.oneof_gen.go" "$CURDIR/../frontend/src/entity/${base}.oneof_gen.ts"; do
[[ -f "$output" ]] && rm -f -- "$output"
done
done
protoc --go_out="$GO_DST_DIR" --go_opt=paths=source_relative \
--go-grpc_out="$GO_DST_DIR" --go-grpc_opt=paths=source_relative \
-I="$SRC_DIR" "$SRC_DIR"/*.proto
# Remove only generated RPC artifacts whose source no longer declares a service.
for source in ./*.proto; do
if rg -q '^[[:space:]]*service[[:space:]]' "$source"; then
continue
fi
base=$(basename "$source" .proto)
for artifact in "$CURDIR/${base}_grpc.pb.go" "$CURDIR/../frontend/src/entity/${base}.client.ts"; do
if [[ -f "$artifact" ]] && rg -q '@generated|Code generated' "$artifact"; then
rm -f -- "$artifact"
fi
done
done
go generate ./...
# The frozen legacy wire adapter is generated independently of the current API.
LEGACY_DIR="$CURDIR/../internal/migrate/legacy/pb"
protoc --go_out="$LEGACY_DIR" --go_opt=paths=source_relative -I="$LEGACY_DIR" "$LEGACY_DIR/legacy.proto"
if [[ -f "$LEGACY_DIR/v1.pb.go" ]] && rg -q 'Code generated' "$LEGACY_DIR/v1.pb.go"; then
rm -f -- "$LEGACY_DIR/v1.pb.go"
fi
cd ../frontend;
pnpm run gen-proto;