project_generation

package
v0.61.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 14 Imported by: 0

README

Project Generation

What

If you do not have a folder structure for your project, and one doesn't exist on GitHub for your project, then this project templating tool will do this for you. If you wish, it will also create the repo on GitHub for you.

This tool can be used to create projects of the following types:

How to use

It is always beneficial to ensure you are using the most up to date version of the dp-cli tool. To update pull the latest changes and rebuild the tool like so:

git pull; make install; 
dp generate-project

This tool can be used in conjunction with the repository creation tool, for further details read COMPLETE_PROJECT_SETUP.md

Optional flags

Although these flags are optional, for most, if they are not provided then the user will be prompted for details.

  • --name : The name of the application, if Dissemination specific application it should be prepended with 'dis-'
  • --description: Description for the application
  • --rt-version : The version of the runtime (Go or Node.js) the application should use (Not used on generic-projects; Node.js is only used when generating a library)
  • --go-version : (Deprecated) Use --rt-version instead. The version of Go the application should use (Not used on generic-projects)
  • --project-location : Location to generate project in
  • --create-repository : Should a repository be created for the project, default no. Value can be y/Y/yes/YES/ or n/N/no/NO
  • --port : Port number for the application
  • --type : Type of application to generate, values can be: generic-project, base-application, api, controller, event-driven, library
  • --team-slugs : Comma separated list of team slugs for ownership
Example output

The project generation command has been used to create example outputs of the various types of project. These can be found in the dp-hello-world repository. This provides a place where issues and discussions around the content of the base projects can be discussed and agreed upon. Once agreed upon there, the changes need to be applied to the templates in this repository and the example output can be regenerated with the new version of this tool, ready for further improvements.

What is created?
Generic Project

This option creates:

  • CONTRIBUTING.md
  • LICENSE.md
  • README.md
  • CODEOWNERS
  • PULL_REQUEST_TEMPLATE
  • ISSUES_TEMPLATE
  • .gitignore
Base Application

This option creates:

  • everything in generic-project plus
  • ci folder
  • config folder
  • Dockerfile.concourse
  • go.mod
  • Makefile
  • go.sum
  • <repo_name>.nomad
API

This option creates:

  • everything in base-application plus
  • main.go
  • service folder
  • api folder
  • swagger.yaml
Controller

This option creates:

  • everything in base-application plus
  • handlers folder
  • mapper folder
  • routes
Event Driven

This option creates:

  • everything in base-application plus
  • event folder
  • schema
  • service
  • cmd
Library

This option creates:

  • everything in generic-project plus
  • ci folder
  • makefile
  • go.mod

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FinaliseJSModules added in v0.56.0

func FinaliseJSModules(ctx context.Context, pathToRepo string)

FinaliseJSModules runs `npm install` to ensure dependencies are up to date and clean.

func FinaliseModules

func FinaliseModules(ctx context.Context, pathToRepo string, opts ...AppOptions)

FinaliseModules will run go build ./... to generate go modules dependency management files

func FormatGoFiles

func FormatGoFiles(ctx context.Context, pathToRepo string)

FormatGoFiles will run go fmt ./... to ensure all generated code conforms to standards

func GenerateProject

func GenerateProject(appName, appDesc, projType, projectLocation, runtimeVer, port, teamSlugs, projectLanguage string, repositoryCreated bool) error

GenerateProject is the entry point into generating a project

func GetTemplatePath

func GetTemplatePath() string

func InitGoModules

func InitGoModules(ctx context.Context, pathToRepo, name string) error

InitGoModules will initialise the go modules for a project at a given directory unless go.mod already exists

func IsEmptyDir

func IsEmptyDir(path string) (isEmptyDir bool, err error)

IsEmptyDir will check if a given directory is empty or not

func OfferPurgeProjectDestination

func OfferPurgeProjectDestination(ctx context.Context, projectPath string) error

OfferPurgeProjectDestination will offer the user an option to purge the contents at a given location

func OptionPromptInput

func OptionPromptInput(ctx context.Context, prompt string, options ...string) (string, error)

func PromptForConfirmation

func PromptForConfirmation(ctx context.Context, prompt string, maxInputAttempts int) bool

PromptForConfirmation will prompt for yes/no style answers on command-line

func PromptForInput

func PromptForInput(ctx context.Context, prompt string) (string, error)

PromptForInput will write a line to output then wait for input which is returned from the function

func SetTemplatePath

func SetTemplatePath(path string)

func ValidVersionNumber

func ValidVersionNumber(ver string) bool

func ValidateAppDescription

func ValidateAppDescription(ctx context.Context, description string) (string, error)

ValidateAppDescription will ensure that the app description has been provided and is acceptable, if not it will keep prompting until it is

func ValidateAppName

func ValidateAppName(ctx context.Context, name string) (string, error)

ValidateAppName will ensure that the app name has been provided and is acceptable, if not it will keep prompting until it is

func ValidateArguments

func ValidateArguments(arguments map[string]*Argument) (map[string]*Argument, error)

func ValidateBranchingStrategy

func ValidateBranchingStrategy(ctx context.Context, branchingStrategy string) (string, error)

ValidateBranchingStrategy will ensure that the strategy provided by the user is one that can be boilerplate

func ValidateGoVersion

func ValidateGoVersion(ctx context.Context, goVer string) (string, error)

ValidateGoVersion will ensure that the golang docker hub image version provided by the user is valid

func ValidateNodeVersion added in v0.56.0

func ValidateNodeVersion(ctx context.Context, nodeVer string) (string, error)

ValidateNodeVersion will ensure that the node docker hub image version provided by the user is valid

func ValidatePortNumber

func ValidatePortNumber(ctx context.Context, port string) (validatedPort string, err error)

func ValidateProjectDirectory

func ValidateProjectDirectory(ctx context.Context, path, projectName string) error

func ValidateProjectLanguage added in v0.56.0

func ValidateProjectLanguage(ctx context.Context, projectLanguage string) (validatedProjectType string, err error)

ValidateProjectLanguage will ensure that the project language provided by the users is one that can be boilerplate

func ValidateProjectLocation

func ValidateProjectLocation(ctx context.Context, projectLocation string) (string, error)

ValidateProjectLocation will ensure that the projects location has been provided and is acceptable. It will ensure the directory exists and has the option to offer a purge of files at that location

func ValidateProjectType

func ValidateProjectType(ctx context.Context, projectType string) (validatedProjectType string, err error)

ValidateProjectType will ensure that the project type provided by the users is one that can be boilerplate

func ValidateTeamSlugs added in v0.52.0

func ValidateTeamSlugs(ctx context.Context, teamSlugs string) (string, error)

func ValidateVersion added in v0.56.0

func ValidateVersion(ctx context.Context, version, prompt string) (string, error)

ValidateVersion will ensure that the provided version is valid

Types

type AppOptions

type AppOptions struct {
	Type ProjectType
}

type Argument

type Argument struct {
	Validator func(context.Context, string) (string, error)
	Context   context.Context
	InputVal  string
	OutputVal string
}

type ListOfArguments

type ListOfArguments map[string]*Argument

type ProjectType

type ProjectType string
const (
	GenericProject  ProjectType = "generic-project"
	BaseApplication ProjectType = "base-application"
	API             ProjectType = "api"
	Controller      ProjectType = "controller"
	EventDriven     ProjectType = "event-driven"
	Library         ProjectType = "library"
)

type TemplateModel

type TemplateModel struct {
	Name           string
	Description    string
	Year           int
	RuntimeVersion string
	DebianCodename string
	Port           string
	TeamSlugs      []string
}

func PopulateTemplateModel

func PopulateTemplateModel(name, desc, runtimeVer, debCN, port string, teamSlugs []string) TemplateModel

PopulateTemplateModel will populate the templating model with variables that can be used in templates

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL