5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 21:30:39 +08:00

Support updating the build assets

This commit is contained in:
Lea Anthony 2024-10-24 10:07:11 +11:00
parent 4325b06ac4
commit 1cb7a33442
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
12 changed files with 136 additions and 18 deletions

View File

@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Templates for sveltekit and sveltekit-ts that are set for non-SSR development by [atterpac](https://github.com/atterpac) in [#3829](https://github.com/wailsapp/wails/pull/3829)
- Update build assets using new `wails3 update build-assets` command by [leaanthony](https://github.com/leaanthony).
### Changed
- Taskfile refactor by [leaanthony](https://github.com/leaanthony) in [#3748](https://github.com/wailsapp/wails/pull/3748)

View File

@ -35,6 +35,7 @@ func main() {
app.NewSubCommandFunction("dev", "Run in Dev mode", commands.Dev)
app.NewSubCommandFunction("package", "Package application", commands.Package)
app.NewSubCommandFunction("doctor", "System status report", commands.Doctor)
task := app.NewSubCommand("task", "Run and list tasks")
var taskFlags commands.RunTaskOptions
task.AddFlags(&taskFlags)
@ -42,10 +43,15 @@ func main() {
return commands.RunTask(&taskFlags, task.OtherArgs())
})
task.LongDescription("\nUsage: wails3 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("build-assets", "Generate build assets", commands.GenerateBuildAssets)
generate.NewSubCommandFunction("icons", "Generate icons", commands.GenerateIcons)
generate.NewSubCommandFunction("syso", "Generate Windows .syso file", commands.GenerateSyso)
update := app.NewSubCommand("update", "Update tools")
update.NewSubCommandFunction("build-assets", "Updates the build assets using the given config file", commands.UpdateBuildAssets)
bindgen := generate.NewSubCommand("bindings", "Generate bindings + models")
var bindgenFlags flags.GenerateBindingsOptions
bindgen.AddFlags(&bindgenFlags)
@ -59,6 +65,7 @@ func main() {
plugin := app.NewSubCommand("service", "Service tools")
plugin.NewSubCommandFunction("init", "Initialise a new service", commands.ServiceInit)
tool := app.NewSubCommand("tool", "Various tools")
tool.NewSubCommandFunction("checkport", "Checks if a port is open. Useful for testing if vite is running.", commands.ToolCheckPort)
tool.NewSubCommandFunction("watcher", "Watches files and runs a command when they change", commands.Watcher)
@ -67,6 +74,7 @@ func main() {
app.NewSubCommandFunction("version", "Print the version", commands.Version)
app.NewSubCommand("sponsor", "Sponsor the project").Action(openSponsor)
defer printFooter()
err := app.Run()

View File

@ -33,7 +33,8 @@ require (
github.com/wailsapp/mimetype v1.4.1
golang.org/x/sys v0.20.0
golang.org/x/term v0.20.0
golang.org/x/tools v0.21.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.21.0
)
@ -84,14 +85,13 @@ require (
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/image v0.15.0 // indirect
golang.org/x/image v0.21.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect

View File

@ -240,8 +240,8 @@ golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
@ -259,8 +259,8 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -302,14 +302,14 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -5,6 +5,7 @@ import (
_ "embed"
"fmt"
"github.com/leaanthony/gosod"
"gopkg.in/yaml.v3"
"io/fs"
"os"
"path/filepath"
@ -16,8 +17,11 @@ import (
//go:embed build_assets
var buildAssets embed.FS
//go:embed updatable_build_assets
var updatableBuildAssets embed.FS
type BuildAssetsOptions struct {
Dir string `description:"The directory to generate the files into" default:"build"`
Dir string `description:"The directory to generate the files into" default:"."`
Name string `description:"The name of the project"`
Binary string `description:"The name of the binary"`
ProductName string `description:"The name of the product" default:"My Product"`
@ -30,6 +34,23 @@ type BuildAssetsOptions struct {
Silent bool `description:"Suppress output to console"`
}
type UpdateBuildAssetsOptions struct {
Dir string `description:"The directory to generate the files into" default:"build"`
Config string `description:"The config file to use" default:"appdata.yaml"`
Silent bool `description:"Suppress output to console"`
}
type Config struct {
Binary string `yaml:"binaryName"`
ProductCompany string `yaml:"companyName"`
ProductName string `yaml:"productName"`
ProductIdentifier string `yaml:"productIdentifier"`
ProductDescription string `yaml:"description"`
ProductVersion string `yaml:"productVersion"`
ProductCopyright string `yaml:"copyright"`
ProductComments string `yaml:"comments"`
}
func GenerateBuildAssets(options *BuildAssetsOptions) error {
DisableFooter = true
@ -70,8 +91,71 @@ func GenerateBuildAssets(options *BuildAssetsOptions) error {
if !options.Silent {
println("Generating build assets in " + options.Dir)
}
err = gosod.New(tfs).Extract(options.Dir, options)
if err != nil {
return err
}
tfs, err = fs.Sub(updatableBuildAssets, "updatable_build_assets")
if err != nil {
return err
}
return gosod.New(tfs).Extract(options.Dir, options)
}
func UpdateBuildAssets(options *UpdateBuildAssetsOptions) error {
DisableFooter = true
if options.Config == "" {
return fmt.Errorf("config file required for update")
}
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
}
}
tfs, err := fs.Sub(updatableBuildAssets, "updatable_build_assets")
if err != nil {
return err
}
configFile := filepath.Join(options.Dir, options.Config)
if _, err := os.Stat(configFile); os.IsNotExist(err) {
return fmt.Errorf("config file %s does not exist", configFile)
}
config, err := os.ReadFile(configFile)
if err != nil {
return err
}
var configData Config
err = yaml.Unmarshal(config, &configData)
if err != nil {
return err
}
fmt.Printf("%+v\n", configData)
err = gosod.New(tfs).Extract(options.Dir, configData)
if err != nil {
return err
}
if !options.Silent {
println("Successfully updated build assets in " + options.Dir)
}
return nil
}
func normaliseName(name string) string {

View File

@ -0,0 +1,25 @@
# The name of the company
companyName: "{{.ProductCompany}}"
# The name of the application
productName: "{{.ProductName}}"
# The unique product identifier
productIdentifier: "{{.ProductIdentifier}}"
# The application description
description: "{{.ProductDescription}}"
# The application version
productVersion: "{{.ProductVersion}}"
# Copyright text
copyright: "{{.ProductCopyright}}"
# Comments
comments: "{{.ProductComments}}"
# The name of the binary.
# Only update this if you have changed it in `Taskfile.yml`
binaryName: "{{.Name}}"

View File

@ -43,13 +43,13 @@ func Init(options *flags.Init) error {
Name: options.ProjectName,
Dir: filepath.Join(options.ProjectDir, "build"),
Silent: true,
ProductComments: options.ProductComments,
ProductCompany: options.ProductCompany,
ProductDescription: options.ProductDescription,
ProductName: options.ProductName,
ProductDescription: options.ProductDescription,
ProductVersion: options.ProductVersion,
ProductIdentifier: options.ProductIdentifier,
ProductCopyright: options.ProductCopyright,
ProductComments: options.ProductComments,
}
return GenerateBuildAssets(buildAssetsOptions)
}

View File

@ -6,7 +6,7 @@
<key>CFBundleName</key>
<string>{{.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.Name}}</string>
<string>{{.Binary}}</string>
<key>CFBundleIdentifier</key>
<string>{{.ProductIdentifier}}</string>
<key>CFBundleVersion</key>

View File

@ -6,7 +6,7 @@
<key>CFBundleName</key>
<string>{{.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.Name}}</string>
<string>{{.Binary}}</string>
<key>CFBundleIdentifier</key>
<string>{{.ProductIdentifier}}</string>
<key>CFBundleVersion</key>