This commit is contained in:
maddalax 2024-09-13 19:25:50 -05:00
parent 78cc819029
commit 5a30ca62fd
3 changed files with 126 additions and 0 deletions

View file

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

View file

@ -0,0 +1,3 @@
module github.com/maddalax/htmgo/framework/tooling/htmgo
go 1.23.0

View file

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