dir, service blplt generation (without imports, logic)

This commit is contained in:
2025-02-14 00:23:28 +07:00
parent a1df30a318
commit 742a685804
6 changed files with 61 additions and 4 deletions

16
generation/gen.go Normal file
View File

@@ -0,0 +1,16 @@
package generation
import (
"fmt"
"nto_cli/entities"
"os"
"strings"
)
func Generate(structName string, fields []entities.Field) {
mkName := strings.ToLower(fmt.Sprintf("./%s", structName))
if err := os.Mkdir(mkName, 0755); err != nil {
panic(err)
}
GenerateService(structName, mkName)
}

2
generation/page.go Normal file
View File

@@ -0,0 +1,2 @@
package generation

1
generation/scheme.go Normal file
View File

@@ -0,0 +1 @@
package generation

39
generation/service.go Normal file
View File

@@ -0,0 +1,39 @@
package generation
import (
"fmt"
"os"
)
func GenerateService(structName, mkName string) {
serviceFile, err := os.Create(mkName + "/service.ts")
if err != nil {
panic(err)
}
defer serviceFile.Close()
_, err = serviceFile.WriteString(fmt.Sprintf(`
export class %sService {
async read() {
}
async readAll() {
}
async create() {
}
async delete() {
}
async update() {
}
}
`, structName))
if err != nil {
panic(err)
}
}

BIN
main

Binary file not shown.

View File

@@ -1,13 +1,12 @@
package main package main
import ( import (
"fmt"
input "nto_cli/cmd" input "nto_cli/cmd"
"nto_cli/generation"
"nto_cli/utils" "nto_cli/utils"
"os" "os"
) )
func main() { func main() {
structName, path := input.Input() structName, path := input.Input()
file, err := os.Open(path) file, err := os.Open(path)
@@ -18,5 +17,5 @@ func main() {
structFields := utils.GetStructFields(file, structName) structFields := utils.GetStructFields(file, structName)
fmt.Printf("%+v\n", structFields) generation.Generate(structName, structFields)
} }