From 4f79af848664fd91ac6101ac91fd59170f46d087 Mon Sep 17 00:00:00 2001 From: Luigi Morel Date: Sun, 21 Sep 2025 20:12:54 +0300 Subject: [PATCH 1/3] feat: add CreateAirFile function and update gitignore handling for CLI projects --- internal/air.go | 70 ++++++++++++++++++++++++++++++++++++++++++++ internal/env-file.go | 6 ++++ internal/project.go | 13 ++++++++ 3 files changed, 89 insertions(+) create mode 100644 internal/air.go diff --git a/internal/air.go b/internal/air.go new file mode 100644 index 0000000..6da6356 --- /dev/null +++ b/internal/air.go @@ -0,0 +1,70 @@ +package internal + +import ( + "os" + "path/filepath" +) + +func (pg *ProjectGenerator) CreateAirFile(dirName, dirType string) error { + airContent := `root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "./tmp/gogen" + cmd = "go build -o \"./tmp/gogen\" ." + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[proxy] + app_port = 0 + enabled = false + proxy_port = 0 + +[screen] + clear_on_rebuild = false + keep_scroll = true +` + + var filePath string + if dirType == "web" { + filePath = filepath.Join(dirName, "api", ".air.toml") + } else { + filePath = filepath.Join(dirName, ".air.toml") + } + + return os.WriteFile(filePath, []byte(airContent), 0600) +} diff --git a/internal/env-file.go b/internal/env-file.go index 7e5a656..77ef675 100644 --- a/internal/env-file.go +++ b/internal/env-file.go @@ -86,7 +86,13 @@ func (pg *ProjectGenerator) CreateGitignoreFile(dirType, dirName string) error { .env.local .env.production.local .env.*.local +tmp ` + } else if dirType == "cli" { + gitignoreContent = `# Binaries for programs and plugins +*.exe +tmp +main` } else if dirType == "frontend" { gitignoreContent = `logs *.log diff --git a/internal/project.go b/internal/project.go index efb8c5a..c838c4b 100644 --- a/internal/project.go +++ b/internal/project.go @@ -121,6 +121,14 @@ func main() { fmt.Printf("Warning: failed to initialize git repository: %v\n", err) } + if err := pg.CreateAirFile(".", "cli"); err != nil { + fmt.Printf("Warning: failed to create .air.toml file: %v\n", err) + } + + if err := pg.CreateGitignoreFile("cli", "."); err != nil { + fmt.Printf("Warning: failed to create .gitignore file: %v\n", err) + } + cmd := exec.Command("go", "mod", "tidy") return cmd.Run() } @@ -177,6 +185,7 @@ func (pg *ProjectGenerator) createConfigFiles() error { if err := pg.CreateGitignoreFile("api", "."); err != nil { return fmt.Errorf("warning: failed to create .gitignore file in api: %v", err) } + return nil } @@ -270,5 +279,9 @@ func (pg *ProjectGenerator) createAPIProjectInDir(baseDir, projectName, moduleNa } } + if err := pg.CreateAirFile(".", "web"); err != nil { + fmt.Printf("Warning: failed to create .air.toml file: %v\n", err) + } + return nil } From 377ea341b01e42593efe907c4541623fbef73a0b Mon Sep 17 00:00:00 2001 From: Luigi Morel Date: Sun, 21 Sep 2025 20:21:44 +0300 Subject: [PATCH 2/3] fix: lint error about using if statements --- internal/env-file.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/env-file.go b/internal/env-file.go index 77ef675..ef18644 100644 --- a/internal/env-file.go +++ b/internal/env-file.go @@ -81,19 +81,20 @@ export default config; func (pg *ProjectGenerator) CreateGitignoreFile(dirType, dirName string) error { var gitignoreContent string - if dirType == "api" { + switch dirType { + case "api": gitignoreContent = `.env .env.local .env.production.local .env.*.local tmp ` - } else if dirType == "cli" { + case "cli": gitignoreContent = `# Binaries for programs and plugins *.exe tmp main` - } else if dirType == "frontend" { + default: gitignoreContent = `logs *.log npm-debug.log* From 92e1c13c934c1f3beccfd71cafbdf38a03d4772b Mon Sep 17 00:00:00 2001 From: Luigi Morel Date: Wed, 1 Oct 2025 10:42:33 +0300 Subject: [PATCH 3/3] fix: binary name on live reload --- internal/air.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/air.go b/internal/air.go index 6da6356..739720e 100644 --- a/internal/air.go +++ b/internal/air.go @@ -12,8 +12,8 @@ tmp_dir = "tmp" [build] args_bin = [] - bin = "./tmp/gogen" - cmd = "go build -o \"./tmp/gogen\" ." + bin = "./tmp/main" + cmd = "go build -o \"./tmp/main\" ." delay = 1000 exclude_dir = ["assets", "tmp", "vendor", "testdata"] exclude_file = []