From e91c30fad0d3cd7b1ffd8c09a58c8f908832be98 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 3 Apr 2024 20:48:55 +1100 Subject: [PATCH] Small doctor improvements --- v2/cmd/wails/doctor.go | 2 +- v3/internal/doctor/doctor.go | 102 ++++++++++++++++----------- v3/internal/doctor/doctor_common.go | 30 ++++++++ v3/internal/doctor/doctor_darwin.go | 20 +++++- v3/internal/doctor/doctor_linux.go | 14 ++-- v3/internal/doctor/doctor_test.go | 10 +++ v3/internal/doctor/doctor_windows.go | 10 +-- v3/internal/version/version.txt | 2 +- 8 files changed, 134 insertions(+), 56 deletions(-) create mode 100644 v3/internal/doctor/doctor_common.go create mode 100644 v3/internal/doctor/doctor_test.go diff --git a/v2/cmd/wails/doctor.go b/v2/cmd/wails/doctor.go index 5306cab1742..015ef8a0b90 100644 --- a/v2/cmd/wails/doctor.go +++ b/v2/cmd/wails/doctor.go @@ -67,7 +67,7 @@ func diagnoseEnvironment(f *flags.Doctor) error { wailsTableData = append(wailsTableData, []string{"Package Manager", info.PM.Name()}) } - err = pterm.DefaultTable.WithData(wailsTableData).Render() + err = pterm.DefaultTable.WithBoxed().WithData(wailsTableData).Render() if err != nil { return err } diff --git a/v3/internal/doctor/doctor.go b/v3/internal/doctor/doctor.go index c46fd9027c7..4bbae931e1a 100644 --- a/v3/internal/doctor/doctor.go +++ b/v3/internal/doctor/doctor.go @@ -7,6 +7,7 @@ import ( "runtime/debug" "slices" "strconv" + "strings" "github.com/go-git/go-git/v5" "github.com/jaypipes/ghw" @@ -65,7 +66,7 @@ func Run() (err error) { return dep.Path == "github.com/wailsapp/wails/v3" }) - wailsVersion := version.VersionString + wailsVersion := strings.TrimSpace(version.VersionString) if wailsPackage != nil && wailsPackage.Replace != nil { wailsVersion = "(local) => " + filepath.ToSlash(wailsPackage.Replace.Path) // Get the latest commit hash @@ -80,47 +81,13 @@ func Run() (err error) { platformExtras, ok := getInfo() + dependencies := make(map[string]string) + checkPlatformDependencies(dependencies, &ok) + spinner.Success() /** Output **/ - pterm.DefaultSection.Println("Build Environment") - - tableData := pterm.TableData{ - {"Wails CLI", wailsVersion}, - {"Go Version", runtime.Version()}, - } - - if buildInfo, _ := debug.ReadBuildInfo(); buildInfo != nil { - buildSettingToName := map[string]string{ - "vcs.revision": "Revision", - "vcs.modified": "Modified", - } - for _, buildSetting := range buildInfo.Settings { - name := buildSettingToName[buildSetting.Key] - if name == "" { - continue - } - tableData = append(tableData, []string{name, buildSetting.Value}) - } - } - - mapKeys := lo.Keys(BuildSettings) - slices.Sort(mapKeys) - for _, key := range mapKeys { - tableData = append(tableData, []string{key, BuildSettings[key]}) - } - - //// Exit early if PM not found - //if info.PM != nil { - // wailsTableData = append(wailsTableData, []string{"Package Manager", info.PM.Name()}) - //} - - err = pterm.DefaultTable.WithData(tableData).Render() - if err != nil { - return err - } - pterm.DefaultSection.Println("System") systemTabledata := pterm.TableData{ @@ -133,7 +100,7 @@ func Run() (err error) { {pterm.Sprint("Architecture"), runtime.GOARCH}, } - mapKeys = lo.Keys(platformExtras) + mapKeys := lo.Keys(platformExtras) slices.Sort(mapKeys) for _, key := range mapKeys { systemTabledata = append(systemTabledata, []string{key, platformExtras[key]}) @@ -177,11 +144,66 @@ func Run() (err error) { //systemTabledata = append(systemTabledata, []string{"CPU", cpu.Processors[0].Model}) - err = pterm.DefaultTable.WithData(systemTabledata).Render() + err = pterm.DefaultTable.WithBoxed().WithData(systemTabledata).Render() + if err != nil { + return err + } + + // Build Environment + + pterm.DefaultSection.Println("Build Environment") + + tableData := pterm.TableData{ + {"Wails CLI", wailsVersion}, + {"Go Version", runtime.Version()}, + } + + if buildInfo, _ := debug.ReadBuildInfo(); buildInfo != nil { + buildSettingToName := map[string]string{ + "vcs.revision": "Revision", + "vcs.modified": "Modified", + } + for _, buildSetting := range buildInfo.Settings { + name := buildSettingToName[buildSetting.Key] + if name == "" { + continue + } + tableData = append(tableData, []string{name, buildSetting.Value}) + } + } + + mapKeys = lo.Keys(BuildSettings) + slices.Sort(mapKeys) + for _, key := range mapKeys { + tableData = append(tableData, []string{key, BuildSettings[key]}) + } + + err = pterm.DefaultTable.WithBoxed(true).WithData(tableData).Render() if err != nil { return err } + // Dependencies + pterm.DefaultSection.Println("Dependencies") + dependenciesBox := pterm.DefaultBox.WithTitleBottomCenter().WithTitle(pterm.Gray("*") + " - Optional Dependency") + dependencyTableData := pterm.TableData{} + if len(dependencies) == 0 { + pterm.Info.Println("No dependencies found") + } else { + var optionals pterm.TableData + mapKeys = lo.Keys(dependencies) + for _, key := range mapKeys { + if strings.HasPrefix(dependencies[key], "*") { + optionals = append(optionals, []string{key, dependencies[key]}) + } else { + dependencyTableData = append(dependencyTableData, []string{key, dependencies[key]}) + } + } + dependencyTableData = append(dependencyTableData, optionals...) + dependenciesTableString, _ := pterm.DefaultTable.WithData(dependencyTableData).Srender() + dependenciesBox.Println(dependenciesTableString) + } + pterm.DefaultSection.Println("Diagnosis") if !ok { pterm.Warning.Println("There are some items above that need addressing!") diff --git a/v3/internal/doctor/doctor_common.go b/v3/internal/doctor/doctor_common.go new file mode 100644 index 00000000000..944729bb040 --- /dev/null +++ b/v3/internal/doctor/doctor_common.go @@ -0,0 +1,30 @@ +package doctor + +import ( + "bytes" + "os/exec" + "strconv" + "strings" +) + +func checkCommonDependencies(result map[string]string, ok *bool) { + // Check for npm + npmVersion := []byte("Not Installed. Requires npm >= 7.0.0") + npmVersion, err := exec.Command("npm", "-v").Output() + if err != nil { + *ok = false + } else { + npmVersion = bytes.TrimSpace(npmVersion) + // Check that it's at least version 7 by converting first byte to int and checking if it's >= 7 + // Parse the semver string + semver := strings.Split(string(npmVersion), ".") + if len(semver) > 0 { + major, _ := strconv.Atoi(semver[0]) + if major < 7 { + *ok = false + npmVersion = append(npmVersion, []byte(". Installed, but requires npm >= 7.0.0")...) + } + } + } + result["npm"] = string(npmVersion) +} diff --git a/v3/internal/doctor/doctor_darwin.go b/v3/internal/doctor/doctor_darwin.go index d92d8953ee0..9ffb368f1aa 100644 --- a/v3/internal/doctor/doctor_darwin.go +++ b/v3/internal/doctor/doctor_darwin.go @@ -3,6 +3,7 @@ package doctor import ( + "bytes" "github.com/samber/lo" "os/exec" "strings" @@ -31,11 +32,16 @@ func getInfo() (map[string]string, bool) { result["Apple Silicon"] = appleSilicon result["CPU"] = getSysctl("machdep.cpu.brand_string") + return result, ok +} + +func checkPlatformDependencies(result map[string]string, ok *bool) { + // Check for xcode command line tools output, err := exec.Command("xcode-select", "-v").Output() cliToolsVersion := "N/A. Install by running: `xcode-select --install`" if err != nil { - ok = false + *ok = false } else { cliToolsVersion = strings.TrimPrefix(string(output), "xcode-select version ") cliToolsVersion = strings.TrimSpace(cliToolsVersion) @@ -43,5 +49,15 @@ func getInfo() (map[string]string, bool) { } result["Xcode cli tools"] = cliToolsVersion - return result, ok + checkCommonDependencies(result, ok) + + // Check for nsis + nsisVersion := []byte("Not Installed. Install with `brew install makensis`.") + output, err = exec.Command("makensis", "-VERSION").Output() + if err == nil && output != nil { + nsisVersion = output + } + nsisVersion = bytes.TrimSpace(nsisVersion) + + result["*NSIS"] = string(nsisVersion) } diff --git a/v3/internal/doctor/doctor_linux.go b/v3/internal/doctor/doctor_linux.go index 7c64da1a66b..f9454305f1d 100644 --- a/v3/internal/doctor/doctor_linux.go +++ b/v3/internal/doctor/doctor_linux.go @@ -2,15 +2,13 @@ package doctor -import ( - "github.com/wailsapp/wails/v3/internal/doctor/packagemanager" - "github.com/wailsapp/wails/v3/internal/operatingsystem" -) - func getInfo() (map[string]string, bool) { result := make(map[string]string) - ok := true + return result, true +} +func checkPlatformDependencies(result map[string]string, ok *bool) { + result := make(map[string]string) info, _ := operatingsystem.Info() pm := packagemanager.Find(info.ID) @@ -23,7 +21,7 @@ func getInfo() (map[string]string, bool) { if dep.Optional { status = "[Optional] " } else { - ok = false + *ok = false } status += "not installed." if dep.InstallCommand != "" { @@ -36,5 +34,5 @@ func getInfo() (map[string]string, bool) { result[dep.Name] = status } - return result, ok + checkCommonDependencies(result, ok) } diff --git a/v3/internal/doctor/doctor_test.go b/v3/internal/doctor/doctor_test.go new file mode 100644 index 00000000000..98f4c3f8a35 --- /dev/null +++ b/v3/internal/doctor/doctor_test.go @@ -0,0 +1,10 @@ +package doctor + +import "testing" + +func TestRun(t *testing.T) { + err := Run() + if err != nil { + t.Errorf("TestRun failed: %v", err) + } +} diff --git a/v3/internal/doctor/doctor_windows.go b/v3/internal/doctor/doctor_windows.go index c8b0c6b2961..541041e0aa5 100644 --- a/v3/internal/doctor/doctor_windows.go +++ b/v3/internal/doctor/doctor_windows.go @@ -18,10 +18,6 @@ func getInfo() (map[string]string, bool) { webviewVersion = "Error:" + err.Error() } result["WebView2 Version"] = webviewVersion - - // add nsis - result["NSIS"] = getNSISVersion() - return result, ok } @@ -33,3 +29,9 @@ func getNSISVersion() string { } return string(output) } + +func checkPlatformDependencies(result map[string]string, ok *bool) { + checkCommonDependencies(result, ok) + // add nsis + result["NSIS"] = getNSISVersion() +} diff --git a/v3/internal/version/version.txt b/v3/internal/version/version.txt index 60fbe96c7c7..5781d3b0460 100644 --- a/v3/internal/version/version.txt +++ b/v3/internal/version/version.txt @@ -1 +1 @@ -v3.0.0-alpha.4 +v3.0.0-alpha.4 \ No newline at end of file