From 191c635e09760c2875137250bda13ec38fd6eb0c Mon Sep 17 00:00:00 2001 From: Brijesh Date: Tue, 9 Jul 2024 01:32:54 -0700 Subject: [PATCH 1/2] Removed nondbMakeFile --- cmd/program/program.go | 19 +++------ cmd/template/framework/files/makefile.tmpl | 2 + .../framework/files/nondbMakeFile.tmpl | 42 ------------------- cmd/template/framework/main.go | 7 ---- 4 files changed, 7 insertions(+), 63 deletions(-) delete mode 100644 cmd/template/framework/files/nondbMakeFile.tmpl diff --git a/cmd/program/program.go b/cmd/program/program.go index 8d5ec77a..e8d02738 100644 --- a/cmd/program/program.go +++ b/cmd/program/program.go @@ -356,20 +356,11 @@ func (p *Project) CreateMainFile() error { defer makeFile.Close() - if p.DBDriver == "sqlite" || p.DBDriver == "none" { - // inject makefile template - makeFileTemplate := template.Must(template.New("makefile").Parse(string(framework.NonDbMakeFileTemplate()))) - err = makeFileTemplate.Execute(makeFile, p) - if err != nil { - return err - } - } else { - // inject makefile template for database excluding sqlite - makeFileTemplate := template.Must(template.New("makefile").Parse(string(framework.MakeTemplate()))) - err = makeFileTemplate.Execute(makeFile, p) - if err != nil { - return err - } + // inject makefile template + makeFileTemplate := template.Must(template.New("makefile").Parse(string(framework.MakeTemplate()))) + err = makeFileTemplate.Execute(makeFile, p) + if err != nil { + return err } readmeFile, err := os.Create(filepath.Join(projectPath, "README.md")) diff --git a/cmd/template/framework/files/makefile.tmpl b/cmd/template/framework/files/makefile.tmpl index f6ec1255..c0b8a466 100644 --- a/cmd/template/framework/files/makefile.tmpl +++ b/cmd/template/framework/files/makefile.tmpl @@ -13,6 +13,7 @@ build: run: @go run cmd/api/main.go +{{if and (ne .DBDriver "none") (ne .DBDriver "sqlite")}} # Create DB container docker-run: @if docker compose up 2>/dev/null; then \ @@ -30,6 +31,7 @@ docker-down: echo "Falling back to Docker Compose V1"; \ docker-compose down; \ fi +{{end}} # Test the application test: diff --git a/cmd/template/framework/files/nondbMakeFile.tmpl b/cmd/template/framework/files/nondbMakeFile.tmpl deleted file mode 100644 index 19da233b..00000000 --- a/cmd/template/framework/files/nondbMakeFile.tmpl +++ /dev/null @@ -1,42 +0,0 @@ -# Simple Makefile for a Go project - -# Build the application -all: build - -build: - @echo "Building..." - {{if .AdvancedOptions.htmx}}@templ generate{{end}} - @go build -o main cmd/api/main.go - -# Run the application -run: - @go run cmd/api/main.go - -# Test the application -test: - @echo "Testing..." - @go test ./tests -v - -# Clean the binary -clean: - @echo "Cleaning..." - @rm -f main - -# Live Reload -watch: - @if command -v air > /dev/null; then \ - air; \ - echo "Watching...";\ - else \ - read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \ - if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \ - go install github.com/air-verse/air@latest; \ - air; \ - echo "Watching...";\ - else \ - echo "You chose not to install air. Exiting..."; \ - exit 1; \ - fi; \ - fi - -.PHONY: all build run test clean diff --git a/cmd/template/framework/main.go b/cmd/template/framework/main.go index 288023ff..0611822b 100644 --- a/cmd/template/framework/main.go +++ b/cmd/template/framework/main.go @@ -9,9 +9,6 @@ import ( //go:embed files/main/main.go.tmpl var mainTemplate []byte -//go:embed files/nondbMakeFile.tmpl -var nondbMakeFileTemplate []byte - //go:embed files/air.toml.tmpl var airTomlTemplate []byte @@ -43,7 +40,3 @@ func AirTomlTemplate() []byte { func ReadmeTemplate() []byte { return readmeTemplate } - -func NonDbMakeFileTemplate() []byte { - return nondbMakeFileTemplate -} From 2bbcbba1d531df1a6b49b833baffed1e1216d902 Mon Sep 17 00:00:00 2001 From: Brijesh Date: Wed, 10 Jul 2024 07:59:24 -0700 Subject: [PATCH 2/2] Add templ generate if tailwind css is selected --- cmd/template/framework/files/makefile.tmpl | 2 +- xs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 xs diff --git a/cmd/template/framework/files/makefile.tmpl b/cmd/template/framework/files/makefile.tmpl index c0b8a466..ded58c97 100644 --- a/cmd/template/framework/files/makefile.tmpl +++ b/cmd/template/framework/files/makefile.tmpl @@ -5,7 +5,7 @@ all: build build: @echo "Building..." - {{if .AdvancedOptions.htmx}}@templ generate{{end}} + {{if or ( .AdvancedOptions.htmx ) ( .AdvancedOptions.tailwind )}}@templ generate{{end}} {{if .AdvancedOptions.tailwind}}@tailwindcss -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css{{end}} @go build -o main cmd/api/main.go diff --git a/xs b/xs new file mode 160000 index 00000000..d08e5614 --- /dev/null +++ b/xs @@ -0,0 +1 @@ +Subproject commit d08e5614d45cd18c0efd6ee112c02cae19a7f0bf