summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-28 11:18:21 +0300
committerPaul Buetow <paul@buetow.org>2025-08-28 11:18:21 +0300
commit101500cc9a9b4e636451aba67ae5f8e924432afa (patch)
tree4de216b50c4b75598ff87b14f1c1bc197edcc803
parentfaf87a23a782bc7d717e363a3a399a64d6a34146 (diff)
build: replace Taskfile with Magefile; add Mage targets and README build notes
-rw-r--r--Magefile.go102
-rw-r--r--README.md12
-rw-r--r--Taskfile.yaml45
3 files changed, 114 insertions, 45 deletions
diff --git a/Magefile.go b/Magefile.go
new file mode 100644
index 0000000..d1ad2ed
--- /dev/null
+++ b/Magefile.go
@@ -0,0 +1,102 @@
+//go:build mage
+
+// Hexai mage targets: build, dev, test, lint, install, etc.
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/magefile/mage/mg"
+ "github.com/magefile/mage/sh"
+)
+
+// Default target: build both binaries.
+var Default = Build
+
+// Build builds the Hexai LSP and CLI binaries.
+func Build() error {
+ mg.Deps(BuildHexaiLSP, BuildHexaiCLI)
+ return nil
+}
+
+// BuildHexaiLSP builds the LSP server binary.
+func BuildHexaiLSP() error {
+ return sh.RunV("go", "build", "-o", "hexai-lsp", "cmd/hexai-lsp/main.go")
+}
+
+// BuildHexaiCLI builds the CLI binary.
+func BuildHexaiCLI() error {
+ return sh.RunV("go", "build", "-o", "hexai", "cmd/hexai/main.go")
+}
+
+// Dev runs tests, vet, lint, then builds with race for both binaries.
+func Dev() error {
+ mg.Deps(Test, Vet, Lint)
+ if err := sh.RunV("go", "build", "-race", "-o", "hexai-lsp", "cmd/hexai-lsp/main.go"); err != nil {
+ return err
+ }
+ return sh.RunV("go", "build", "-race", "-o", "hexai", "cmd/hexai/main.go")
+}
+
+// Run launches the LSP server via go run (useful during development).
+func Run() error {
+ mg.Deps(Dev)
+ return sh.RunV("go", "run", "cmd/hexai-lsp/main.go")
+}
+
+// RunCLI runs the CLI with a small test input.
+func RunCLI() error {
+ mg.Deps(Dev)
+ cmd := "echo 'test' | go run cmd/hexai/main.go"
+ return sh.RunV("bash", "-lc", cmd)
+}
+
+// Install copies built binaries to GOPATH/bin (defaults to ~/go/bin when GOPATH is unset).
+func Install() error {
+ mg.Deps(Build)
+ gopath := os.Getenv("GOPATH")
+ if gopath == "" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return fmt.Errorf("resolve home: %w", err)
+ }
+ gopath = filepath.Join(home, "go")
+ }
+ bin := filepath.Join(gopath, "bin")
+ if err := os.MkdirAll(bin, 0o755); err != nil {
+ return err
+ }
+ if err := sh.RunV("cp", "-v", "./hexai-lsp", bin+"/"); err != nil {
+ return err
+ }
+ return sh.RunV("cp", "-v", "./hexai", bin+"/")
+}
+
+// Test runs the test suite.
+func Test() error {
+ if err := sh.RunV("go", "clean", "-testcache"); err != nil {
+ return err
+ }
+ return sh.RunV("go", "test", "-v", "./...")
+}
+
+// Vet runs go vet.
+func Vet() error {
+ return sh.RunV("go", "vet", "./...")
+}
+
+// Lint runs golangci-lint.
+func Lint() error {
+ return sh.RunV("golangci-lint", "run")
+}
+
+// DevInstall installs helpful developer tools.
+func DevInstall() error {
+ if err := sh.RunV("go", "install", "golang.org/x/tools/gopls@latest"); err != nil {
+ return err
+ }
+ return sh.RunV("go", "install", "github.com/golangci/golangci-lint/cmd/golangci-lint@latest")
+}
+
diff --git a/README.md b/README.md
index 888a403..dd9baac 100644
--- a/README.md
+++ b/README.md
@@ -18,3 +18,15 @@ AI coded it under human supervision, and a human developer reviewed the code.
* [Configuration guide](docs/configuration.md)
* [Usage examples](docs/usage-examples.md)
+
+## Build and tasks
+
+Hexai uses Mage for developer tasks. Install Mage, then run targets like build, dev, test, and install.
+
+- Install Mage: `go install github.com/magefile/mage@latest`
+- Build binaries: `mage build` (produces `hexai` and `hexai-lsp`)
+- Dev build (+ tests, vet, lint): `mage dev`
+- Run tests: `mage test`
+- Install binaries to `GOPATH/bin`: `mage install`
+
+Note: `mage lint` uses `golangci-lint`. Install via `mage devinstall` if needed.
diff --git a/Taskfile.yaml b/Taskfile.yaml
deleted file mode 100644
index 753a5f7..0000000
--- a/Taskfile.yaml
+++ /dev/null
@@ -1,45 +0,0 @@
-version: '3'
-
-tasks:
- default:
- deps: ["build"]
- install:
- deps: ["build"]
- cmds:
- - cp -v ./hexai-lsp ~/go/bin/
- - cp -v ./hexai ~/go/bin/
- run:
- deps: ["dev"]
- cmds:
- - go run cmd/hexai-lsp/main.go
- build:
- deps: ["build-hexai-lsp", "build-hexai-cli"]
- build-hexai-lsp:
- cmds:
- - go build -o hexai-lsp cmd/hexai-lsp/main.go
- build-hexai-cli:
- cmds:
- - go build -o hexai cmd/hexai/main.go
- dev:
- deps: ["test", "vet", "lint"]
- cmds:
- - go build -race -o hexai-lsp cmd/hexai-lsp/main.go
- - go build -race -o hexai cmd/hexai/main.go
- run-cli:
- deps: ["dev"]
- cmds:
- - echo 'test' | go run cmd/hexai/main.go
- test:
- cmds:
- - go clean -testcache
- - go test -v ./...
- vet:
- cmds:
- - go vet ./...
- lint:
- cmds:
- - golangci-lint run
- dev-install:
- cmds:
- - go install golang.org/x/tools/gopls@latest
- - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest