mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Run go mod tidy on project creation. Use better method of relative module location.
This commit is contained in:
parent
15f602f867
commit
1059e36b52
2 changed files with 17 additions and 17 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue