mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
feat: prerequisite checking (osx)
This commit is contained in:
parent
54a88ae3d9
commit
ea5e06aabd
2 changed files with 104 additions and 25 deletions
79
cmd/prerequisites.go
Normal file
79
cmd/prerequisites.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// binaryPrerequisite defines a binaryPrerequisite
|
||||
type binaryPrerequisite struct {
|
||||
Name string
|
||||
Help string
|
||||
Path string
|
||||
}
|
||||
|
||||
func newBinaryPrerequisite(name, help string) *binaryPrerequisite {
|
||||
return &binaryPrerequisite{Name: name, Help: help}
|
||||
}
|
||||
|
||||
// binaryPrerequisites is a list of binaryPrerequisites
|
||||
type binaryPrerequisites []*binaryPrerequisite
|
||||
|
||||
// Add given prereq object to list
|
||||
func (p *binaryPrerequisites) Add(prereq *binaryPrerequisite) {
|
||||
*p = append(*p, prereq)
|
||||
}
|
||||
|
||||
func (p *binaryPrerequisites) check() (success *binaryPrerequisites, failed *binaryPrerequisites) {
|
||||
success = &binaryPrerequisites{}
|
||||
failed = &binaryPrerequisites{}
|
||||
programHelper := NewProgramHelper()
|
||||
for _, prereq := range *p {
|
||||
bin := programHelper.FindProgram(prereq.Name)
|
||||
if bin == nil {
|
||||
failed.Add(prereq)
|
||||
} else {
|
||||
path, err := bin.GetFullPathToBinary()
|
||||
if err != nil {
|
||||
failed.Add(prereq)
|
||||
} else {
|
||||
prereq.Path = path
|
||||
success.Add(prereq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success, failed
|
||||
}
|
||||
|
||||
var platformbinaryPrerequisites = make(map[string]*binaryPrerequisites)
|
||||
|
||||
func init() {
|
||||
platformbinaryPrerequisites["darwin"] = &binaryPrerequisites{}
|
||||
newDarwinbinaryPrerequisite("clang", "Please install with `xcode-select --install` and try again")
|
||||
}
|
||||
|
||||
func newDarwinbinaryPrerequisite(name, help string) {
|
||||
prereq := newBinaryPrerequisite(name, help)
|
||||
platformbinaryPrerequisites["darwin"].Add(prereq)
|
||||
}
|
||||
|
||||
func CheckBinaryPrerequisites() (*binaryPrerequisites, *binaryPrerequisites, error) {
|
||||
platformPreReqs := platformbinaryPrerequisites[runtime.GOOS]
|
||||
if platformPreReqs == nil {
|
||||
return nil, nil, fmt.Errorf("Platform '%s' is not supported at this time", runtime.GOOS)
|
||||
}
|
||||
success, failed := platformPreReqs.check()
|
||||
return success, failed, nil
|
||||
}
|
||||
|
||||
func CheckNonBinaryPrerequisites() error {
|
||||
|
||||
var err error
|
||||
|
||||
// Check non-binaries
|
||||
if runtime.GOOS == "linux" {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
|
|
@ -22,36 +21,37 @@ func init() {
|
|||
return err
|
||||
}
|
||||
|
||||
var successMessage string
|
||||
|
||||
var successMessage = `Ready for take off!
|
||||
Create your first project by running 'wails init'.`
|
||||
if runtime.GOOS != "windows" {
|
||||
successMessage = "🚀 " + successMessage
|
||||
}
|
||||
logger.Yellow("Checking for prerequisites...")
|
||||
// Check we have a cgo capable environment
|
||||
programHelper := cmd.NewProgramHelper()
|
||||
prerequisites := make(map[string]map[string]string)
|
||||
prerequisites["darwin"] = make(map[string]string)
|
||||
prerequisites["darwin"]["clang"] = "Please install with `xcode-select --install` and try again"
|
||||
prerequisites["darwin"]["npm"] = "Please download and install npm + node from here: https://nodejs.org/en/"
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
successMessage = "🚀 Awesome! We are going to the moon! 🚀"
|
||||
default:
|
||||
return fmt.Errorf("platform '%s' is unsupported at this time", runtime.GOOS)
|
||||
|
||||
successDeps, failedDeps, err := cmd.CheckBinaryPrerequisites()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
errors := false
|
||||
for name, help := range prerequisites[runtime.GOOS] {
|
||||
bin := programHelper.FindProgram(name)
|
||||
if bin == nil {
|
||||
errors = true
|
||||
logger.Red("Unable to find '%s' - %s", name, help)
|
||||
} else {
|
||||
logger.Green("Found program '%s' at '%s'", name, bin.Path)
|
||||
}
|
||||
for _, dep := range *successDeps {
|
||||
logger.Green("Found '%s' at '%s'", dep.Name, dep.Path)
|
||||
}
|
||||
|
||||
if errors {
|
||||
err = fmt.Errorf("There were missing dependencies")
|
||||
} else {
|
||||
logger.White("")
|
||||
|
||||
for _, dep := range *failedDeps {
|
||||
logger.Red("PreRequisite '%s' missing. %s", dep.Name, dep.Help)
|
||||
}
|
||||
|
||||
// Check non-binary prerequisites
|
||||
err = cmd.CheckNonBinaryPrerequisites()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(*failedDeps) == 0 {
|
||||
logger.Yellow(successMessage)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue