Add generate build-assets. Update Taskfile for vanilla template

This commit is contained in:
Lea Anthony
2023-09-09 10:25:56 +10:00
parent 350b411afe
commit a5812578c5
16 changed files with 131 additions and 110 deletions
+4
View File
@@ -14,8 +14,11 @@ theme:
- navigation.sections
- navigation.expand
- navigation.instant
- navigation.instant.prefetch
- navigation.top
- navigation.footer
- navigation.path
- navigation.prune
- toc.integrate
- toc.follow
@@ -86,6 +89,7 @@ nav:
- Status: development/status.md
- v3 Changes: development/changes.md
- Change Log: changelog.md
- Sponsor❤️: https://github.com/sponsors/leaanthony
markdown_extensions:
+1 -1
View File
@@ -37,7 +37,7 @@ func main() {
})
task.LongDescription("\nUsage: wails task [taskname] [flags]\n\nTasks are defined in the `Taskfile.yaml` file. See https://taskfile.dev for more information.")
generate := app.NewSubCommand("generate", "Generation tools")
generate.NewSubCommandFunction("defaults", "Generate default build assets", commands.Defaults)
generate.NewSubCommandFunction("build-assets", "Generate build assets", commands.GenerateBuildAssets)
generate.NewSubCommandFunction("icons", "Generate icons", commands.GenerateIcons)
generate.NewSubCommandFunction("syso", "Generate Windows .syso file", commands.GenerateSyso)
generate.NewSubCommandFunction("bindings", "Generate bindings + models", commands.GenerateBindings)
+66
View File
@@ -0,0 +1,66 @@
package commands
import (
"embed"
_ "embed"
"fmt"
"github.com/leaanthony/gosod"
"io/fs"
"os"
"path/filepath"
"strings"
"time"
)
//go:embed build_assets
var buildAssets embed.FS
type BuildAssetsOptions struct {
Dir string `description:"The directory to generate the files into" default:"build"`
Name string `description:"The name of the project"`
ProductName string `description:"The name of the product" default:"My Product"`
ProductDescription string `description:"The description of the product" default:"My Product Description"`
ProductVersion string `description:"The version of the product" default:"0.1.0"`
ProductCompany string `description:"The company of the product" default:"My Company"`
ProductCopyright string `description:"The copyright notice"`
ProductComments string `description:"Comments to add to the generated files" default:"This is a comment"`
ProductIdentifier string `description:"The product identifier, e.g com.mycompany.myproduct"`
}
func GenerateBuildAssets(options *BuildAssetsOptions) error {
var err error
options.Dir, err = filepath.Abs(options.Dir)
if err != nil {
return err
}
// If directory doesn't exist, create it
if _, err := os.Stat(options.Dir); os.IsNotExist(err) {
err = os.MkdirAll(options.Dir, 0755)
if err != nil {
return err
}
}
if options.ProductComments == "" {
options.ProductComments = fmt.Sprintf("(c) %d %s", time.Now().Year(), options.ProductCompany)
}
if options.ProductIdentifier == "" {
options.ProductIdentifier = "com.wails." + normaliseName(options.Name)
}
tfs, err := fs.Sub(buildAssets, "build_assets")
if err != nil {
return err
}
println("Generating build assets in " + options.Dir)
return gosod.New(tfs).Extract(options.Dir, options)
}
func normaliseName(name string) string {
return strings.ToLower(strings.ReplaceAll(name, " ", "-"))
}
@@ -4,17 +4,17 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>{{.Info.ProductName}}</string>
<string>{{.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.Name}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<string>{{.ProductIdentifier}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<string>{{.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
<string>{{.Info.Comments}}</string>
<string>{{.ProductComments}}</string>
<key>CFBundleShortVersionString</key>
<string>{{.Info.ProductVersion}}</string>
<string>{{.ProductVersion}}</string>
<key>CFBundleIconFile</key>
<string>icons</string>
<key>LSMinimumSystemVersion</key>
@@ -22,7 +22,7 @@
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>{{.Info.Copyright}}</string>
<string>{{.ProductCopyright}}</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
@@ -8,13 +8,13 @@
<key>CFBundleExecutable</key>
<string>{{.Name}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<string>{{.ProductIdentifier}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<string>{{.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
<string>{{.Info.Comments}}</string>
<string>{{.ProductComments}}</string>
<key>CFBundleShortVersionString</key>
<string>{{.Info.ProductVersion}}</string>
<string>{{.ProductVersion}}</string>
<key>CFBundleIconFile</key>
<string>icons</string>
<key>LSMinimumSystemVersion</key>
@@ -22,6 +22,6 @@
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>{{.Info.Copyright}}</string>
<string>{{.ProductCopyright}}</string>
</dict>
</plist>

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

@@ -0,0 +1,15 @@
{
"fixed": {
"file_version": "{{.ProductVersion}}"
},
"info": {
"0000": {
"ProductVersion": "{{.ProductVersion}}",
"CompanyName": "{{.ProductCompany}}",
"FileDescription": "{{.ProductDescription}}",
"LegalCopyright": "{{.ProductCopyright}}",
"ProductName": "{{.ProductName}}",
"Comments": "{{.ProductComments}}"
}
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity type="win32" name="com.wails.myproductname" version="v1.0.0.0" processorArchitecture="*"/>
<assemblyIdentity type="win32" name="{{.ProductIdentifier}}" version="{{.ProductVersion}}" processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
-61
View File
@@ -1,61 +0,0 @@
package commands
import (
_ "embed"
"os"
)
//go:embed defaults/info.json
var Info []byte
//go:embed defaults/wails.exe.manifest
var Manifest []byte
//go:embed defaults/appicon.png
var AppIcon []byte
//go:embed defaults/icon.ico
var IconIco []byte
//go:embed defaults/Info.plist
var InfoPlist []byte
//go:embed defaults/Info.dev.plist
var InfoDevPlist []byte
//go:embed defaults/icons.icns
var IconsIcns []byte
var AllAssets = map[string][]byte{
"info.json": Info,
"wails.exe.manifest": Manifest,
"appicon.png": AppIcon,
"icon.ico": IconIco,
"Info.plist": InfoPlist,
"Info.dev.plist": InfoDevPlist,
"icons.icns": IconsIcns,
}
type DefaultsOptions struct {
Dir string `description:"The directory to generate the files into"`
}
func Defaults(options *DefaultsOptions) error {
dir := options.Dir
if dir == "" {
dir = "."
}
for filename, data := range AllAssets {
// If file exists, skip it
if _, err := os.Stat(dir + "/" + filename); err == nil {
println("Skipping " + filename)
continue
}
err := os.WriteFile(dir+"/"+filename, data, 0644)
if err != nil {
return err
}
println("Generated " + filename)
}
return nil
}
-15
View File
@@ -1,15 +0,0 @@
{
"fixed": {
"file_version": "v1.0.0"
},
"info": {
"0000": {
"ProductVersion": "v1.0.0",
"CompanyName": "My Company Name",
"FileDescription": "A thing that does a thing",
"LegalCopyright": "(c) 2023 My Company Name",
"ProductName": "My Product Name",
"Comments": "This is a comment"
}
}
}
+5 -1
View File
@@ -68,7 +68,11 @@ func GenerateIcons(options *IconsOptions) error {
}
func generateExampleIcon() error {
return os.WriteFile("appicon.png", []byte(AppIcon), 0644)
appIcon, err := buildAssets.ReadFile("build_assets/appicon.png")
if err != nil {
return err
}
return os.WriteFile("appicon.png", appIcon, 0644)
}
func parseSizes(sizes string) ([]int, error) {
-20
View File
@@ -10,7 +10,6 @@ import (
)
type SysoOptions struct {
Example bool `description:"Generate example manifest & info files"`
Manifest string `description:"The manifest file"`
Info string `description:"The info.json file"`
Icon string `description:"The icon file"`
@@ -26,11 +25,6 @@ func (i *SysoOptions) Default() *SysoOptions {
func GenerateSyso(options *SysoOptions) error {
// Generate example files?
if options.Example {
return generateExampleSyso()
}
if options.Manifest == "" {
return fmt.Errorf("manifest is required")
}
@@ -107,17 +101,3 @@ func GenerateSyso(options *SysoOptions) error {
}
return nil
}
func generateExampleSyso() error {
// Generate example info.json
err := os.WriteFile("info.json", Info, 0644)
if err != nil {
return err
}
// Generate example manifest
err = os.WriteFile("wails.exe.manifest", Manifest, 0644)
if err != nil {
return err
}
return nil
}
@@ -2,9 +2,23 @@ version: '3'
vars:
APP_NAME: "{{.ProjectName}}{{exeExt}}"
APP_VERSION: "0.1.0"
PRODUCT_NAME: "My Product"
PRODUCT_DESCRIPTION: "My Product Description"
PRODUCT_VERSION: "0.1.0"
PRODUCT_COMPANY: "My Company"
PRODUCT_COPYRIGHT: "(c) 2023 My Company"
PRODUCT_COMMENTS: "My Comments"
PRODUCT_IDENTIFIER: "com.mycompany.myproduct"
BUILD_DIR: "build"
tasks:
generate:build-assets:
summary: Generates the build assets
cmds:
- wails3 generate build-assets -dir {{.BUILD_DIR}} -name "{{.APP_NAME}}" -productname "{{.PRODUCT_NAME}}" -productdescription "{{.PRODUCT_DESCRIPTION}}" -productversion "{{.PRODUCT_VERSION}}" -productcompany "{{.PRODUCT_COMPANY}}" -productcopyright "{{.PRODUCT_COPYRIGHT}}" -productcomments "{{.PRODUCT_COMMENTS}}" -productidentifier "{{.PRODUCT_IDENTIFIER}}"
pre-build:
summary: Pre-build hooks
@@ -2,9 +2,23 @@ version: '3'
vars:
APP_NAME: "{{.ProjectName}}"
APP_VERSION: "0.1.0"
PRODUCT_NAME: "My Product"
PRODUCT_DESCRIPTION: "My Product Description"
PRODUCT_VERSION: "0.1.0"
PRODUCT_COMPANY: "My Company"
PRODUCT_COPYRIGHT: "(c) 2023 My Company"
PRODUCT_COMMENTS: "My Comments"
PRODUCT_IDENTIFIER: "com.mycompany.myproduct"
BUILD_DIR: "build"
tasks:
generate:build-assets:
summary: Generates the build assets
cmds:
- wails3 generate build-assets -dir {{.BUILD_DIR}} -name "{{.APP_NAME}}" -productname "{{.PRODUCT_NAME}}" -productdescription "{{.PRODUCT_DESCRIPTION}}" -productversion "{{.PRODUCT_VERSION}}" -productcompany "{{.PRODUCT_COMPANY}}" -productcopyright "{{.PRODUCT_COPYRIGHT}}" -productcomments "{{.PRODUCT_COMMENTS}}" -productidentifier "{{.PRODUCT_IDENTIFIER}}"
pre-build:
summary: Pre-build hooks