-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (126 loc) · 4.18 KB
/
Makefile
File metadata and controls
146 lines (126 loc) · 4.18 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
.PHONY: build test clean install install-local lint fmt deps
# Build variables
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-X main.Version=$(VERSION)"
BINARY := lnpm
BUILD_DIR := bin
# Default target
all: build
# Build the binary
build:
go build $(LDFLAGS) -o $(BINARY) ./cmd/lnpm
# Build for release (multiple platforms)
release:
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY)-linux-amd64 ./cmd/lnpm
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY)-linux-arm64 ./cmd/lnpm
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY)-darwin-amd64 ./cmd/lnpm
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY)-darwin-arm64 ./cmd/lnpm
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY)-windows-amd64.exe ./cmd/lnpm
# Install dependencies
deps:
go mod download
go mod tidy
# Run tests
test:
go test -v ./...
# Run tests with coverage
test-coverage:
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Run benchmarks
bench:
go test -bench=. -benchtime=3s ./tests/
# Run benchmarks with memory allocation stats
bench-mem:
go test -bench=. -benchtime=3s -benchmem ./tests/
# Compare lnpm vs competitors (yalc, relative-deps)
bench-compare:
./scripts/benchmark-compare.sh
# Run linter
lint:
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed, running go vet"; \
go vet ./...; \
fi
# Format code
fmt:
go fmt ./...
@if command -v goimports >/dev/null 2>&1; then \
goimports -w .; \
fi
# Install binary to GOPATH/bin
install: build
go install $(LDFLAGS) ./cmd/lnpm
# Install to ~/.local/bin for local testing
install-local: build
@mkdir -p ~/.local/bin
cp $(BINARY) ~/.local/bin/$(BINARY)
@echo "Installed to ~/.local/bin/lnpm"
@echo "Make sure ~/.local/bin is in your PATH"
# Clean build artifacts
clean:
rm -f $(BINARY)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
# Run the CLI (for testing)
run: build
./$(BINARY) $(ARGS)
# Development: watch and rebuild (requires entr)
watch:
@if command -v entr >/dev/null 2>&1; then \
find . -name '*.go' | entr -r make build; \
else \
echo "entr not installed. Install it for file watching."; \
fi
# Show help
help:
@echo "Available targets:"
@echo " build - Build the binary"
@echo " release - Build for all platforms"
@echo " deps - Download and tidy dependencies"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " bench - Run Go benchmarks"
@echo " bench-mem - Run benchmarks with memory stats"
@echo " bench-compare - Compare lnpm vs yalc/relative-deps"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " install - Install to GOPATH/bin"
@echo " install-local - Install to ~/.local/bin for testing"
@echo " clean - Remove build artifacts"
@echo " run ARGS=... - Build and run with arguments"
@echo " watch - Watch for changes and rebuild"
@echo " hooks-enable - Enable git hooks at .githooks"
@echo " lint-staged - Run linter on staged changes only"
# Enable git hooks (pre-commit runs golangci-lint)
.PHONY: hooks-enable
hooks-enable:
@git config core.hooksPath .githooks
@chmod +x .githooks/pre-commit .githooks/pre-push || true
@echo "Git hooks enabled (core.hooksPath=.githooks)."
# Lint only staged changes using a generated patch
.PHONY: lint-staged
lint-staged:
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint not installed. Install: brew install golangci-lint"; \
exit 1; \
fi
@if ! git rev-parse --verify HEAD >/dev/null 2>&1; then \
echo "No previous commit; running full lint"; \
golangci-lint run ./...; \
exit 0; \
fi
@TMP_PATCH=$$(mktemp); \
git diff --cached --no-color > $$TMP_PATCH; \
if [ -s $$TMP_PATCH ]; then \
golangci-lint run --new-from-patch=$$TMP_PATCH --new=false; RC=$$?; \
rm -f $$TMP_PATCH; \
exit $$RC; \
else \
echo "No staged changes to lint."; \
rm -f $$TMP_PATCH; \
fi