2018-12-20 06:58:55 +11:00
package cmd
import (
"fmt"
"runtime"
)
2018-12-22 18:40:36 -08:00
func newPrerequisite ( name , help string ) * Prerequisite {
return & Prerequisite { Name : name , Help : help }
2018-12-20 06:58:55 +11:00
}
2018-12-22 18:40:36 -08:00
// Prerequisites is a list of things required to use Wails
type Prerequisites [] * Prerequisite
2018-12-20 06:58:55 +11:00
// Add given prereq object to list
2018-12-22 18:40:36 -08:00
func ( p * Prerequisites ) Add ( prereq * Prerequisite ) {
2018-12-20 06:58:55 +11:00
* p = append ( * p , prereq )
}
2018-12-22 18:40:36 -08:00
// GetRequiredPrograms returns a list of programs required for the platform
func GetRequiredPrograms () ( * Prerequisites , error ) {
switch runtime . GOOS {
case "darwin" :
return getRequiredProgramsOSX (), nil
case "linux" :
return getRequiredProgramsLinux (), nil
case "windows" :
return getRequiredProgramsWindows (), nil
2018-12-19 12:49:04 -08:00
default :
2018-12-22 18:40:36 -08:00
return nil , fmt . Errorf ( "platform '%s' not supported at this time" , runtime . GOOS )
2018-12-19 12:49:04 -08:00
}
2018-12-20 06:58:55 +11:00
}
2018-12-22 18:40:36 -08:00
func getRequiredProgramsOSX () * Prerequisites {
result := & Prerequisites {}
result . Add ( newPrerequisite ( "clang" , "Please install with `xcode-select --install` and try again" ))
2018-12-23 17:10:32 +11:00
result . Add ( newPrerequisite ( "npm" , "Please install from https://nodejs.org/en/download/ and try again" ))
2018-12-22 18:40:36 -08:00
return result
2018-12-20 06:58:55 +11:00
}
2018-12-22 18:40:36 -08:00
func getRequiredProgramsLinux () * Prerequisites {
result := & Prerequisites {}
distroInfo := GetLinuxDistroInfo ()
2019-10-08 06:12:08 +11:00
if distroInfo . Distribution != Unknown {
var linuxDB = NewLinuxDB ()
distro := linuxDB . GetDistro ( distroInfo . ID )
release := distro . GetRelease ( distroInfo . Release )
for _ , program := range release . Programs {
result . Add ( program )
}
2018-12-20 06:58:55 +11:00
}
2018-12-22 18:40:36 -08:00
return result
}
// TODO: Test this on Windows
func getRequiredProgramsWindows () * Prerequisites {
result := & Prerequisites {}
2018-12-23 15:37:51 +11:00
result . Add ( newPrerequisite ( "gcc" , "Please install gcc from here and try again: http://tdm-gcc.tdragon.net/download. You will need to add the bin directory to your path, EG: C:\\TDM-GCC-64\\bin\\" ))
result . Add ( newPrerequisite ( "npm" , "Please install node/npm from here and try again: https://nodejs.org/en/download/" ))
2018-12-22 18:40:36 -08:00
return result
}
// GetRequiredLibraries returns a list of libraries (packages) required for the platform
func GetRequiredLibraries () ( * Prerequisites , error ) {
switch runtime . GOOS {
case "darwin" :
return getRequiredLibrariesOSX ()
case "linux" :
return getRequiredLibrariesLinux ()
case "windows" :
return getRequiredLibrariesWindows ()
default :
return nil , fmt . Errorf ( "platform '%s' not supported at this time" , runtime . GOOS )
}
}
func getRequiredLibrariesOSX () ( * Prerequisites , error ) {
result := & Prerequisites {}
return result , nil
}
func getRequiredLibrariesLinux () ( * Prerequisites , error ) {
result := & Prerequisites {}
2019-10-08 06:12:08 +11:00
// The Linux Distribution DB
2018-12-22 18:40:36 -08:00
distroInfo := GetLinuxDistroInfo ()
2019-10-08 06:12:08 +11:00
if distroInfo . Distribution != Unknown {
var linuxDB = NewLinuxDB ()
distro := linuxDB . GetDistro ( distroInfo . ID )
release := distro . GetRelease ( distroInfo . Release )
for _ , library := range release . Libraries {
result . Add ( library )
}
2018-12-22 18:40:36 -08:00
}
return result , nil
}
func getRequiredLibrariesWindows () ( * Prerequisites , error ) {
result := & Prerequisites {}
return result , nil
2018-12-20 06:58:55 +11:00
}