@@ -15,6 +15,7 @@ import (
1515 "github.com/zeromicro/go-zero/tools/goctl/util"
1616 "golang.org/x/tools/go/ast/astutil"
1717
18+ "github.com/jzero-io/jzero/cmd/jzero/internal/config"
1819 "github.com/jzero-io/jzero/cmd/jzero/internal/pkg/templatex"
1920)
2021
@@ -47,12 +48,12 @@ var (
4748 return err
4849 }
4950
50- _ = os .MkdirAll (filepath .Join ("internal" , "types" , goPackage ), 0o755 )
51+ _ = os .MkdirAll (filepath .Join (config . C . Gen . TypesDir , "types" , goPackage ), 0o755 )
5152 process , err := gosimports .Process ("" , typesGoBytes , nil )
5253 if err != nil {
5354 return err
5455 }
55- if err = os .WriteFile (filepath .Join ("internal" , "types" , goPackage , "types.go" ), process , 0o644 ); err != nil {
56+ if err = os .WriteFile (filepath .Join (config . C . Gen . TypesDir , "types" , goPackage , "types.go" ), process , 0o644 ); err != nil {
5657 return err
5758 }
5859 } else {
@@ -96,27 +97,33 @@ var (
9697 if err != nil {
9798 return err
9899 }
99- if err = os .WriteFile (filepath .Join ("internal" , "types" , "types.go" ), process , 0o644 ); err != nil {
100+ if err = os .WriteFile (filepath .Join (config . C . Gen . TypesDir , "types" , "types.go" ), process , 0o644 ); err != nil {
100101 return err
101102 }
102103 return nil
103104}
104105
105106func (ja * JzeroApi ) updateHandlerImportedTypesPath (f * ast.File , fset * token.FileSet , file HandlerFile ) error {
107+ typesImportPath := fmt .Sprintf ("%s/%s" , ja .Module , config .C .Gen .TypesDir )
106108 if astutil .UsesImport (f , fmt .Sprintf ("%s/internal/types" , ja .Module )) {
107109 astutil .DeleteImport (fset , f , fmt .Sprintf ("%s/internal/types" , ja .Module ))
108- astutil .AddNamedImport (fset , f , "types" , fmt .Sprintf ("%s/internal/types/%s" , ja .Module , file .Package ))
109110 }
111+ if astutil .UsesImport (f , typesImportPath ) {
112+ return nil
113+ }
114+ astutil .AddNamedImport (fset , f , "types" , fmt .Sprintf ("%s/%s/%s" , ja .Module , config .C .Gen .TypesDir , file .Package ))
110115
111116 return nil
112117}
113118
114119func (ja * JzeroApi ) updateLogicImportedTypesPath (f * ast.File , fset * token.FileSet , file LogicFile ) error {
115- astutil .DeleteImport (fset , f , fmt .Sprintf ("%s/internal/types" , ja .Module ))
120+ typesImportPath := fmt .Sprintf ("%s/%s" , ja .Module , config .C .Gen .TypesDir )
121+ oldImportPath := fmt .Sprintf ("%s/internal/types" , ja .Module )
122+ astutil .DeleteImport (fset , f , oldImportPath )
116123 if file .RequestType == nil && file .ResponseType == nil {
117124 return nil
118125 }
119- astutil .AddNamedImport (fset , f , "types" , fmt .Sprintf ("%s/internal/types/ %s" , ja .Module , file .Package ))
126+ astutil .AddNamedImport (fset , f , "types" , fmt .Sprintf ("%s/%s/ %s" , ja .Module , config . C . Gen . TypesDir , file .Package ))
120127 return nil
121128}
122129
0 commit comments