5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:39:21 +08:00
wails/v2/internal/runtime/scripts/rebuild.go
Eng Zer Jun ef8d7d2fd7
refactor: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-11-25 12:15:43 +08:00

85 lines
2.1 KiB
Go

package main
import (
"bytes"
"fmt"
"log"
"os"
"strings"
"github.com/wailsapp/wails/v2/internal/fs"
"github.com/wailsapp/wails/v2/internal/shell"
)
func main() {
sourceDir := fs.RelativePath("../../../internal/runtime/js")
platforms := []string{"darwin", "windows", "linux"}
for _, platform := range platforms {
println("Building JS Runtime for " + platform)
envvars := []string{"WAILSPLATFORM=" + platform}
// Split up the InstallCommand and execute it
stdout, stderr, err := shell.RunCommand(sourceDir, "npm", "install")
if err != nil {
for _, l := range strings.Split(stdout, "\n") {
fmt.Printf(" %s\n", l)
}
for _, l := range strings.Split(stderr, "\n") {
fmt.Printf(" %s\n", l)
}
}
runtimeDir := fs.RelativePath("../js")
cmd := shell.CreateCommand(runtimeDir, "npm", "run", "build:desktop")
cmd.Env = append(os.Environ(), envvars...)
var stdo, stde bytes.Buffer
cmd.Stdout = &stdo
cmd.Stderr = &stde
err = cmd.Run()
if err != nil {
for _, l := range strings.Split(stdo.String(), "\n") {
fmt.Printf(" %s\n", l)
}
for _, l := range strings.Split(stde.String(), "\n") {
fmt.Printf(" %s\n", l)
}
log.Fatal(err)
}
wailsJS := fs.RelativePath("../assets/desktop_" + platform + ".js")
runtimeData, err := os.ReadFile(wailsJS)
if err != nil {
log.Fatal(err)
}
// Copy this file to bridge directory for embedding
bridgeDir := fs.RelativePath("../../bridge/" + platform + ".js")
println("Copying", wailsJS, "to", bridgeDir)
err = fs.CopyFile(wailsJS, bridgeDir)
if err != nil {
log.Fatal(err)
}
// Convert to C structure
runtimeC := `
// runtime.c (c) 2019-Present Lea Anthony.
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file was auto-generated. DO NOT MODIFY.
const unsigned char runtime[]={`
for _, b := range runtimeData {
runtimeC += fmt.Sprintf("0x%x, ", b)
}
runtimeC += "0x00};"
// Save file
outputFile := fs.RelativePath(fmt.Sprintf("../../ffenestri/runtime_%s.c", platform))
if err := os.WriteFile(outputFile, []byte(runtimeC), 0600); err != nil {
log.Fatal(err)
}
}
}