From 5a30ca62fdd21305c675bd07f5f553dbb12ed2ad Mon Sep 17 00:00:00 2001 From: maddalax Date: Fri, 13 Sep 2024 19:25:50 -0500 Subject: [PATCH] woops --- framework/tooling/htmgo/Taskfile.yml | 65 ++++++++++++++++++++++++++++ framework/tooling/htmgo/go.mod | 3 ++ framework/tooling/htmgo/runner.go | 58 +++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 framework/tooling/htmgo/Taskfile.yml create mode 100644 framework/tooling/htmgo/go.mod create mode 100644 framework/tooling/htmgo/runner.go diff --git a/framework/tooling/htmgo/Taskfile.yml b/framework/tooling/htmgo/Taskfile.yml new file mode 100644 index 0000000..abf5fef --- /dev/null +++ b/framework/tooling/htmgo/Taskfile.yml @@ -0,0 +1,65 @@ +version: '3' + +interval: 500ms + +tasks: + + template: + dir: '{{.USER_WORKING_DIR}}' + desc: Generate template from source code + cmds: + - go run github.com/maddalax/htmgo/framework/tooling/downloadtemplate@latest -out my-app + - echo "Template generated successfully to ./my-app" + + setup: + deps: [copy-framework-assets, ast] + dir: '{{.USER_WORKING_DIR}}' + desc: Setup the project + cmds: + - go mod download + - go mod tidy + + run: + dir: '{{.USER_WORKING_DIR}}' + desc: Run the project + cmds: + - task: setup + dir: '{{.USER_WORKING_DIR}}' + - go run . + + build: + deps: [setup] + dir: '{{.USER_WORKING_DIR}}' + desc: Build the project + cmds: + - rm -rf ./dist + - mkdir -p ./dist/assets/dist + - cp -r ./assets/dist/* ./dist/assets/dist/ + - go build -o "./dist" . + - echo "Build successful" + + copy-framework-assets: + dir: '{{.USER_WORKING_DIR}}' + desc: Copy framework assets + cmds: + - go run github.com/maddalax/htmgo/framework/tooling/copyassets@latest + + ast: + dir: '{{.USER_WORKING_DIR}}' + desc: Generate AST from source code + generates: + - '**/generated.go' + cmds: + - go run github.com/maddalax/htmgo/framework/tooling/astgen@latest + + ast-watch: + dir: '{{.USER_WORKING_DIR}}' + desc: Generate AST from source code and watch for changes + watch: true + generates: + - '**/generated.go' + sources: + - '**/*.go' + cmds: + - task: ast + dir: '{{.USER_WORKING_DIR}}' \ No newline at end of file diff --git a/framework/tooling/htmgo/go.mod b/framework/tooling/htmgo/go.mod new file mode 100644 index 0000000..f376e8a --- /dev/null +++ b/framework/tooling/htmgo/go.mod @@ -0,0 +1,3 @@ +module github.com/maddalax/htmgo/framework/tooling/htmgo + +go 1.23.0 \ No newline at end of file diff --git a/framework/tooling/htmgo/runner.go b/framework/tooling/htmgo/runner.go new file mode 100644 index 0000000..5372cce --- /dev/null +++ b/framework/tooling/htmgo/runner.go @@ -0,0 +1,58 @@ +package main + +import ( + _ "embed" + "flag" + "fmt" + "os" + "os/exec" +) + +//go:embed Taskfile.yml +var taskFile string + +func main() { + taskFlag := flag.String("task", "", "Specify the task to run (e.g., build, setup). Type -task list to see the list of tasks to run.") + + // Parse the command-line flags + flag.Parse() + + install := exec.Command("go", "install", "github.com/go-task/task/v3/cmd/task@latest") + install.Stdout = os.Stdout + install.Stderr = os.Stderr + err := install.Run() + if err != nil { + fmt.Printf("Error installing task: %v\n", err) + return + } + + temp, err := os.CreateTemp("", "Taskfile.yml") + + if err != nil { + fmt.Printf("Error creating temporary file: %v\n", err) + return + } + + os.WriteFile(temp.Name(), []byte(taskFile), 0644) + + if *taskFlag == "" { + fmt.Println("Please specify a task to run using the -task flag") + return + } + + if *taskFlag == "list" { + *taskFlag = "--list" + } + + // Define the command and arguments + cmd := exec.Command("task", "-t", temp.Name(), *taskFlag) + // Set the standard output and error to be the same as the Go program + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + // Run the command + err = cmd.Run() + if err != nil { + fmt.Printf("Error running task command: %v\n", err) + return + } +}