diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index d0b7a79e5..5448ff383 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -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) diff --git a/v3/cmd/wails3/main.go b/v3/cmd/wails3/main.go index 98456b393..0d229117a 100644 --- a/v3/cmd/wails3/main.go +++ b/v3/cmd/wails3/main.go @@ -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) diff --git a/v3/internal/commands/runtime.go b/v3/internal/commands/runtime.go new file mode 100644 index 000000000..7414c8b32 --- /dev/null +++ b/v3/internal/commands/runtime.go @@ -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() +}