mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 17:10:34 +07:00
sync
This commit is contained in:
@@ -14,4 +14,5 @@ func Generate(structName string, fields []entities.Field) {
|
||||
panic(err)
|
||||
}
|
||||
GenerateService(structName, mkPath)
|
||||
GenerateScheme(structName, fields, mkPath)
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
package generation
|
||||
|
||||
@@ -1 +1,57 @@
|
||||
package generation
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"nto_cli/entities"
|
||||
"nto_cli/utils"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GenerateScheme(structName string, fields []entities.Field, mkPath string) {
|
||||
schemeFile, err := os.Create(mkPath + "/" + strings.ToTitle(structName) + "Scheme.vue")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer schemeFile.Close()
|
||||
_, err = schemeFile.WriteString(fmt.Sprintf(
|
||||
`<script setup lang="ts">
|
||||
import Table from ../table/Table.vue
|
||||
import { onMounted, reactive } from 'vue'
|
||||
import { getDefaultValues } from '../utils/structs/defaults.util'
|
||||
import S from './%s.service.ts'
|
||||
import type { Scheme } from '../types/scheme.type'
|
||||
import { %s } from '%s'
|
||||
|
||||
const service = new S
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
})
|
||||
|
||||
const scheme: Scheme = reactive({
|
||||
%s
|
||||
})
|
||||
|
||||
getDefaults = () => getDefaultValues(scheme)
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="w-screen h-screen>
|
||||
<Table :scheme :service :getDefaults></Table>
|
||||
</main>
|
||||
</template>
|
||||
`, strings.ToLower(structName), structName, utils.GetServiceStructType(structName), GenerateFields(fields)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateFields(fields []entities.Field) string {
|
||||
result := "{\n"
|
||||
for _, field := range fields {
|
||||
result += field.Generate() + ", \n"
|
||||
}
|
||||
return result + "\n}"
|
||||
}
|
||||
@@ -2,24 +2,12 @@ package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"nto_cli/utils"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetServiceBindPath(structName string) string {
|
||||
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")
|
||||
@@ -28,11 +16,11 @@ func GenerateService(structName, mkPath string) {
|
||||
}
|
||||
defer serviceFile.Close()
|
||||
_, err = serviceFile.WriteString(fmt.Sprintf(
|
||||
`import { GetAll, Create, Delete, ExportToExcel, GetById, Update, Count } from "%s"
|
||||
`import { GetAll, Create, Delete, ExportToExcel, GetById, Update, Count } from "%s"
|
||||
import type { %s } from "%s"
|
||||
import type { IService } from "%s"
|
||||
|
||||
export class %sService implements IService<%s> {
|
||||
export default class %sService implements IService<%s> {
|
||||
async read(id: number) {
|
||||
return await GetById(id)
|
||||
}
|
||||
@@ -58,7 +46,7 @@ export class %sService implements IService<%s> {
|
||||
return await ExportToExcel()
|
||||
}
|
||||
}
|
||||
`, GetServiceBindPath(structName), structName, GetServiceStructType(structName), GetServiceType(), structName, structName, structName, structName, structName))
|
||||
`, utils.GetServiceBindPath(structName), structName, utils.GetServiceStructType(structName), utils.GetServiceType(), structName, structName, structName, structName, structName))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user