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.exe
frontend
task.py

View File

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

View File

@@ -9,7 +9,7 @@ import (
)
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 {
panic(err)
}

View File

@@ -2,14 +2,22 @@ package generation
import (
"fmt"
"nto_cli/utils"
"os"
"strings"
)
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
}
@@ -19,27 +27,38 @@ func GenerateService(structName, mkPath string) {
panic(err)
}
defer serviceFile.Close()
_, err = serviceFile.WriteString(fmt.Sprintf(`export class %sService {
async read() {
_, err = serviceFile.WriteString(
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() {
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 {
panic(err)
}

View File

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