summaryrefslogtreecommitdiff
path: root/Magefile.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-19 21:51:47 +0300
committerPaul Buetow <paul@buetow.org>2026-04-19 21:51:47 +0300
commita87e799634280e2b52a5fcacafc44cb28a0d288e (patch)
treeb0fb8aa3854f0982bef448599125c0d100ffd555 /Magefile.go
t4: scaffold ComicForge Go project
Diffstat (limited to 'Magefile.go')
-rw-r--r--Magefile.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/Magefile.go b/Magefile.go
new file mode 100644
index 0000000..df71e47
--- /dev/null
+++ b/Magefile.go
@@ -0,0 +1,64 @@
+//go:build mage
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/magefile/mage/mg"
+ "github.com/magefile/mage/sh"
+)
+
+const binaryName = "comicforge"
+
+// Default builds the project.
+func Default() {
+ mg.Deps(Build)
+}
+
+// Build compiles the comicforge binary.
+func Build() error {
+ return sh.RunV("go", "build", "-o", binaryName, "./cmd/comicforge")
+}
+
+// Test runs the Go test suite.
+func Test() error {
+ return sh.RunV("go", "test", "./...")
+}
+
+// Install copies the built binary into GOPATH/bin.
+func Install() error {
+ mg.Deps(Build)
+
+ gopath, err := resolveGOPATH()
+ if err != nil {
+ return err
+ }
+
+ binDir := filepath.Join(gopath, "bin")
+ if err := os.MkdirAll(binDir, 0o755); err != nil {
+ return fmt.Errorf("create bin dir: %w", err)
+ }
+
+ return sh.RunV("cp", "-v", binaryName, filepath.Join(binDir, binaryName))
+}
+
+// Clean removes build outputs from the repository root.
+func Clean() error {
+ return sh.RunV("rm", "-f", binaryName)
+}
+
+func resolveGOPATH() (string, error) {
+ if gopath := os.Getenv("GOPATH"); gopath != "" {
+ return gopath, nil
+ }
+
+ homeDir, err := os.UserHomeDir()
+ if err != nil {
+ return "", fmt.Errorf("resolve home directory: %w", err)
+ }
+
+ return filepath.Join(homeDir, "go"), nil
+}