feat(go-swagger): Improve Makefile
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
b7f0d796e4
commit
edbd97705a
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user