//go:build mage

package main

import (
	"io/fs"
	"path/filepath"

	"github.com/magefile/mage/sh"
)

func Protos() error {
	var fileNames []string

	filepath.WalkDir("pkgs/rpc", func(path string, d fs.DirEntry, err error) error {
		if d.IsDir() {
			return nil
		}
		if filepath.Ext(path) == ".proto" {
			fileNames = append(fileNames, path)
		}
		return nil
	})

	args := []string{"--go_out=.", "--go_opt=paths=source_relative", "--go-grpc_out=.", "--go-grpc_opt=paths=source_relative"}
	args = append(args, fileNames...)
	return sh.Run("protoc", args...)
}
