diff --git a/cli/htmgo/runner.go b/cli/htmgo/runner.go index d835fcf..dd6408d 100644 --- a/cli/htmgo/runner.go +++ b/cli/htmgo/runner.go @@ -20,7 +20,7 @@ func main() { done := RegisterSignals() commandMap := make(map[string]*flag.FlagSet) - commands := []string{"template", "run", "watch", "build", "setup", "css", "schema", "generate"} + commands := []string{"template", "run", "watch", "build", "setup", "css", "schema", "generate", "tailwind-cli"} for _, command := range commands { commandMap[command] = flag.NewFlagSet(command, flag.ExitOnError) @@ -54,7 +54,9 @@ func main() { slog.Debug("Running task:", slog.String("task", taskName)) slog.Debug("working dir:", slog.String("dir", process.GetWorkingDir())) - if taskName == "watch" { + if taskName == "tailwind-cli" { + _ = css.DownloadTailwindCli() + } else if taskName == "watch" { os.Setenv("ENV", "development") os.Setenv("WATCH_MODE", "true") copyassets.CopyAssets() diff --git a/cli/htmgo/tasks/css/css.go b/cli/htmgo/tasks/css/css.go index 3e2f8f1..2a574e8 100644 --- a/cli/htmgo/tasks/css/css.go +++ b/cli/htmgo/tasks/css/css.go @@ -1,10 +1,14 @@ package css -import "github.com/maddalax/htmgo/cli/htmgo/tasks/process" +import ( + "fmt" + "github.com/maddalax/htmgo/cli/htmgo/tasks/process" + "log" + "runtime" +) func GenerateCss(flags ...process.RunFlag) error { return process.RunMany([]string{ - "chmod +x ./assets/css/tailwindcss", "./assets/css/tailwindcss -i ./assets/css/input.css -o ./assets/dist/main.css -c ./assets/css/tailwind.config.js", }, append(flags, process.Silent)...) } @@ -14,3 +18,28 @@ func GenerateCssWatch(flags ...process.RunFlag) error { "./assets/css/tailwindcss -i ./assets/css/input.css -o ./assets/dist/main.css -c ./assets/css/tailwind.config.js --watch=always", }, append(flags, process.KillOnlyOnExit, process.Silent)...) } + +func DownloadTailwindCli() error { + distro := "" + os := runtime.GOOS + arch := runtime.GOARCH + switch { + case os == "darwin" && arch == "arm64": + distro = "macos-arm64" + case os == "darwin" && arch == "amd64": + distro = "macos-x64" + case os == "linux" && arch == "arm64": + distro = "linux-arm64" + case os == "linux" && arch == "amd64": + distro = "linux-x64" + default: + log.Fatal(fmt.Sprintf("Unsupported OS/ARCH: %s/%s", os, arch)) + } + fileName := fmt.Sprintf(`tailwindcss-%s`, distro) + url := fmt.Sprintf(`https://github.com/tailwindlabs/tailwindcss/releases/latest/download/%s`, fileName) + return process.RunMany([]string{ + fmt.Sprintf(`curl -sLO %s`, url), + fmt.Sprintf(`chmod +x %s`, fileName), + fmt.Sprintf(`mv %s ./assets/css/tailwindcss`, fileName), + }) +} diff --git a/cli/htmgo/tasks/run/build.go b/cli/htmgo/tasks/run/build.go index 53c6d2f..6c55e30 100644 --- a/cli/htmgo/tasks/run/build.go +++ b/cli/htmgo/tasks/run/build.go @@ -8,6 +8,8 @@ import ( ) func Build() { + css.DownloadTailwindCli() + astgen.GenAst(process.ExitOnError) css.GenerateCss(process.ExitOnError) diff --git a/framework/assets/css/tailwindcss b/framework/assets/css/tailwindcss deleted file mode 100755 index f012497..0000000 Binary files a/framework/assets/css/tailwindcss and /dev/null differ diff --git a/htmgo-site/assets/css/tailwindcss b/htmgo-site/assets/css/tailwindcss deleted file mode 100755 index f012497..0000000 Binary files a/htmgo-site/assets/css/tailwindcss and /dev/null differ