mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 14:30:35 +07:00
feat: relatives paths
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
main
|
||||
main.exe
|
||||
frontend
|
||||
frontend
|
||||
task.py
|
||||
@@ -1,8 +1,7 @@
|
||||
package entities
|
||||
|
||||
type Field struct {
|
||||
Name string
|
||||
Type string
|
||||
Name string
|
||||
Type string
|
||||
Medatada []Medatada
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -2,45 +2,64 @@ 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
|
||||
}
|
||||
|
||||
func GenerateService(structName, mkPath string) {
|
||||
serviceFile, err := os.Create(mkPath + "/" + strings.ToLower(structName) + ".service.ts")
|
||||
serviceFile, err := os.Create(mkPath + "/" + strings.ToLower(structName) + ".service.ts")
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user