Skip to content

Commit

Permalink
[bug] live reload fixed (#283)
Browse files Browse the repository at this point in the history
* air (live reload) will work on windows
  • Loading branch information
jexroid authored Aug 8, 2024
1 parent b5e0e3b commit 838c20a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
13 changes: 13 additions & 0 deletions cmd/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"
"text/template"

Expand Down Expand Up @@ -37,6 +38,7 @@ type Project struct {
AdvancedOptions map[string]bool
AdvancedTemplates AdvancedTemplates
GitOptions flags.Git
UnixBased bool
}

type AdvancedTemplates struct {
Expand Down Expand Up @@ -116,6 +118,14 @@ const (
gitHubActionPath = ".github/workflows"
)

// CheckOs checks Operation system and generates MakeFile and `go build` command
// Based on Project.Unixbase
func (p *Project) CheckOs() {
if runtime.GOOS != "windows" {
p.UnixBased = true
}
}

// ExitCLI checks if the Project has been exited, and closes
// out of the CLI if it has
func (p *Project) ExitCLI(tprogram *tea.Program) {
Expand Down Expand Up @@ -247,6 +257,9 @@ func (p *Project) CreateMainFile() error {
}
}

// Define Operating system
p.CheckOs()

// Create the map for our program
p.createFrameworkMap()

Expand Down
2 changes: 1 addition & 1 deletion cmd/template/framework/files/air.toml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tmp_dir = "tmp"

[build]
args_bin = []
bin = "./main"
bin = {{if .UnixBased }}"./main"{{ else }}".\\main.exe"{{ end }}
cmd = "make build"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
Expand Down
35 changes: 20 additions & 15 deletions cmd/template/framework/files/makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build:
@echo "Building..."
{{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
{{if .UnixBased }}@go build -o main cmd/api/main.go{{ else }}@go build -o main.exe cmd/api/main.go{{ end }}

# Run the application
run:
Expand Down Expand Up @@ -51,20 +51,25 @@ clean:
@rm -f main

# Live Reload
{{if .UnixBased}}
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
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
{{else}}
watch:
@air
{{end}}

.PHONY: all build run test clean
.PHONY: all build run test clean watch

1 comment on commit 838c20a

@NobakhtNet
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welldone @jexroid !

Please sign in to comment.