feat(init): Continue on template
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Matthieu 'JP' DERASSE
2022-08-09 21:37:57 +00:00
parent 3536298742
commit cf7901890c
13 changed files with 206 additions and 7 deletions

View File

@ -0,0 +1,13 @@
package base
import (
"github.com/juju/errors"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
"git.home.m-and-m.ovh/mderasse/gouick/models"
)
// CreateProjectSkeleton will generate all the files needed to start a new project.
func (a APIType) CreateProjectSkeleton(path string, config *models.Config) error {
return errors.NotImplementedf("%s not implemented for %s", helpers.GetCurrentFuncName(), a.GetName())
}

View File

@ -0,0 +1,13 @@
package base
import (
"github.com/juju/errors"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
"git.home.m-and-m.ovh/mderasse/gouick/models"
)
// GenerateMakefile will generate makefile based on the given config.
func (a APIType) GenerateMakefile(path string, config *models.Config) error {
return errors.NotImplementedf("%s not implemented for %s", helpers.GetCurrentFuncName(), a.GetName())
}

View File

@ -0,0 +1,4 @@
package go_swagger
// templateDirectory contain the path to the templates for that apiType.
const templateDirectory = "templates/go-swagger"

View File

@ -0,0 +1,44 @@
package go_swagger
import (
"path/filepath"
"github.com/juju/errors"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
log "github.com/sirupsen/logrus"
)
var standardDirectories = []string{
"api",
"chart",
"cmd",
"models",
"pkg",
"restapi",
"testdata",
}
// createDirectories will create all skeleton directories for the project.
func (a APIType) createDirectories(path string) error {
log.Debugf("Starting %s - %s", a.GetName(), helpers.GetCurrentFuncName())
for _, directory := range standardDirectories {
log.Debugf("Will create directory %s", directory)
fullPath := filepath.Join(path, directory)
created, err := helpers.CheckAndCreateDir(fullPath)
if err != nil {
log.Errorf("Failed to create directory %s", directory)
return errors.Trace(err)
}
if !created {
log.Debugf("Skipping directory %s", directory)
}
}
return nil
}

View File

@ -1,13 +1,32 @@
package go_swagger
import (
"github.com/juju/errors"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
"git.home.m-and-m.ovh/mderasse/gouick/models"
log "github.com/sirupsen/logrus"
)
// CreateProjectSkeleton will generate all the files needed to start a new project.
// it will return a list of created files or an error
func (a APIType) CreateProjectSkeleton(path string) ([]string, error) {
log.Debugf("Starting %s create project skeleton", string(a.GetName()))
func (a APIType) CreateProjectSkeleton(path string, config *models.Config) error {
log.Debugf("Starting %s - %s", a.GetName(), helpers.GetCurrentFuncName())
return nil, nil
err := a.createDirectories(path)
if err != nil {
log.Error("Fail to create project directories")
return errors.Trace(err)
}
// Generate Makefile
err = a.GenerateMakefile(path, config)
if err != nil {
log.Error("Fail to generate Makefile")
return errors.Trace(err)
}
// Generate Readme
// Generate api.yaml
return nil
}

View File

@ -0,0 +1,36 @@
package go_swagger
import (
"path/filepath"
"github.com/iancoleman/strcase"
"github.com/juju/errors"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
"git.home.m-and-m.ovh/mderasse/gouick/models"
log "github.com/sirupsen/logrus"
)
type makefile struct {
AppNameKebabCase string
}
// GenerateMakefile will generate makefile based on the given config.
func (a APIType) GenerateMakefile(path string, config *models.Config) error {
log.Debugf("Starting %s - %s", a.GetName(), helpers.GetCurrentFuncName())
templatePath := filepath.Join(templateDirectory, "Makefile.tmpl")
savePath := filepath.Join(path, "Makefile")
data := makefile{
AppNameKebabCase: strcase.ToKebab(config.ProjectName),
}
err := helpers.WriteTemplate(templatePath, savePath, data)
if err != nil {
return errors.Trace(err)
}
return nil
}

View File

@ -5,6 +5,8 @@ import "git.home.m-and-m.ovh/mderasse/gouick/models"
// APITypeInterface is the interface that need to be respected by an APIType.
type APITypeInterface interface {
CheckInitialize() error
GetName() models.APITypeName
CreateProjectSkeleton(path string, config *models.Config) error
GenerateMakefile(path string, config *models.Config) error
GetInitializeUserInput(params *models.Config) (*models.Config, error)
GetName() models.APITypeName
}