diff --git a/README.md b/README.md index 3d175eb..ead08de 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ ## Projects -A portable CLI tool for initializing programming projects from pre-defined templates. This tools is written in GoLang and doesn't have any 3rd-party dependencies. +A portable CLI tool for initializing programming projects from pre-defined templates. This tools is written in GoLang and doesn't have any 3rd-party dependencies. + + +### Inspiration +Golang's tooling is fantastic. It is simple and doesn't require any additional setup for testing, formatting etc. It would be nice if we could replicate a similar experience with other programming languages. Hence, this project was born. ### Installation @@ -31,7 +35,7 @@ Usage of projects: -name string Name of project being initialized (default "sandbox") -template string - Project template to use (default "cpp-cmake") + Project template to use (default "go") ``` ### Available templates @@ -40,6 +44,7 @@ Usage of projects: $ projects -list Valid templates include: + - go - c - cpp-cmake - cpp-make diff --git a/internal/templates/golang/golang.go b/internal/templates/golang/golang.go new file mode 100644 index 0000000..cf94fc0 --- /dev/null +++ b/internal/templates/golang/golang.go @@ -0,0 +1,23 @@ +package golang + +import ( + "path/filepath" + + "github.com/moeenn/projects/internal/templates" +) + +func NewGolangConfig(args *templates.TemplateArgs) *templates.TemplateConfig { + files := map[string]string{ + "go.main_go": filepath.Join(args.RootPath, "main.go"), + "go.go_mod": filepath.Join(args.RootPath, "go.mod"), + } + + return &templates.TemplateConfig{ + Directories: []string{}, + Files: files, + Gitignore: []string{ + args.ProjectName, + ".DS_Store", + }, + } +} diff --git a/main.go b/main.go index 047695b..793d62e 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/moeenn/projects/internal/templates/c" "github.com/moeenn/projects/internal/templates/cppCmake" "github.com/moeenn/projects/internal/templates/cppMake" + "github.com/moeenn/projects/internal/templates/golang" "github.com/moeenn/projects/internal/templates/javaGradle" "github.com/moeenn/projects/internal/templates/js" "github.com/moeenn/projects/internal/templates/python" @@ -23,8 +24,8 @@ import ( var stubFS embed.FS var ( - TEMPLATE_NAMES = [7]string{ - "c", "cpp-cmake", "cpp-make", "javascript (or 'js')", "typescript (or 'ts')", "java-gradle", "python (or 'py')", + TEMPLATE_NAMES = [8]string{ + "go", "c", "cpp-cmake", "cpp-make", "javascript (or 'js')", "typescript (or 'ts')", "java-gradle", "python (or 'py')", } ) @@ -65,6 +66,10 @@ func run() error { config = cppCmake.NewCPPCmakeConfig(templateArgs) err = templateArgs.Initialize("C++ (Cmake)", config) + case "go": + config = golang.NewGolangConfig(templateArgs) + err = templateArgs.Initialize("Golang", config) + case "js", "javascript": config = js.NewJSConfig(templateArgs) err = templateArgs.Initialize("Javascript (vanilla)", config) diff --git a/stubs/golang/go.go_mod.stub b/stubs/golang/go.go_mod.stub new file mode 100644 index 0000000..e06c139 --- /dev/null +++ b/stubs/golang/go.go_mod.stub @@ -0,0 +1,5 @@ +{{ define "go.go_mod" }} +module {{ .ProjectName }} + +go 1.22.0 +{{ end }} \ No newline at end of file diff --git a/stubs/golang/go.main_go.stub b/stubs/golang/go.main_go.stub new file mode 100644 index 0000000..e8e935e --- /dev/null +++ b/stubs/golang/go.main_go.stub @@ -0,0 +1,11 @@ +{{ define "go.main_go" }} +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello world") +} +{{ end }} \ No newline at end of file