From 18fd8ca15f6cfd4cdf488fb0dc949d6c189a5c30 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Fri, 3 Nov 2023 11:39:05 +0530 Subject: [PATCH 01/12] feat: Initialize Git repository for new feature --- cmd/program/program.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/program/program.go b/cmd/program/program.go index 63f2bbe8..4e275b72 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -5,6 +5,7 @@ import ( "html/template" "log" "os" + "os/exec" tea "github.com/charmbracelet/bubbletea" tpl "github.com/melkeydev/go-blueprint/cmd/template" @@ -172,6 +173,16 @@ func (p *Project) CreateMainFile() error { return err } + // Initialize git repo + gitInitCmd := exec.Command("npx", "gitignore", "go") + gitInitCmd.Dir = projectPath + gitInitCmd.Stdout = os.Stdout + gitInitCmd.Stderr = os.Stderr + if err := gitInitCmd.Run(); err != nil { + log.Printf("Error initializing Git repository: %v", err) + return nil + } + return nil } From dd2e39f9c7aad388cfb7b98d9c933544d5a4b15d Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Fri, 3 Nov 2023 12:14:56 +0530 Subject: [PATCH 02/12] fix: git init and creating .gitigonre file --- cmd/program/program.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index 4e275b72..cf7d25b3 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -5,8 +5,6 @@ import ( "html/template" "log" "os" - "os/exec" - tea "github.com/charmbracelet/bubbletea" tpl "github.com/melkeydev/go-blueprint/cmd/template" "github.com/melkeydev/go-blueprint/cmd/utils" @@ -173,17 +171,21 @@ func (p *Project) CreateMainFile() error { return err } - // Initialize git repo - gitInitCmd := exec.Command("npx", "gitignore", "go") - gitInitCmd.Dir = projectPath - gitInitCmd.Stdout = os.Stdout - gitInitCmd.Stderr = os.Stderr - if err := gitInitCmd.Run(); err != nil { - log.Printf("Error initializing Git repository: %v", err) - return nil - } - - return nil + // Initialize git repo + err = utils.ExecuteCmd("git", []string{"init"}, projectPath) + if err != nil { + log.Printf("Error initializing git repo: %v", err) + cobra.CheckErr(err) + return err + } + // Create gitignore + err = utils.ExecuteCmd("npx", []string{"gitignore", "go"}, projectPath) + if err != nil { + log.Printf("Error creating gitignore: %v", err) + cobra.CheckErr(err) + return err + } + return nil } func (p *Project) CreatePath(pathToCreate string, projectPath string) error { From f29bc176bbfe949dac6dcdf6adf3eef571e68b26 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Sun, 5 Nov 2023 13:23:51 +0530 Subject: [PATCH 03/12] fix: injecting .gitignore file instead of using npx --- cmd/program/program.go | 42 +++++++++++++++++++++++++----------------- cmd/template/main.go | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index cf7d25b3..1f655cf1 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -2,9 +2,9 @@ package program import ( "fmt" - "html/template" - "log" - "os" + "html/template" + "log" + "os" tea "github.com/charmbracelet/bubbletea" tpl "github.com/melkeydev/go-blueprint/cmd/template" "github.com/melkeydev/go-blueprint/cmd/utils" @@ -172,20 +172,28 @@ func (p *Project) CreateMainFile() error { } // Initialize git repo - err = utils.ExecuteCmd("git", []string{"init"}, projectPath) - if err != nil { - log.Printf("Error initializing git repo: %v", err) - cobra.CheckErr(err) - return err - } - // Create gitignore - err = utils.ExecuteCmd("npx", []string{"gitignore", "go"}, projectPath) - if err != nil { - log.Printf("Error creating gitignore: %v", err) - cobra.CheckErr(err) - return err - } - return nil + err = utils.ExecuteCmd("git", []string{"init"}, projectPath) + if err != nil { + log.Printf("Error initializing git repo: %v", err) + cobra.CheckErr(err) + return err + } + // Create gitignore + gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) + if err != nil { + cobra.CheckErr(err) + return err + } + + defer gitignoreFile.Close() + + // inject gitignore template + gitignoreTemplate := template.Must(template.New(".gitignore").Parse(string(tpl.GitIgnoreTemplate()))) + err = gitignoreTemplate.Execute(gitignoreFile, p) + if err != nil { + return err + } + return nil } func (p *Project) CreatePath(pathToCreate string, projectPath string) error { diff --git a/cmd/template/main.go b/cmd/template/main.go index 7196781a..e264b89a 100644 --- a/cmd/template/main.go +++ b/cmd/template/main.go @@ -48,3 +48,27 @@ clean: .PHONY: all build run test clean `) } + +func GitIgnoreTemplate() []byte { + return []byte( + ` +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with "go test -c" +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + `) +} From 826eac1c6dd19a929617c9603c7e0b938fff80ef Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Mon, 6 Nov 2023 00:37:52 +0530 Subject: [PATCH 04/12] feat: Checkout to main branch after git init --- cmd/program/program.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/program/program.go b/cmd/program/program.go index dc6fb4d6..31e50147 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -199,6 +199,14 @@ func (p *Project) CreateMainFile() error { cobra.CheckErr(err) return err } + // Switch to main branch + err = utils.ExecuteCmd("git", []string{"branch", "-M", "main"}, projectPath) + if err != nil { + log.Printf("Error switching to main branch: %v", err) + cobra.CheckErr(err) + return err + } + // Create gitignore gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) if err != nil { From 499e23dcf245a47922ffdef8345e4523d3a67434 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Mon, 6 Nov 2023 12:58:16 +0530 Subject: [PATCH 05/12] fix: fix gitignore for air hot reload --- cmd/template/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/template/main.go b/cmd/template/main.go index 5740b191..daa5a114 100644 --- a/cmd/template/main.go +++ b/cmd/template/main.go @@ -71,6 +71,16 @@ func GitIgnoreTemplate() []byte { # Go workspace file go.work + +vendor/ +tmp/ + +# IDE specific files +.vscode +.idea + +# build output +air `) } func ReadmeTemplate() []byte { From 594a828f2dff258d73066a5981680b919d14f6a4 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Wed, 8 Nov 2023 12:01:24 +0530 Subject: [PATCH 06/12] fix: git checkout to main branch (resolved) --- cmd/program/program.go | 15 --------------- cmd/template/main.go | 8 +++----- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index d67a85e5..d334f39b 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -260,21 +260,6 @@ func (p *Project) CreateMainFile() error { return err } - // Create .air.toml file - airTomlFile, err := os.Create(fmt.Sprintf("%s/.air.toml", projectPath)) - if err != nil { - cobra.CheckErr(err) - return err - } - - defer airTomlFile.Close() - - // inject air.toml template - airTomlTemplate := template.Must(template.New("airtoml").Parse(string(tpl.AirTomlTemplate()))) - err = airTomlTemplate.Execute(airTomlFile, p) - if err != nil { - return err - } err = utils.GoFmt(projectPath) diff --git a/cmd/template/main.go b/cmd/template/main.go index 972f891d..50e92bfd 100644 --- a/cmd/template/main.go +++ b/cmd/template/main.go @@ -2,7 +2,7 @@ // help with the templating of created files. package template -// MakeHTTPRoutes returns a byte slice that represents +// MakeHTTPRoutes returns a byte slice that represents // the default cmd/api/main.go file template. func MainTemplate() []byte { return []byte(`package main @@ -23,7 +23,7 @@ func main() { `) } -// MakeHTTPRoutes returns a byte slice that represents +// MakeHTTPRoutes returns a byte slice that represents // the default Makefile. func MakeTemplate() []byte { return []byte( @@ -82,8 +82,6 @@ func GitIgnoreTemplate() []byte { # Go workspace file go.work - -vendor/ tmp/ # IDE specific files @@ -148,7 +146,7 @@ tmp_dir = "tmp" } -// ReadmeTemplate returns a byte slice that represents +// ReadmeTemplate returns a byte slice that represents // the default README.md file template. func ReadmeTemplate() []byte { return []byte( From cc30a7fcda5d0055e1a12043db55d25e572f31d8 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Wed, 8 Nov 2023 12:06:10 +0530 Subject: [PATCH 07/12] feat: rename master branch to main branch --- cmd/program/program.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index d334f39b..fe6d7051 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -222,11 +222,13 @@ func (p *Project) CreateMainFile() error { cobra.CheckErr(err) return err } - // Switch to main branch - err = utils.ExecuteCmd("git", []string{"branch", "-M", "main"}, projectPath) - if err != nil { - log.Printf("Error switching to main branch: %v", err) - } + // rename to main from master + err = utils.ExecuteCmd("git", []string{"branch", "--move", "main"}, projectPath) + if err != nil { + log.Printf("Error renaming master branch to main: %v", err) + cobra.CheckErr(err) + return err + } // Create gitignore gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) if err != nil { @@ -266,8 +268,8 @@ func (p *Project) CreateMainFile() error { if err != nil { log.Printf("Could not gofmt in new project %v\n", err) cobra.CheckErr(err) + return err } - return nil } From 287a5b65260280da4466146b22549b99572a873d Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Wed, 8 Nov 2023 12:22:33 +0530 Subject: [PATCH 08/12] feat: master to main --- cmd/program/program.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index fe6d7051..65206a3f 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -214,28 +214,26 @@ func (p *Project) CreateMainFile() error { return err } - - // Initialize git repo - err = utils.ExecuteCmd("git", []string{"init"}, projectPath) - if err != nil { - log.Printf("Error initializing git repo: %v", err) - cobra.CheckErr(err) - return err - } - // rename to main from master - err = utils.ExecuteCmd("git", []string{"branch", "--move", "main"}, projectPath) + // Initialize git repo + err = utils.ExecuteCmd("git", []string{"init"}, projectPath) + if err != nil { + log.Printf("Error initializing git repo: %v", err) + cobra.CheckErr(err) + return err + } + // rename master to main + err = utils.ExecuteCmd("git", []string{"branch", "-m", "main"}, projectPath) if err != nil { log.Printf("Error renaming master branch to main: %v", err) cobra.CheckErr(err) return err } - // Create gitignore - gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) - if err != nil { - cobra.CheckErr(err) - return err - } - + // Create gitignore + gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) + if err != nil { + cobra.CheckErr(err) + return err + } defer gitignoreFile.Close() // inject gitignore template From fa551f09ff0007597367ec051d575798b28e8174 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Wed, 8 Nov 2023 12:31:11 +0530 Subject: [PATCH 09/12] fix: format --- cmd/program/program.go | 61 +++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index 65206a3f..4ea8cdad 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -5,15 +5,11 @@ package program import ( "fmt" - "html/template" - "log" - "os" "html/template" "log" "os" "strings" - tea "github.com/charmbracelet/bubbletea" tpl "github.com/melkeydev/go-blueprint/cmd/template" "github.com/melkeydev/go-blueprint/cmd/utils" @@ -221,46 +217,43 @@ func (p *Project) CreateMainFile() error { cobra.CheckErr(err) return err } - // rename master to main - err = utils.ExecuteCmd("git", []string{"branch", "-m", "main"}, projectPath) - if err != nil { - log.Printf("Error renaming master branch to main: %v", err) - cobra.CheckErr(err) - return err - } + // rename master to main + err = utils.ExecuteCmd("git", []string{"branch", "-move", "main"}, projectPath) + if err != nil { + log.Printf("Error renaming master branch to main: %v", err) + cobra.CheckErr(err) + return err + } // Create gitignore gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) if err != nil { cobra.CheckErr(err) return err } - defer gitignoreFile.Close() + defer gitignoreFile.Close() - // inject gitignore template - gitignoreTemplate := template.Must(template.New(".gitignore").Parse(string(tpl.GitIgnoreTemplate()))) - err = gitignoreTemplate.Execute(gitignoreFile, p) - if err != nil { - return err - } - - // Create .air.toml file - airTomlFile, err := os.Create(fmt.Sprintf("%s/.air.toml", projectPath)) - if err != nil { - cobra.CheckErr(err) - return err - } - - - defer airTomlFile.Close() + // inject gitignore template + gitignoreTemplate := template.Must(template.New(".gitignore").Parse(string(tpl.GitIgnoreTemplate()))) + err = gitignoreTemplate.Execute(gitignoreFile, p) + if err != nil { + return err + } - // inject air.toml template - airTomlTemplate := template.Must(template.New("airtoml").Parse(string(tpl.AirTomlTemplate()))) - err = airTomlTemplate.Execute(airTomlFile, p) - if err != nil { - return err - } + // Create .air.toml file + airTomlFile, err := os.Create(fmt.Sprintf("%s/.air.toml", projectPath)) + if err != nil { + cobra.CheckErr(err) + return err + } + defer airTomlFile.Close() + // inject air.toml template + airTomlTemplate := template.Must(template.New("airtoml").Parse(string(tpl.AirTomlTemplate()))) + err = airTomlTemplate.Execute(airTomlFile, p) + if err != nil { + return err + } err = utils.GoFmt(projectPath) if err != nil { From 1a3dd5958bf0a16fe98bc4b48d797d91570dd37e Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Wed, 8 Nov 2023 12:38:54 +0530 Subject: [PATCH 10/12] fix: master to main --- cmd/program/program.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index 4ea8cdad..cfff4b1c 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -218,7 +218,7 @@ func (p *Project) CreateMainFile() error { return err } // rename master to main - err = utils.ExecuteCmd("git", []string{"branch", "-move", "main"}, projectPath) + err = utils.ExecuteCmd("git", []string{"branch", "-move", "main"}, projectPath) if err != nil { log.Printf("Error renaming master branch to main: %v", err) cobra.CheckErr(err) From 3779f0d5e208d9b9506f4d96742cf9d988514fec Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Wed, 8 Nov 2023 13:55:25 +0530 Subject: [PATCH 11/12] feat: checkout main --- cmd/program/program.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index cfff4b1c..ca8e05d3 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -4,12 +4,10 @@ package program import ( "fmt" - "html/template" "log" "os" "strings" - tea "github.com/charmbracelet/bubbletea" tpl "github.com/melkeydev/go-blueprint/cmd/template" "github.com/melkeydev/go-blueprint/cmd/utils" @@ -218,7 +216,7 @@ func (p *Project) CreateMainFile() error { return err } // rename master to main - err = utils.ExecuteCmd("git", []string{"branch", "-move", "main"}, projectPath) + err = utils.ExecuteCmd("git", []string{"branch","-f", "-m","main"}, projectPath) if err != nil { log.Printf("Error renaming master branch to main: %v", err) cobra.CheckErr(err) From 0723024c24e60e155e7f35017b05d1704f4222d9 Mon Sep 17 00:00:00 2001 From: 20pa5a1210 <20pa5a1210@vishnu.edu.in> Date: Fri, 10 Nov 2023 15:40:40 +0530 Subject: [PATCH 12/12] fix: removed switching from main branch --- cmd/program/program.go | 7 ------- cmd/template/main.go | 3 --- 2 files changed, 10 deletions(-) diff --git a/cmd/program/program.go b/cmd/program/program.go index ca8e05d3..c597875d 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -215,13 +215,6 @@ func (p *Project) CreateMainFile() error { cobra.CheckErr(err) return err } - // rename master to main - err = utils.ExecuteCmd("git", []string{"branch","-f", "-m","main"}, projectPath) - if err != nil { - log.Printf("Error renaming master branch to main: %v", err) - cobra.CheckErr(err) - return err - } // Create gitignore gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath)) if err != nil { diff --git a/cmd/template/main.go b/cmd/template/main.go index 50e92bfd..0a05b9d4 100644 --- a/cmd/template/main.go +++ b/cmd/template/main.go @@ -87,9 +87,6 @@ tmp/ # IDE specific files .vscode .idea - -# build output -air `) }