diff --git a/helpers/api_types/go_swagger/generate_launcher.go b/helpers/api_types/go_swagger/generate_launcher.go index 8a0d0f8..432aba0 100644 --- a/helpers/api_types/go_swagger/generate_launcher.go +++ b/helpers/api_types/go_swagger/generate_launcher.go @@ -24,11 +24,7 @@ func (a APIType) GenerateLauncher(path string, config *models.Config) error { templatePath := filepath.Join(templateDirectory, "launcher.sh.tmpl") savePath := filepath.Join(path, "launcher.sh") - data := launcherTemplate{ - APIs: []*models.Process{}, - Crons: []*models.Process{}, - Workers: []*models.Process{}, - } + data := launcherTemplate{} processes, err := a.getProcesses(path) if err != nil { diff --git a/helpers/api_types/go_swagger/generate_makefile.go b/helpers/api_types/go_swagger/generate_makefile.go index 905cbe4..a21c622 100644 --- a/helpers/api_types/go_swagger/generate_makefile.go +++ b/helpers/api_types/go_swagger/generate_makefile.go @@ -3,7 +3,6 @@ package go_swagger import ( "path/filepath" - "github.com/iancoleman/strcase" "github.com/juju/errors" "git.home.m-and-m.ovh/mderasse/gouick/helpers" @@ -13,7 +12,9 @@ import ( ) type makefileTemplate struct { - AppNameKebabCase string + APIs []*models.Process + Crons []*models.Process + Workers []*models.Process } // GenerateMakefile will generate makefile based on the given config. @@ -24,11 +25,26 @@ func (a APIType) GenerateMakefile(path string, config *models.Config) error { templatePath := filepath.Join(templateDirectory, "Makefile.tmpl") savePath := filepath.Join(path, "Makefile") - data := makefileTemplate{ - AppNameKebabCase: strcase.ToKebab(config.ProjectName), + data := makefileTemplate{} + + processes, err := a.getProcesses(path) + if err != nil { + log.Error("Fail to list processes") + return errors.Trace(err) } - err := helpers.WriteTemplate(templatePath, savePath, data) + for _, process := range processes { + switch process.Type { + case models.ProcessType_API: + data.APIs = append(data.APIs, process) + case models.ProcessType_CRON: + data.Crons = append(data.Crons, process) + case models.ProcessType_WORKER: + data.Workers = append(data.Workers, process) + } + } + + err = helpers.WriteTemplate(templatePath, savePath, data) if err != nil { return errors.Trace(err) } diff --git a/templates/go-swagger/Makefile.tmpl b/templates/go-swagger/Makefile.tmpl index 7e64aa8..e72b8e1 100644 --- a/templates/go-swagger/Makefile.tmpl +++ b/templates/go-swagger/Makefile.tmpl @@ -1,11 +1,49 @@ # Code generated by gouick; DO NOT EDIT. -APICMD= go run cmd/{{ .AppNameKebabCase }}-server/* -CMD= env PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} $(APICMD) +{{ if eq (len .APIs) 1 }} +api: + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @echo "\tLaunch API '{{ (index .APIs 0).Binary }}'" + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \ + go run cmd/{{ (index .APIs 0).Binary }}/* +{{ else if gt (len .APIs) 1 }} +{{- range .APIs -}} +{{.Binary}} +{{ end }}: + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @echo "\tLaunch API '$@'" + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \ + go run cmd/$@/main.go +{{ end }} +{{- if ne (len .Workers) 0 }} +{{- range .Workers -}} +{{.Binary}} +{{ end }}: + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @echo "\tLaunch worker '$@'" + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \ + go run cmd/$@/main.go +{{ end }} + +{{- if ne (len .Crons) 0 }} +{{- range .Crons -}} +{{.Binary}} +{{ end }}: + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @echo "\tLaunch cron '$@'" + @echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + @PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \ + go run cmd/$@/main.go +{{ end }} generate: - gouick generate + @gouick generate -launch: - @$(CMD) +test: + @gouick test + +.PHONY: api generate test diff --git a/templates/go-swagger/launcher.sh.tmpl b/templates/go-swagger/launcher.sh.tmpl index 7e59937..52584da 100644 --- a/templates/go-swagger/launcher.sh.tmpl +++ b/templates/go-swagger/launcher.sh.tmpl @@ -1,4 +1,5 @@ #!/bin/sh +# Code generated by gouick; DO NOT EDIT. # the launcher file will launch the correct app / worker based on the given env variable # the main goal of that launcher is to be used as a Docker entrypoint