build.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package got
  2. import (
  3. "fmt"
  4. "os"
  5. . "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/common"
  6. )
  7. var Build = func(project *Project, buildOptions *BuildOptions) (fn *BuildSet, err error) {
  8. var (
  9. files []os.FileInfo
  10. before = []*Command{
  11. {
  12. Cmd: "rm -f go.*",
  13. Description: "Remove os arquivos do módulo do GO",
  14. },
  15. {
  16. Cmd: "go mod init {project.custom.go.package.repository}/build",
  17. Description: "Inicializa o módulo do GO",
  18. },
  19. }
  20. )
  21. if files, err = GetFiles(project.Paths.Include("/go")); err == nil {
  22. for _, file := range files {
  23. if file.Name()[0] == '*' {
  24. continue
  25. }
  26. if file.IsDir() {
  27. name := file.Name()
  28. before = append(before, &Command{
  29. Cmd: fmt.Sprintf("go mod edit -replace {project.custom.go.package.repository}/build/v1/%s=./v1/%s", name, name),
  30. Description: "Inicializa o módulo do GO",
  31. })
  32. }
  33. }
  34. }
  35. fn = &BuildSet{
  36. Before: before,
  37. After: []*Command{
  38. {
  39. Id: "build",
  40. Cmd: "GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ../dist/server",
  41. Description: "Compila a aplicação server da api",
  42. },
  43. // {
  44. // Id: "clear",
  45. // Cmd: "",
  46. // Description: "Clear temporary files",
  47. // },
  48. },
  49. }
  50. return
  51. }