mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 19:10:35 +07:00
feat: getting frontend dir, service binding
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
main
|
main
|
||||||
main.exe
|
main.exe
|
||||||
|
frontend
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package structs
|
|
||||||
|
|
||||||
type Post struct {
|
|
||||||
title string `ui:"hidden,asd,ass=[s;s]"`
|
|
||||||
}
|
|
||||||
@@ -3,14 +3,15 @@ package generation
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"nto_cli/entities"
|
"nto_cli/entities"
|
||||||
|
"nto_cli/utils"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Generate(structName string, fields []entities.Field) {
|
func Generate(structName string, fields []entities.Field) {
|
||||||
mkName := strings.ToLower(fmt.Sprintf("./%s", structName))
|
mkPath := strings.ToLower(fmt.Sprintf("%s/frontend/%s", utils.FindFrontendPath() , structName))
|
||||||
if err := os.Mkdir(mkName, 0755); err != nil {
|
if err := os.Mkdir(mkPath, 0755); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
GenerateService(structName, mkName)
|
GenerateService(structName, mkPath)
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,19 @@ package generation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"nto_cli/utils"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateService(structName, mkName string) {
|
func GetServiceBindPath(structName string) string {
|
||||||
serviceFile, err := os.Create(mkName + "/" + strings.ToLower(structName) + ".service.ts")
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -17,5 +17,6 @@ func main() {
|
|||||||
|
|
||||||
structFields := utils.GetStructFields(file, structName)
|
structFields := utils.GetStructFields(file, structName)
|
||||||
|
|
||||||
generation.Generate(structName, structFields)
|
generation.Generate(structName, structFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
utils/find_frontend_path.go
Normal file
30
utils/find_frontend_path.go
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user