#!/usr/bin/env bash
#
# Dependencies:
#
# protobuf (pacman -S protobuf)
# protoc-gen-go (go install google.golang.org/protobuf/cmd/protoc-gen-go@latest)
# protoc-gen-go-grpc (go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest)
# ts-proto (uses local copy from node_modules)
#
set -ex

TARGET_BACKEND="./backend/generated"
TARGET_FRONTEND="./frontend/src/generated"

mkdir -p $TARGET_BACKEND
mkdir -p $TARGET_FRONTEND

protoc \
  -I./proto/ \
  --plugin="./frontend/node_modules/.bin/protoc-gen-ts_proto" \
  --go_out="$TARGET_BACKEND" \
  --go-grpc_out="$TARGET_BACKEND" \
  --js_out="import_style=commonjs,binary:$TARGET_FRONTEND" \
  --ts_proto_out="outputClientImpl=grpc-web,useOptionals=true,esModuleInterop=true:$TARGET_FRONTEND" \
  ./proto/*
