From 9423171ef83cf4743b98a4326abd6dc4ce9f1333 Mon Sep 17 00:00:00 2001 From: maddalax Date: Fri, 13 Sep 2024 20:50:24 -0500 Subject: [PATCH] css working --- framework/tooling/copyassets/bundle.go | 15 +++++++++++---- framework/tooling/copyassets/go.mod | 4 +++- framework/tooling/htmgo/Taskfile.yml | 11 +++++++++++ framework/tooling/htmgo/runner.go | 12 ++++++++++-- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/framework/tooling/copyassets/bundle.go b/framework/tooling/copyassets/bundle.go index 52e47ea..6c4c39b 100644 --- a/framework/tooling/copyassets/bundle.go +++ b/framework/tooling/copyassets/bundle.go @@ -93,19 +93,26 @@ func main() { if err != nil { log.Fatal(err) } - assetDir := fmt.Sprintf("%s/go/pkg/mod/%s@%s/assets/dist", dirname, modulePath, version) + + assetDir := fmt.Sprintf("%s/go/pkg/mod/%s@%s/assets", dirname, modulePath, version) + assetDistDir := fmt.Sprintf("%s/dist", assetDir) + assetCssDir := fmt.Sprintf("%s/css", assetDir) + cwd, err := os.Getwd() if err != nil { log.Fatal("failed to get cwd") } - destDir := fmt.Sprintf("%s/assets/dist", cwd) + destDir := fmt.Sprintf("%s/assets", cwd) + destDirDist := fmt.Sprintf("%s/dist", destDir) + destDirCss := fmt.Sprintf("%s/css", destDir) - err = copyDir(assetDir, destDir) + err = copyDir(assetDistDir, destDirDist) + err = copyDir(assetCssDir, destDirCss) if err != nil { - log.Fatal(err.Error()) + log.Fatalf("Error: %v", err) } fmt.Printf("successfully copied assets to %s\n", destDir) diff --git a/framework/tooling/copyassets/go.mod b/framework/tooling/copyassets/go.mod index 7d87fd8..a09dfd7 100644 --- a/framework/tooling/copyassets/go.mod +++ b/framework/tooling/copyassets/go.mod @@ -1,3 +1,5 @@ module github.com/maddalax/htmgo/framework/tooling/copyassets -go 1.23.0 \ No newline at end of file +go 1.23.0 + +require golang.org/x/mod v0.21.0 diff --git a/framework/tooling/htmgo/Taskfile.yml b/framework/tooling/htmgo/Taskfile.yml index 2f3141d..4f21af0 100644 --- a/framework/tooling/htmgo/Taskfile.yml +++ b/framework/tooling/htmgo/Taskfile.yml @@ -20,6 +20,8 @@ tasks: dir: '{{.USER_WORKING_DIR}}' - task: ast dir: '{{.USER_WORKING_DIR}}' + - task: css + dir: '{{.USER_WORKING_DIR}}' run: dir: '{{.USER_WORKING_DIR}}' @@ -46,6 +48,15 @@ tasks: cmds: - go run github.com/maddalax/htmgo/framework/tooling/copyassets@latest + css: + dir: '{{.USER_WORKING_DIR}}' + desc: Generate CSS from source code + generates: + - '**/main.css' + cmds: + - chmod +x ./assets/css/tailwindcss + - ./assets/css/tailwindcss -i ./assets/css/input.css -o ./assets/dist/main.css -c ./assets/css/tailwind.config.js + ast: dir: '{{.USER_WORKING_DIR}}' desc: Generate AST from source code diff --git a/framework/tooling/htmgo/runner.go b/framework/tooling/htmgo/runner.go index 9f49b85..bf77949 100644 --- a/framework/tooling/htmgo/runner.go +++ b/framework/tooling/htmgo/runner.go @@ -14,7 +14,7 @@ var taskFile string func main() { commandMap := make(map[string]*flag.FlagSet) - commands := []string{"template", "run", "build", "setup"} + commands := []string{"template", "run", "build", "setup", "css"} for _, command := range commands { commandMap[command] = flag.NewFlagSet(command, flag.ExitOnError) @@ -25,7 +25,15 @@ func main() { os.Exit(1) } - err := commandMap[os.Args[1]].Parse(os.Args[2:]) + c := commandMap[os.Args[1]] + + if c == nil { + fmt.Println(fmt.Sprintf("Usage: htmgo [%s]", strings.Join(commands, " | "))) + os.Exit(1) + return + } + + err := c.Parse(os.Args[2:]) if err != nil { fmt.Println(err.Error()) os.Exit(1)