Run go mod tidy on project creation. Use better method of relative module location.

This commit is contained in:
Lea Anthony 2023-08-12 14:32:52 +10:00
commit 1059e36b52
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
2 changed files with 17 additions and 17 deletions

View file

@ -1,35 +1,23 @@
package debug
import (
"os"
"path/filepath"
"runtime"
"runtime/debug"
"github.com/samber/lo"
)
// Why go doesn't provide this as a map already is beyond me.
var buildSettings = map[string]string{}
var LocalModulePath = ""
func init() {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return
}
buildSettings = lo.Associate(buildInfo.Settings, func(setting debug.BuildSetting) (string, string) {
return setting.Key, setting.Value
})
if isLocalBuild() || buildInfo.Path == "" {
// Check if .git exists in the relative directory from here: ../../..
// If it does, we are in a local build
gitDir := RelativePath("..", "..", "..", ".git")
if _, err := os.Stat(gitDir); err == nil {
modulePath := RelativePath("..", "..", "..")
LocalModulePath, _ = filepath.Abs(modulePath)
}
}
func isLocalBuild() bool {
return buildSettings["vcs.modified"] == "true"
}
// RelativePath returns a qualified path created by joining the
// directory of the calling file and the given relative path.
func RelativePath(relativepath string, optionalpaths ...string) string {

View file

@ -11,6 +11,7 @@ import (
"github.com/wailsapp/wails/v3/internal/debug"
"io/fs"
"os"
"os/exec"
"path/filepath"
"strings"
@ -354,6 +355,17 @@ func Install(options *flags.Init) error {
return err
}
// Change to project directory
err = os.Chdir(templateData.ProjectDir)
if err != nil {
return err
}
// Run `go mod tidy`
err = exec.Command("go", "mod", "tidy").Run()
if err != nil {
return err
}
pterm.Printf("\nProject '%s' created successfully.\n", options.ProjectName)
return nil