diff --git a/cli/runner.go b/cli/runner.go index 7d10f42..285f395 100644 --- a/cli/runner.go +++ b/cli/runner.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "flag" "fmt" "github.com/maddalax/htmgo/cli/tasks/astgen" @@ -61,23 +62,29 @@ func main() { copyassets.CopyAssets() _ = astgen.GenAst(true) _ = css.GenerateCss(true) - } - if taskName == "css" { + } else if taskName == "css" { _ = css.GenerateCss(true) - } - if taskName == "ast" { + } else if taskName == "ast" { _ = astgen.GenAst(true) - } - if taskName == "run" { + } else if taskName == "run" { _ = astgen.GenAst(true) _ = css.GenerateCss(true) _ = run.Server(true) + } else if taskName == "template" { + reader := bufio.NewReader(os.Stdin) + fmt.Print("What would you like to call your new app?: ") + text, _ := reader.ReadString('\n') + text = strings.TrimSuffix(text, "\n") + text = strings.ReplaceAll(text, " ", "-") + text = strings.ToLower(text) + downloadtemplate.DownloadTemplate(fmt.Sprintf("./%s", text)) + } else if taskName == "build" { + run.Build() + } else { + fmt.Println(fmt.Sprintf("Usage: htmgo [%s]", strings.Join(commands, " | "))) } - if taskName == "template" { - downloadtemplate.DownloadTemplate("./my-app") - } + os.Exit(1) } <-done - fmt.Println("Cleanup complete. Exiting.") } diff --git a/cli/tasks/downloadtemplate/main.go b/cli/tasks/downloadtemplate/main.go index 10a995b..ae3bb5b 100644 --- a/cli/tasks/downloadtemplate/main.go +++ b/cli/tasks/downloadtemplate/main.go @@ -86,7 +86,7 @@ func DownloadTemplate(outPath string) { fmt.Println("Template downloaded successfully.") fmt.Println("To start the development server, run the following commands:") - fmt.Printf("cd %s && htmgo run\n", outPath) + fmt.Printf("cd %s && htmgo watch\n", outPath) fmt.Printf("To build the project, run the following command:\n") fmt.Printf("cd %s && htmgo build\n", outPath) diff --git a/cli/tasks/run/build.go b/cli/tasks/run/build.go new file mode 100644 index 0000000..c9aed9f --- /dev/null +++ b/cli/tasks/run/build.go @@ -0,0 +1,17 @@ +package run + +import ( + "github.com/maddalax/htmgo/cli/tasks/astgen" + "github.com/maddalax/htmgo/cli/tasks/css" + "github.com/maddalax/htmgo/cli/tasks/process" +) + +func Build() { + astgen.GenAst(true) + css.GenerateCss(true) + process.RunOrExit("rm -rf ./dist") + process.RunOrExit("mkdir -p ./dist/assets/dist") + process.RunOrExit("cp -r ./assets/dist/* ./dist/assets/dist/") + process.RunOrExit("go build -o \"./dist\" .") + process.RunOrExit("echo \"Build successful\"") +} diff --git a/starter-template/Taskfile.yml b/starter-template/Taskfile.yml new file mode 100644 index 0000000..8e9b9c3 --- /dev/null +++ b/starter-template/Taskfile.yml @@ -0,0 +1,16 @@ +version: '3' + +tasks: + run: + cmds: + - go run github.com/maddalax/htmgo/cli@latest run + silent: true + + build: + cmds: + - go run github.com/maddalax/htmgo/cli@latest build + + watch: + cmds: + - go run github.com/maddalax/htmgo/cli@latest watch + silent: true \ No newline at end of file diff --git a/starter-template/go.mod b/starter-template/go.mod index 2e5a6fa..4bc3ff8 100644 --- a/starter-template/go.mod +++ b/starter-template/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/gofiber/fiber/v2 v2.52.5 - github.com/maddalax/htmgo/framework v0.0.0-20240914010415-2397bf9fb057 + github.com/maddalax/htmgo/framework v0.0.0-20240916224719-9e5d8edada65 ) require ( diff --git a/starter-template/pages/index.go b/starter-template/pages/index.go index a53ac6b..a673aa7 100644 --- a/starter-template/pages/index.go +++ b/starter-template/pages/index.go @@ -34,7 +34,7 @@ func IndexPage(c *fiber.Ctx) *h.Page { func Button() h.Renderable { return h.Button(h.Class("btn bg-slate-500 p-4 rounded text-white"), - h.Text("Click here use my ytes"), + h.Text("Ctest"), h.AfterRequest( h.SetDisabled(true), h.RemoveClass("bg-red-600"),