add build command, upgrade dep

This commit is contained in:
maddalax 2024-09-16 18:02:35 -05:00
parent 9e5d8edada
commit 7f056b1d5e
6 changed files with 53 additions and 13 deletions

View file

@ -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.")
}

View file

@ -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)

17
cli/tasks/run/build.go Normal file
View file

@ -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\"")
}

View file

@ -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

View file

@ -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 (

View file

@ -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"),