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:
parent
e4cfae2885
commit
f078ee9f9a
@ -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)
|
||||
|
@ -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)
|
||||
|
47
v3/internal/commands/runtime.go
Normal file
47
v3/internal/commands/runtime.go
Normal 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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user