Skip to content

Commit

Permalink
Small doctor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Apr 3, 2024
1 parent 3e3f7b9 commit e91c30f
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 56 deletions.
2 changes: 1 addition & 1 deletion v2/cmd/wails/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
102 changes: 62 additions & 40 deletions v3/internal/doctor/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime/debug"
"slices"
"strconv"
"strings"

"github.com/go-git/go-git/v5"
"github.com/jaypipes/ghw"
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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]})
Expand Down Expand Up @@ -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!")
Expand Down
30 changes: 30 additions & 0 deletions v3/internal/doctor/doctor_common.go
Original file line number Diff line number Diff line change
@@ -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)
}
20 changes: 18 additions & 2 deletions v3/internal/doctor/doctor_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package doctor

import (
"bytes"
"github.com/samber/lo"
"os/exec"
"strings"
Expand Down Expand Up @@ -31,17 +32,32 @@ 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)
cliToolsVersion = strings.TrimSuffix(cliToolsVersion, ".")
}
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)
}
14 changes: 6 additions & 8 deletions v3/internal/doctor/doctor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 != "" {
Expand All @@ -36,5 +34,5 @@ func getInfo() (map[string]string, bool) {
result[dep.Name] = status
}

return result, ok
checkCommonDependencies(result, ok)
}
10 changes: 10 additions & 0 deletions v3/internal/doctor/doctor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package doctor

import "testing"

func TestRun(t *testing.T) {
err := Run()
if err != nil {
t.Errorf("TestRun failed: %v", err)
}
}
10 changes: 6 additions & 4 deletions v3/internal/doctor/doctor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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()
}
2 changes: 1 addition & 1 deletion v3/internal/version/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.0.0-alpha.4
v3.0.0-alpha.4

0 comments on commit e91c30f

Please sign in to comment.