diff --git a/cli/htmgo/go.mod b/cli/htmgo/go.mod index f7e9fc8..0d0995e 100644 --- a/cli/htmgo/go.mod +++ b/cli/htmgo/go.mod @@ -7,7 +7,6 @@ require ( github.com/fsnotify/fsnotify v1.7.0 golang.org/x/mod v0.21.0 golang.org/x/net v0.29.0 + golang.org/x/sys v0.25.0 golang.org/x/tools v0.25.0 ) - -require golang.org/x/sys v0.25.0 // indirect diff --git a/cli/htmgo/runner.go b/cli/htmgo/runner.go index b71ea41..d48dd5b 100644 --- a/cli/htmgo/runner.go +++ b/cli/htmgo/runner.go @@ -55,15 +55,18 @@ func main() { slog.Debug("working dir:", slog.String("dir", process.GetWorkingDir())) if taskName == "watch" { + fmt.Printf("Running in watch mode\n") os.Setenv("ENV", "development") os.Setenv("WATCH_MODE", "true") + fmt.Printf("Starting processes...") copyassets.CopyAssets() astgen.GenAst(process.ExitOnError) - css.GenerateCss(process.ExitOnError, process.Silent) + css.GenerateCss(process.ExitOnError) run.EntGenerate() go func() { css.GenerateCssWatch(process.ExitOnError) }() + fmt.Printf("Starting server...\n") go func() { _ = run.Server() }() diff --git a/cli/htmgo/tasks/css/css.go b/cli/htmgo/tasks/css/css.go index bcc06d9..1321d21 100644 --- a/cli/htmgo/tasks/css/css.go +++ b/cli/htmgo/tasks/css/css.go @@ -90,22 +90,18 @@ func downloadTailwindCli() { } fileName := fmt.Sprintf(`tailwindcss-%s`, distro) url := fmt.Sprintf(`https://github.com/tailwindlabs/tailwindcss/releases/latest/download/%s`, fileName) - if os == "windows" { - process.RunMany([]string{ - fmt.Sprintf(`curl -LO %s`, url), - }, process.ExitOnError) - } else { - process.RunMany([]string{ - fmt.Sprintf(`curl -LO %s`, url), - fmt.Sprintf(`chmod +x %s`, fileName), - }, process.ExitOnError) - } + process.Run(fmt.Sprintf(`curl -LO %s`, url), process.ExitOnError) outputFileName := GetTailwindExecutableName() + newPath := filepath.Join(process.GetWorkingDir(), outputFileName) err := dirutil.MoveFile( filepath.Join(process.GetWorkingDir(), fileName), - filepath.Join(process.GetWorkingDir(), outputFileName)) + newPath) + + if os != "windows" { + err = process.Run(fmt.Sprintf(`chmod +x %s`, newPath), process.ExitOnError) + } if err != nil { log.Fatalf("Error moving file: %s\n", err.Error()) diff --git a/framework/h/app.go b/framework/h/app.go index ab43b73..4553acf 100644 --- a/framework/h/app.go +++ b/framework/h/app.go @@ -1,15 +1,9 @@ package h import ( - "fmt" "github.com/labstack/echo/v4" "github.com/maddalax/htmgo/framework/hx" - "github.com/maddalax/htmgo/framework/internal/process" "github.com/maddalax/htmgo/framework/service" - "log/slog" - "os/exec" - "runtime" - "time" ) type RequestContext struct { @@ -92,25 +86,7 @@ func (a App) start() { err := a.Echo.Start(port) if err != nil { - // If we are in watch mode, just try to kill any processes holding that port - // and try again - if IsDevelopment() && IsWatchMode() { - slog.Info("Port already in use, trying to kill the process and start again") - if runtime.GOOS == "windows" { - cmd := exec.Command("cmd", "/C", fmt.Sprintf(`for /F "tokens=5" %%i in ('netstat -aon ^| findstr :%s') do taskkill /F /PID %%i`, port)) - cmd.Run() - } else { - process.RunOrExit(fmt.Sprintf("kill -9 $(lsof -t -i%s)", port)) - } - - time.Sleep(time.Millisecond * 50) - err = a.Echo.Start(port) - if err != nil { - panic(err) - } - } else { - panic(err) - } + panic(err) } }