From 1059e36b5218c0246144d6807e2f4cf44160fac2 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 12 Aug 2023 14:32:52 +1000 Subject: [PATCH] Run `go mod tidy` on project creation. Use better method of relative module location. --- v3/internal/debug/debug.go | 22 +++++----------------- v3/internal/templates/templates.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/v3/internal/debug/debug.go b/v3/internal/debug/debug.go index d0f0c9dc2..394688ce7 100644 --- a/v3/internal/debug/debug.go +++ b/v3/internal/debug/debug.go @@ -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 { diff --git a/v3/internal/templates/templates.go b/v3/internal/templates/templates.go index bcff82616..2d35d97db 100644 --- a/v3/internal/templates/templates.go +++ b/v3/internal/templates/templates.go @@ -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