diff --git a/cmd/project.go b/cmd/project.go index dc2f053b7..44b101777 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "sort" "strings" @@ -163,6 +164,23 @@ type ProjectOptions struct { Architecture string LdFlags string GoPath string + + // Supported platforms + Platforms []string `json:"platforms,omitempty"` +} + +// PlatformSupported returns true if the template is supported +// on the current platform +func (po *ProjectOptions) PlatformSupported() bool { + + // Default is all platforms supported + if len(po.Platforms) == 0 { + return true + } + + // Check that the platform is in the list + platformsSupported := slicer.String(po.Platforms) + return platformsSupported.Contains(runtime.GOOS) } // Defaults sets the default project template @@ -233,13 +251,16 @@ func (po *ProjectOptions) PromptForInputs() error { for _, k := range keys { templateDetail := templateDetails[k] templateList.Add(templateDetail) + if !templateDetail.Metadata.PlatformSupported() { + templateDetail.Metadata.Name = "* " + templateDetail.Metadata.Name + } options.Add(fmt.Sprintf("%s - %s", templateDetail.Metadata.Name, templateDetail.Metadata.ShortDescription)) } templateIndex := 0 if len(options.AsSlice()) > 1 { - templateIndex = PromptSelection("Please select a template", options.AsSlice(), 0) + templateIndex = PromptSelection("Please select a template (* means unsupported on current platform)", options.AsSlice(), 0) } if len(templateList.AsSlice()) == 0 { @@ -250,6 +271,10 @@ func (po *ProjectOptions) PromptForInputs() error { po.selectedTemplate = templateList.AsSlice()[templateIndex].(*TemplateDetails) } + po.selectedTemplate.Metadata.Name = strings.TrimPrefix(po.selectedTemplate.Metadata.Name, "* ") + if !po.selectedTemplate.Metadata.PlatformSupported() { + println("WARNING: This template is unsupported on this platform!") + } fmt.Println("Template: " + po.selectedTemplate.Metadata.Name) // Setup NPM Project name @@ -372,5 +397,9 @@ func processTemplateMetadata(templateMetadata *TemplateMetadata, po *ProjectOpti } po.FrontEnd.Serve = templateMetadata.Serve } + + // Save platforms + po.Platforms = templateMetadata.Platforms + return nil } diff --git a/cmd/templates.go b/cmd/templates.go index f2ee736be..fe1c68d24 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "path/filepath" + "runtime" "strings" "text/template" @@ -29,6 +30,26 @@ type TemplateMetadata struct { Bridge string `json:"bridge"` WailsDir string `json:"wailsdir"` TemplateDependencies []*TemplateDependency `json:"dependencies,omitempty"` + + // List of platforms that this template is supported on. + // No value means all platforms. A platform name is the same string + // as `runtime.GOOS` will return, eg: "darwin". NOTE: This is + // case sensitive. + Platforms []string `json:"platforms,omitempty"` +} + +// PlatformSupported returns true if this template supports the +// currently running platform +func (m *TemplateMetadata) PlatformSupported() bool { + + // Default is all platforms supported + if len(m.Platforms) == 0 { + return true + } + + // Check that the platform is in the list + platformsSupported := slicer.String(m.Platforms) + return platformsSupported.Contains(runtime.GOOS) } // TemplateDependency defines a binary dependency for the template @@ -128,11 +149,11 @@ func (t *TemplateHelper) GetTemplateDetails() (map[string]*TemplateDetails, erro result[name] = &TemplateDetails{ Path: dir, } - _ = &TemplateMetadata{} metadata, err := t.LoadMetadata(dir) if err != nil { return nil, err } + result[name].Metadata = metadata if metadata.Name != "" { result[name].Name = metadata.Name diff --git a/cmd/wails/4_build.go b/cmd/wails/4_build.go index 22246c5c9..0ecc314b1 100644 --- a/cmd/wails/4_build.go +++ b/cmd/wails/4_build.go @@ -78,6 +78,11 @@ func init() { return fmt.Errorf("Unable to find 'project.json'. Please check you are in a Wails project directory") } + // Check that this platform is supported + if !projectOptions.PlatformSupported() { + logger.Yellow("WARNING: This project is unsupported on %s - it probably won't work!\n Valid platforms: %s\n", runtime.GOOS, strings.Join(projectOptions.Platforms, ", ")) + } + // Set cross-compile projectOptions.Platform = runtime.GOOS if len(platform) > 0 {