mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 16:20:34 +07:00
dir, service blplt generation (without imports, logic)
This commit is contained in:
16
generation/gen.go
Normal file
16
generation/gen.go
Normal 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
2
generation/page.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package generation
|
||||
|
||||
1
generation/scheme.go
Normal file
1
generation/scheme.go
Normal file
@@ -0,0 +1 @@
|
||||
package generation
|
||||
39
generation/service.go
Normal file
39
generation/service.go
Normal 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)
|
||||
}
|
||||
}
|
||||
7
main.go
7
main.go
@@ -1,13 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
input "nto_cli/cmd"
|
||||
"nto_cli/generation"
|
||||
"nto_cli/utils"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
structName, path := input.Input()
|
||||
file, err := os.Open(path)
|
||||
@@ -18,5 +17,5 @@ func main() {
|
||||
|
||||
structFields := utils.GetStructFields(file, structName)
|
||||
|
||||
fmt.Printf("%+v\n", structFields)
|
||||
}
|
||||
generation.Generate(structName, structFields)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user