1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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")
}
|