From 5a55cd5cd9ed3d292418d38965837a33ba8ffdf8 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 15 Mar 2019 16:15:23 +0100 Subject: [PATCH] feat: make it possible to use a template and still add ap4k dependency --- pkg/server/server.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index c9a4364..d486275 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -175,15 +175,28 @@ func CreateZipFile(w http.ResponseWriter, r *http.Request) { p.PackageName = params.Get("packagename") p.OutDir = params.Get("outdir") - if len(params["module"]) > 0 { - p.Modules = asModuleArray(params["module"]) + modules := params["module"] + hasModules := len(modules) > 0 + if hasModules { + p.Modules = asModuleArray(modules) } - // As dependencies and template selection can't be used together, we force the template to be equal to "custom" - // when a user selects a different template. This is because we would like to avoid to populate a project with starters - // which are incompatible or not fully tested with the template proposed - if len(params["module"]) > 0 && p.Template != "custom" { - p.Template = "custom" + useAp4k, _ := strconv.ParseBool(params.Get("ap4k")) + if useAp4k { + // make sure we have ap4k as a dependency + p.Modules = append(p.Modules, scaffold.Module{Name: "ap4k"}) + } + + if hasModules && p.Template != "custom" { + if useAp4k { + // if we asked to use ap4k, keep the template value but reset the modules to only ap4k to avoid incompatibilities + p.Modules = []scaffold.Module{{Name: "ap4k"}} + } else { + // As dependencies and template selection can't be used together, we force the template to be equal to "custom" + // when a user selects a different template. This is because we would like to avoid to populate a project with starters + // which are incompatible or not fully tested with the template proposed + p.Template = "custom" + } } log.Infof("Received request: %s", r.URL)