feat: relatives paths

This commit is contained in:
2025-02-14 13:26:44 +07:00
parent 013a3be72b
commit 8290462d92
5 changed files with 42 additions and 24 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
main main
main.exe main.exe
frontend frontend
task.py

View File

@@ -1,8 +1,7 @@
package entities package entities
type Field struct { type Field struct {
Name string Name string
Type string Type string
Medatada []Medatada Medatada []Medatada
} }

View File

@@ -9,7 +9,7 @@ import (
) )
func Generate(structName string, fields []entities.Field) { func Generate(structName string, fields []entities.Field) {
mkPath := strings.ToLower(fmt.Sprintf("%s/frontend/%s", utils.FindFrontendPath() , structName)) mkPath := strings.ToLower(fmt.Sprintf("%s/frontend/src/%s", utils.FindFrontendPath() , structName))
if err := os.Mkdir(mkPath, 0755); err != nil { if err := os.Mkdir(mkPath, 0755); err != nil {
panic(err) panic(err)
} }

View File

@@ -2,14 +2,22 @@ package generation
import ( import (
"fmt" "fmt"
"nto_cli/utils"
"os" "os"
"strings" "strings"
) )
func GetServiceBindPath(structName string) string { func GetServiceBindPath(structName string) string {
path := utils.FindFrontendPath() path := fmt.Sprintf("../bindings/app/internal/services/%sservice.ts", strings.ToLower(structName))
path += fmt.Sprintf("/bindings/app/internal/services/%sservice.ts", strings.ToLower(structName)) return path
}
func GetServiceStructType(structName string) string {
path := "../bindings/app/internal/services/models.ts"
return path
}
func GetServiceType() string {
path := "./types/service.type.ts"
return path return path
} }
@@ -19,27 +27,38 @@ func GenerateService(structName, mkPath string) {
panic(err) panic(err)
} }
defer serviceFile.Close() defer serviceFile.Close()
_, err = serviceFile.WriteString(fmt.Sprintf(`export class %sService { _, err = serviceFile.WriteString(
async read() { fmt.Sprintf(`import { GetAll, Create, Delete, ExportToExcel, GetById, Update, Count } from "%s"
import type { %s } from "%s"
import type { Service } from "%s"
export class %sService implements Service {
async read(id: number) {
return await GetById(id)
} }
async readAll() { async readAll() {
return await GetAll()
} }
async create() { async create(item: %s) {
return await Create(item)
} }
async delete() { async delete(item: %s) {
return await Delete(item)
} }
async update() { async update(item: %s) {
return await Update(item)
}
async count() {
return await Count()
}
async exportToExcel() {
return await ExportToExcel()
} }
} }
`, structName)) `, GetServiceBindPath(structName), structName, GetServiceStructType(structName), GetServiceType(), structName, structName, structName, structName))
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -3,7 +3,6 @@ package utils
import ( import (
"errors" "errors"
"os" "os"
"slices"
"strings" "strings"
) )
@@ -13,8 +12,8 @@ func FindFrontendPath() string {
panic(err) panic(err)
} }
dirs := strings.Split(currentPath, "\\") dirs := strings.Split(currentPath, "\\")
if !slices.Contains(dirs, "frontend") { if dirs[len(dirs) - 2] + "/" + dirs[len(dirs) - 1] != "frontend/src" {
panic(errors.New("Frontend dir doesn't exist")) panic(errors.New("You're not in frontend/src"))
} }
var path string var path string
for i, dir := range dirs { for i, dir := range dirs {