Select Git revision
build.go 2.79 KiB
package _magefile
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, 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(`gitlab.com/ship-logic/backends/backend/core/%v`, handler)
err := BuildGolangApp(outputFile, appPath, isDebug)
if err != nil {
return err
}
// Copy files in handler folder
err = copyFilesToBuildDir(fullPath, outputDir)
if err != nil {
return err
}
// Copy shared files
err = copyFilesToBuildDir(currentDir+"/core/shared", outputDir)
if err != nil {
return err
}
if isDebug {
// copy env file
err = copyFilesToBuildDir(currentDir+"/.env.debug", outputDir)
if err != nil {