Skip to content

Commit

Permalink
feat(gen): chore pb path
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Jul 25, 2024
1 parent aa604a3 commit 05f7c73
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions internal/gen/genrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
goparser "go/parser"
"go/token"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -104,8 +103,6 @@ func (jr *JzeroRpc) Gen() error {
filepath.Join(embeded.Home, "go-zero"),
jr.Style)

fileBase := v[0 : len(v)-len(path.Ext(v))]

_, err = execx.Run(command, jr.Wd)
if err != nil {
return err
Expand Down Expand Up @@ -137,13 +134,16 @@ func (jr *JzeroRpc) Gen() error {

// # gen proto descriptor
if isNeedGenProtoDescriptor(parse) {
if !pathx.FileExists(generateProtoDescriptorPath(v)) {
_ = os.MkdirAll(filepath.Dir(generateProtoDescriptorPath(v)), 0o755)
}
isNeedGenerateProtoDescriptor = true
protocCommand := fmt.Sprintf("protoc --include_imports -I%s --descriptor_set_out=%s.pb %s",
protocCommand := fmt.Sprintf("protoc --include_imports -I%s --descriptor_set_out=%s %s",
protoDirPath,
fileBase,
generateProtoDescriptorPath(v),
v,
)
protoDescriptorPaths = append(protoDescriptorPaths, filepath.ToSlash(fmt.Sprintf("%s.pb", fileBase)))
protoDescriptorPaths = append(protoDescriptorPaths, generateProtoDescriptorPath(v))
_, err = execx.Run(protocCommand, jr.Wd)
if err != nil {
return err
Expand Down Expand Up @@ -177,7 +177,12 @@ func (jr *JzeroRpc) Gen() error {
}

func generateProtoDescriptorPath(protoPath string) string {
return ""
rel, err := filepath.Rel(filepath.Join("desc", "proto"), protoPath)
if err != nil {
return ""
}

return filepath.Join("desc", "pb", strings.TrimSuffix(rel, ".proto")+".pb")
}

func (jr *JzeroRpc) genServer(serverImports ImportLines, pbImports ImportLines, registerServers RegisterLines) error {
Expand Down

0 comments on commit 05f7c73

Please sign in to comment.