feat: getting frontend dir, service binding

This commit is contained in:
2025-02-14 09:02:06 +07:00
parent d6825508e9
commit 013a3be72b
6 changed files with 48 additions and 13 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
main
main.exe
main.exe
frontend

View File

@@ -1,5 +0,0 @@
package structs
type Post struct {
title string `ui:"hidden,asd,ass=[s;s]"`
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -17,5 +17,6 @@ func main() {
structFields := utils.GetStructFields(file, structName)
generation.Generate(structName, structFields)
}
generation.Generate(structName, structFields)
}

View File

@@ -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
}