mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-07 21:23:02 +08:00
Support platform list in templates
This commit is contained in:
parent
84f407278c
commit
e8a85d4cd6
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -163,6 +164,23 @@ type ProjectOptions struct {
|
|||||||
Architecture string
|
Architecture string
|
||||||
LdFlags string
|
LdFlags string
|
||||||
GoPath 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
|
// Defaults sets the default project template
|
||||||
@ -233,13 +251,16 @@ func (po *ProjectOptions) PromptForInputs() error {
|
|||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
templateDetail := templateDetails[k]
|
templateDetail := templateDetails[k]
|
||||||
templateList.Add(templateDetail)
|
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))
|
options.Add(fmt.Sprintf("%s - %s", templateDetail.Metadata.Name, templateDetail.Metadata.ShortDescription))
|
||||||
}
|
}
|
||||||
|
|
||||||
templateIndex := 0
|
templateIndex := 0
|
||||||
|
|
||||||
if len(options.AsSlice()) > 1 {
|
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 {
|
if len(templateList.AsSlice()) == 0 {
|
||||||
@ -250,6 +271,10 @@ func (po *ProjectOptions) PromptForInputs() error {
|
|||||||
po.selectedTemplate = templateList.AsSlice()[templateIndex].(*TemplateDetails)
|
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)
|
fmt.Println("Template: " + po.selectedTemplate.Metadata.Name)
|
||||||
|
|
||||||
// Setup NPM Project name
|
// Setup NPM Project name
|
||||||
@ -372,5 +397,9 @@ func processTemplateMetadata(templateMetadata *TemplateMetadata, po *ProjectOpti
|
|||||||
}
|
}
|
||||||
po.FrontEnd.Serve = templateMetadata.Serve
|
po.FrontEnd.Serve = templateMetadata.Serve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save platforms
|
||||||
|
po.Platforms = templateMetadata.Platforms
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@ -29,6 +30,26 @@ type TemplateMetadata struct {
|
|||||||
Bridge string `json:"bridge"`
|
Bridge string `json:"bridge"`
|
||||||
WailsDir string `json:"wailsdir"`
|
WailsDir string `json:"wailsdir"`
|
||||||
TemplateDependencies []*TemplateDependency `json:"dependencies,omitempty"`
|
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
|
// TemplateDependency defines a binary dependency for the template
|
||||||
@ -128,11 +149,11 @@ func (t *TemplateHelper) GetTemplateDetails() (map[string]*TemplateDetails, erro
|
|||||||
result[name] = &TemplateDetails{
|
result[name] = &TemplateDetails{
|
||||||
Path: dir,
|
Path: dir,
|
||||||
}
|
}
|
||||||
_ = &TemplateMetadata{}
|
|
||||||
metadata, err := t.LoadMetadata(dir)
|
metadata, err := t.LoadMetadata(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result[name].Metadata = metadata
|
result[name].Metadata = metadata
|
||||||
if metadata.Name != "" {
|
if metadata.Name != "" {
|
||||||
result[name].Name = metadata.Name
|
result[name].Name = metadata.Name
|
||||||
|
@ -78,6 +78,11 @@ func init() {
|
|||||||
return fmt.Errorf("Unable to find 'project.json'. Please check you are in a Wails project directory")
|
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
|
// Set cross-compile
|
||||||
projectOptions.Platform = runtime.GOOS
|
projectOptions.Platform = runtime.GOOS
|
||||||
if len(platform) > 0 {
|
if len(platform) > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user