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

Support wails3 generate runtime

This commit is contained in:
Lea Anthony 2024-11-03 17:28:32 +11:00
parent e4cfae2885
commit f078ee9f9a
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
3 changed files with 49 additions and 0 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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).
- Example to test the HTML Drag and Drop API by [FerroO2000](https://github.com/FerroO2000) in [#3856](https://github.com/wailsapp/wails/pull/3856)
- New `wails3 generate runtime` 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

@ -48,6 +48,7 @@ func main() {
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("runtime", "Generate the pre-built version of the runtime", commands.GenerateRuntime)
update := app.NewSubCommand("update", "Update tools")
update.NewSubCommandFunction("build-assets", "Updates the build assets using the given config file", commands.UpdateBuildAssets)

View File

@ -0,0 +1,47 @@
package commands
import (
"io"
"os"
"path/filepath"
"runtime"
)
type RuntimeOptions struct {
Directory string `name:"d" description:"Directory to generate runtime file in" default:"."`
}
func GenerateRuntime(options *RuntimeOptions) error {
DisableFooter = true
_, thisFile, _, _ := runtime.Caller(0)
localDir := filepath.Dir(thisFile)
bundledAssetsDir := filepath.Join(localDir, "..", "assetserver", "bundledassets")
runtimeJS := filepath.Join(bundledAssetsDir, "runtime.js")
err := CopyFile(runtimeJS, filepath.Join(options.Directory, "runtime.js"))
if err != nil {
return err
}
runtimeDebugJS := filepath.Join(bundledAssetsDir, "runtime.debug.js")
err = CopyFile(runtimeDebugJS, filepath.Join(options.Directory, "runtime-debug.js"))
if err != nil {
return err
}
return nil
}
func CopyFile(source string, target string) error {
s, err := os.Open(source)
if err != nil {
return err
}
defer s.Close()
d, err := os.Create(target)
if err != nil {
return err
}
if _, err := io.Copy(d, s); err != nil {
d.Close()
return err
}
return d.Close()
}