Select Git revision
-
Johan de Klerk authoredJohan de Klerk authored
build.go 3.41 KiB
package mage_helpers
import (
"fmt"
"os"
"os/exec"
"path"
"runtime"
"strings"
"github.com/magefile/mage/sh"
)
func Clean(path string) error {
cmd := exec.Command("rm", "-rf", "build")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = path
err := cmd.Run()
if err != nil {
return err
}
cmd = exec.Command("mkdir", "-p", "build")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = path
err = cmd.Run()
if err != nil {
return err
}
return nil
}
func Build(dir string, module string, isDebug bool) error {
currentDir, _ := os.Getwd()
fullPath := currentDir + "/core/" + dir
if err := Clean(fullPath); err != nil {
return err
}
handler := path.Base(fullPath)
fmt.Println(fmt.Sprintf("Building %v", handler))
outputDir := fmt.Sprintf(currentDir+`/core/build/handlers/%v`, handler)
outputFile := fmt.Sprintf(`%v/%v`, outputDir, handler)
appPath := fmt.Sprintf(`%v/core/%v`, module, handler)
err := BuildGolangApp(outputFile, appPath, module, isDebug)
if err != nil {
return err
}
// Copy files in handler folder
err = copyFilesToBuildDir(fullPath, outputDir)
if err != nil {
return err
}
// Copy shared files
sharedDir := currentDir + "/core/utils"
_, err = os.Stat(sharedDir)
if err == nil {
err = copyFilesToBuildDir(sharedDir, outputDir)
if err != nil {
return err
}
}