mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 10:41:14 +08:00
Refactor TS imports
This commit is contained in:
parent
2c8d94ca48
commit
8bb3af2282
@ -35,7 +35,7 @@ func (b *Bindings) GenerateGoBindings(baseDir string) error {
|
|||||||
tsContent.WriteString(`// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
tsContent.WriteString(`// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
`)
|
`)
|
||||||
var importClasses []string
|
var importClasses slicer.StringSlicer
|
||||||
for methodName, methodDetails := range methods {
|
for methodName, methodDetails := range methods {
|
||||||
|
|
||||||
// Generate JS
|
// Generate JS
|
||||||
@ -55,9 +55,7 @@ func (b *Bindings) GenerateGoBindings(baseDir string) error {
|
|||||||
// Generate TS
|
// Generate TS
|
||||||
|
|
||||||
if len(methodDetails.StructNames) > 0 {
|
if len(methodDetails.StructNames) > 0 {
|
||||||
for _, structName := range methodDetails.StructNames {
|
importClasses.AddSlice(methodDetails.StructNames)
|
||||||
importClasses = append(importClasses, structName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tsBody.WriteString(fmt.Sprintf("\nexport function %s(", methodName))
|
tsBody.WriteString(fmt.Sprintf("\nexport function %s(", methodName))
|
||||||
|
|
||||||
@ -82,10 +80,10 @@ func (b *Bindings) GenerateGoBindings(baseDir string) error {
|
|||||||
tsBody.WriteString(returnType + ";\n")
|
tsBody.WriteString(returnType + ";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
importClasses = removeDuplicates(importClasses)
|
importClasses.Deduplicate()
|
||||||
for _, class := range importClasses {
|
importClasses.Each(func(class string) {
|
||||||
tsContent.WriteString("import {" + class + "} from '../models';\n")
|
tsContent.WriteString("import {" + class + "} from '../models';\n")
|
||||||
}
|
})
|
||||||
tsContent.WriteString(tsBody.String())
|
tsContent.WriteString(tsBody.String())
|
||||||
|
|
||||||
jsfilename := filepath.Join(packageDir, structName+".js")
|
jsfilename := filepath.Join(packageDir, structName+".js")
|
||||||
@ -333,15 +331,3 @@ func goTypeToTypescriptType(input string, useModelsNamespace bool) string {
|
|||||||
}
|
}
|
||||||
return goTypeToJSDocType(input, useModelsNamespace)
|
return goTypeToJSDocType(input, useModelsNamespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeDuplicates(input []string) []string {
|
|
||||||
seen := make(map[string]bool)
|
|
||||||
var result []string
|
|
||||||
for _, val := range input {
|
|
||||||
if _, ok := seen[val]; !ok {
|
|
||||||
result = append(result, val)
|
|
||||||
seen[val] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user