Skip to content

Commit

Permalink
fix(gen): fix #217
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Feb 23, 2025
1 parent b069d96 commit 80ba76b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
8 changes: 3 additions & 5 deletions internal/gen/genapi/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,20 @@ type JzeroApi struct {
}

func (ja *JzeroApi) Gen() error {
apiDirName := filepath.Join("desc", "api")

if !pathx.FileExists(apiDirName) {
if !pathx.FileExists(config.C.ApiDir()) {
return nil
}

fmt.Printf("%s to generate api code.\n", color.WithColor("Start", color.FgGreen))

// format api dir
command := fmt.Sprintf("goctl api format --dir %s", apiDirName)
command := fmt.Sprintf("goctl api format --dir %s", config.C.ApiDir())
_, err := execx.Run(command, config.C.Wd())
if err != nil {
return err
}

apiFiles, err := desc.FindApiFiles(apiDirName)
apiFiles, err := desc.FindApiFiles(config.C.ApiDir())
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions internal/gen/genmodel/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (jm *JzeroModel) Gen() error {
}
}

sqlDir := filepath.Join("desc", "sql")
if !pathx.FileExists(sqlDir) {
if !pathx.FileExists(config.C.SqlDir()) {
return nil
}

Expand All @@ -100,14 +99,14 @@ func (jm *JzeroModel) Gen() error {
)
genCodeSqlSpecMap := make(map[string][]*parser.Table)

allFiles, err = jzerodesc.FindSqlFiles(sqlDir)
allFiles, err = jzerodesc.FindSqlFiles(config.C.SqlDir())
if err != nil {
return err
}

switch {
case config.C.Gen.GitChange && len(config.C.Gen.Desc) == 0 && !config.C.Gen.ModelMysqlDatasource:
m, _, err := gitstatus.ChangedFiles("desc", ".sql")
m, _, err := gitstatus.ChangedFiles(config.C.SqlDir(), ".sql")
if err == nil {
genCodeSqlFiles = append(genCodeSqlFiles, m...)
}
Expand All @@ -126,7 +125,7 @@ func (jm *JzeroModel) Gen() error {
}
}
default:
genCodeSqlFiles, err = jzerodesc.FindSqlFiles(sqlDir)
genCodeSqlFiles, err = jzerodesc.FindSqlFiles(config.C.SqlDir())
if err != nil {
return err
}
Expand Down
18 changes: 8 additions & 10 deletions internal/gen/genrpc/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ type JzeroRpc struct {
}

func (jr *JzeroRpc) Gen() error {
protoDirPath := filepath.Join("desc", "proto")

var (
serverImports jzerodesc.ImportLines
pbImports jzerodesc.ImportLines
registerServers jzerodesc.RegisterLines
)

// 获取全量 proto 文件
protoFiles, err := jzerodesc.GetProtoFilepath(protoDirPath)
protoFiles, err := jzerodesc.GetProtoFilepath(config.C.ProtoDir())
if err != nil {
return err
}
Expand Down Expand Up @@ -165,8 +163,8 @@ func (jr *JzeroRpc) Gen() error {
zrpcOut := "."
command := fmt.Sprintf("goctl rpc protoc %s -I%s -I%s --go_out=%s --go-grpc_out=%s --zrpc_out=%s --client=%t --home %s -m --style %s ",
v,
protoDirPath,
filepath.Join(protoDirPath, "third_party"),
config.C.ProtoDir(),
filepath.Join(config.C.ProtoDir(), "third_party"),
filepath.Join("internal"),
filepath.Join("internal"),
zrpcOut,
Expand Down Expand Up @@ -198,8 +196,8 @@ func (jr *JzeroRpc) Gen() error {
if lo.Contains(genCodeProtoFiles, v) {
command := fmt.Sprintf("protoc %s -I%s -I%s --validate_out=%s",
v,
protoDirPath,
filepath.Join(protoDirPath, "third_party"),
config.C.ProtoDir(),
filepath.Join(config.C.ProtoDir(), "third_party"),
"lang=go:internal",
)
_, err = execx.Run(command, config.C.Wd())
Expand Down Expand Up @@ -262,8 +260,8 @@ func (jr *JzeroRpc) Gen() error {
_ = os.MkdirAll(filepath.Dir(getProtoDescriptorPath(v)), 0o755)
}
protocCommand := fmt.Sprintf("protoc --include_imports -I%s -I%s --descriptor_set_out=%s %s",
protoDirPath,
filepath.Join(protoDirPath, "third_party"),
config.C.ProtoDir(),
filepath.Join(config.C.ProtoDir(), "third_party"),
getProtoDescriptorPath(v),
v,
)
Expand All @@ -290,7 +288,7 @@ func (jr *JzeroRpc) Gen() error {
fmt.Println(color.WithColor("Done", color.FgGreen))
}

if pathx.FileExists(protoDirPath) {
if pathx.FileExists(config.C.ProtoDir()) {
if err = jr.genServer(serverImports, pbImports, registerServers); err != nil {
return err
}
Expand Down

0 comments on commit 80ba76b

Please sign in to comment.