diff --git a/.gitignore b/.gitignore index e3a7f03..7f6e98f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ main -main.exe \ No newline at end of file +main.exe +frontend \ No newline at end of file diff --git a/example_structs/post.go b/example_structs/post.go deleted file mode 100644 index 9a04eb8..0000000 --- a/example_structs/post.go +++ /dev/null @@ -1,5 +0,0 @@ -package structs - -type Post struct { - title string `ui:"hidden,asd,ass=[s;s]"` -} \ No newline at end of file diff --git a/generation/gen.go b/generation/gen.go index 8328bbc..77565e9 100644 --- a/generation/gen.go +++ b/generation/gen.go @@ -3,14 +3,15 @@ package generation import ( "fmt" "nto_cli/entities" + "nto_cli/utils" "os" "strings" ) func Generate(structName string, fields []entities.Field) { - mkName := strings.ToLower(fmt.Sprintf("./%s", structName)) - if err := os.Mkdir(mkName, 0755); err != nil { + mkPath := strings.ToLower(fmt.Sprintf("%s/frontend/%s", utils.FindFrontendPath() , structName)) + if err := os.Mkdir(mkPath, 0755); err != nil { panic(err) } - GenerateService(structName, mkName) + GenerateService(structName, mkPath) } \ No newline at end of file diff --git a/generation/service.go b/generation/service.go index 6da6d8b..911f90f 100644 --- a/generation/service.go +++ b/generation/service.go @@ -2,12 +2,19 @@ package generation import ( "fmt" + "nto_cli/utils" "os" "strings" ) -func GenerateService(structName, mkName string) { - serviceFile, err := os.Create(mkName + "/" + strings.ToLower(structName) + ".service.ts") +func GetServiceBindPath(structName string) string { + path := utils.FindFrontendPath() + path += fmt.Sprintf("/bindings/app/internal/services/%sservice.ts", strings.ToLower(structName)) + return path +} + +func GenerateService(structName, mkPath string) { + serviceFile, err := os.Create(mkPath + "/" + strings.ToLower(structName) + ".service.ts") if err != nil { panic(err) } diff --git a/main.go b/main.go index a8b776a..e79a94b 100644 --- a/main.go +++ b/main.go @@ -17,5 +17,6 @@ func main() { structFields := utils.GetStructFields(file, structName) - generation.Generate(structName, structFields) -} + generation.Generate(structName, structFields) + } + diff --git a/utils/find_frontend_path.go b/utils/find_frontend_path.go new file mode 100644 index 0000000..512b423 --- /dev/null +++ b/utils/find_frontend_path.go @@ -0,0 +1,30 @@ +package utils + +import ( + "errors" + "os" + "slices" + "strings" +) + +func FindFrontendPath() string { + currentPath, err := os.Getwd() + if err != nil { + panic(err) + } + dirs := strings.Split(currentPath, "\\") + if !slices.Contains(dirs, "frontend") { + panic(errors.New("Frontend dir doesn't exist")) + } + var path string + for i, dir := range dirs { + if dir == "frontend" { + break + } + if i > 0 { + dir = "/" + dir + } + path += dir + } + return path +} \ No newline at end of file