From f9834dc9ca4e60ce32ad9381c0e079fe7c625fde Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 2 Nov 2019 06:46:46 +1100 Subject: [PATCH] feat: go build script --- scripts/build.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 scripts/build.go diff --git a/scripts/build.go b/scripts/build.go new file mode 100644 index 00000000..20d31c79 --- /dev/null +++ b/scripts/build.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" +) + +// Default target to run when none is specified +// If not set, running mage will list available targets +// var Default = Build + +/* +# Build runtime +echo "**** Building Runtime ****" +cd runtime/js +npm install +npm run build +cd ../.. + +echo "**** Packing Assets ****" +cd cmd +mewn +cd .. +cd lib/renderer +mewn +cd ../.. + +echo "**** Installing Wails locally ****" +cd cmd/wails +go install +cd ../.. + +echo "**** Tidying the mods! ****" +go mod tidy + +echo "**** WE ARE DONE! ****" + +*/ + +func runCommand(command string, args ...string) { + cmd := exec.Command(command, args...) + output, err := cmd.CombinedOutput() + if err != nil { + log.Fatal(err) + } + cmd.Run() + fmt.Println(string(output)) +} + +// A build step that requires additional params, or platform specific steps for example +func main() { + + dir, _ := os.Getwd() + + // Build Runtime + fmt.Println("**** Building Runtime ****") + runtimeDir, _ := filepath.Abs(filepath.Join(dir, "..", "runtime", "js")) + os.Chdir(runtimeDir) + runCommand("npm", "install") + runCommand("npm", "run", "build") + + // Pack assets + fmt.Println("**** Packing Assets ****") + rendererDir, _ := filepath.Abs(filepath.Join(dir, "..", "lib", "renderer")) + os.Chdir(rendererDir) + runCommand("mewn") + cmdDir, _ := filepath.Abs(filepath.Join(dir, "..", "cmd")) + os.Chdir(cmdDir) + runCommand("mewn") + + // Install Wails + fmt.Println("**** Installing Wails locally ****") + execDir, _ := filepath.Abs(filepath.Join(dir, "..", "cmd", "wails")) + os.Chdir(execDir) + runCommand("go", "install") + + baseDir, _ := filepath.Abs(filepath.Join(dir, "..")) + os.Chdir(baseDir) + runCommand("go", "mod", "tidy") +}