|
1 | 1 | #!/usr/bin/env bash |
2 | | -# Regenerate Python gRPC stubs from proto/kakeya/v1/*.proto. |
| 2 | +# Regenerate gRPC stubs from proto/kakeya/v1/*.proto for every SDK. |
3 | 3 | # |
4 | | -# Generated files land in inference_engine/server/proto_gen/ and are |
5 | | -# committed to the repo. Re-run this script whenever a .proto file |
6 | | -# changes; CI's `proto-stub-drift` check verifies that the committed |
7 | | -# stubs are up-to-date by re-running the script and `git diff |
8 | | -# --exit-code`. |
| 4 | +# Targets: |
| 5 | +# * Python -> inference_engine/server/proto_gen/ (PR-A1) |
| 6 | +# * TypeScript -> sdks/typescript/src/proto_gen/ (PR-B5) |
| 7 | +# |
| 8 | +# Generated files are committed to the repo. Re-run this script |
| 9 | +# whenever a .proto file changes; CI's `proto-stub-drift` check |
| 10 | +# verifies that the committed stubs are byte-identical to what |
| 11 | +# this script produces. |
9 | 12 | # |
10 | 13 | # This is the canonical regeneration command. Do NOT invoke |
11 | | -# `python -m grpc_tools.protoc` ad-hoc — keep all flags here so they |
12 | | -# are reproducible across contributor machines and CI. |
| 14 | +# `protoc` ad-hoc — keep all flags here so they are reproducible |
| 15 | +# across contributor machines and CI. |
| 16 | +# |
| 17 | +# Prerequisites: |
| 18 | +# * Python: grpcio-tools (provides grpc_tools.protoc) |
| 19 | +# * TypeScript: ts-proto (installed in sdks/typescript/node_modules) |
13 | 20 |
|
14 | 21 | set -euo pipefail |
15 | 22 |
|
16 | 23 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
17 | 24 | PROTO_ROOT="$ROOT/proto" |
18 | 25 | OUT_ROOT="$ROOT/inference_engine/server/proto_gen" |
| 26 | +TS_OUT_ROOT="$ROOT/sdks/typescript/src/proto_gen" |
| 27 | +TS_PROTO_PLUGIN="$ROOT/sdks/typescript/node_modules/.bin/protoc-gen-ts_proto" |
19 | 28 |
|
20 | 29 | # Clean only generated files (preserve hand-written package __init__.py). |
21 | 30 | find "$OUT_ROOT" -type f \( -name '*_pb2.py' -o -name '*_pb2_grpc.py' -o -name '*_pb2.pyi' \) -delete 2>/dev/null || true |
@@ -57,4 +66,36 @@ if [ -f "$GRPC_FILE" ]; then |
57 | 66 | rm -f "$GRPC_FILE.bak" |
58 | 67 | fi |
59 | 68 |
|
60 | | -echo "Regenerated stubs into $OUT_ROOT" |
| 69 | +echo "Regenerated Python stubs into $OUT_ROOT" |
| 70 | + |
| 71 | +# ----------------------------------------------------------------------------- |
| 72 | +# TypeScript stubs (PR-B5) |
| 73 | +# ----------------------------------------------------------------------------- |
| 74 | + |
| 75 | +if [ -x "$TS_PROTO_PLUGIN" ]; then |
| 76 | + # Clean only generated TS files (preserve hand-written package |
| 77 | + # entry points — none today, but defensive). |
| 78 | + find "$TS_OUT_ROOT" -type f -name '*.ts' -delete 2>/dev/null || true |
| 79 | + mkdir -p "$TS_OUT_ROOT" |
| 80 | + |
| 81 | + # ts-proto generation flags worth pinning here: |
| 82 | + # esModuleInterop=true tsconfig has it; matching keeps imports clean. |
| 83 | + # forceLong=string uint64 / int64 -> string (JS number can't hold them). |
| 84 | + # useExactTypes=false ts-proto's stricter typing for oneof; we keep |
| 85 | + # the more ergonomic discriminated-union shape. |
| 86 | + # outputServices=grpc-js generate @grpc/grpc-js style client + server. |
| 87 | + # useOptionals=messages proto3 optional + message fields use TS optional. |
| 88 | + # stringEnums=false enums emit as integer constants (matches wire). |
| 89 | + # removeEnumPrefix=true strip the GenerateDone_ prefix from enum members. |
| 90 | + python3 -m grpc_tools.protoc \ |
| 91 | + --plugin="protoc-gen-ts_proto=$TS_PROTO_PLUGIN" \ |
| 92 | + --proto_path="$PROTO_ROOT" \ |
| 93 | + --ts_proto_out="$TS_OUT_ROOT" \ |
| 94 | + --ts_proto_opt=esModuleInterop=true,forceLong=string,outputServices=grpc-js,useOptionals=messages,stringEnums=false,removeEnumPrefix=true \ |
| 95 | + $(find "$PROTO_ROOT" -name '*.proto') |
| 96 | + |
| 97 | + echo "Regenerated TypeScript stubs into $TS_OUT_ROOT" |
| 98 | +else |
| 99 | + echo "WARN: ts-proto plugin not found at $TS_PROTO_PLUGIN; skipping TypeScript stub regen." >&2 |
| 100 | + echo " Run 'npm install' in sdks/typescript/ first." >&2 |
| 101 | +fi |
0 commit comments