5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 05:20:00 +08:00
wails/v2/pkg/parser/resolvePackageReferences.go
Lea Anthony 62374b9b53
Js package generation (#554)
* WIP

* Generation of index.js

* Add RelativeToCwd

* Add JSDoc comments

* Convert to ES6 syntax

* Fix typo

* Initial generation of typescript declarations

* Typescript improvements

* Improved @returns jsdoc

* Improved declaration files

* Simplified output

* Rename file

* Tidy up

* Revert "Simplified output"

This reverts commit 15cdf7382b.

* Now parsing actual code

* Support Array types

* Reimagined parser

* Wrap parsing in Parser

* Rewritten module generator (TS Only)

* Final touches

* Slight refactor to improve output

* Struct comments. External struct literal binding

* Reworked project parser *working*

* remove debug info

* Refactor of parser

* remove the spew

* Better Ts support

* Better project generation logic

* Support local functions in bind()

* JS Object generation. Linting.

* Support json tags in module generation

* Updated mod files

* Support vscode file generation

* Better global.d.ts

* add ts-check to templates

* Support TS declaration files

* improved 'generate' command for module
2020-11-15 09:25:38 +11:00

36 lines
834 B
Go

package parser
import (
"fmt"
"github.com/leaanthony/slicer"
)
// resolvePackageNames will deterine the names for the packages, allowing
// us to create a flat structure for the imports in the frontend module
func (p *Parser) resolvePackageNames() {
// A cache for the names
var packageNameCache slicer.StringSlicer
// Process each package
for _, pkg := range p.packages {
pkgName := pkg.Gopackage.Name
// Check for collision
if packageNameCache.Contains(pkgName) {
// https://www.youtube.com/watch?v=otNNGROI0Cs !!!!!
// We start at 2 because having both "pkg" and "pkg1" is 🙄
count := 2
for ok := true; ok; ok = packageNameCache.Contains(pkgName) {
pkgName = fmt.Sprintf("%s%d", pkg.Gopackage.Name, count)
}
}
// Save the name!
packageNameCache.Add(pkgName)
pkg.Name = pkgName
}
}