-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (133 loc) · 4.19 KB
/
Makefile
File metadata and controls
166 lines (133 loc) · 4.19 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Build variables
VERSION ?= v0.1.0
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
PACKAGE = github.com/techsquidtv/inkling/internal/version
LDFLAGS = -X $(PACKAGE).Version=$(VERSION) -X $(PACKAGE).Commit=$(COMMIT) -X $(PACKAGE).BuildTime=$(BUILD_TIME)
BIN_DIR = bin
BINARY_NAME = server
.PHONY: all dev run build install lint format clean test test-backend test-frontend help dev-go dev-web build-go build-web test-go test-web lint-go lint-web format-go format-web deadcode deadcode-frontend deadcode-backend init
# Initialize new project from template
init:
@if [ -f .initialized ]; then \
echo "❌ This project has already been initialized."; \
echo "To reinitialize, delete the .initialized file first."; \
exit 1; \
fi
@chmod +x scripts/init.sh
@./scripts/init.sh
all: format lint build
# Development
dev: openapi-gen
@echo "Starting backend and frontend in development mode..."
@make -j2 dev-backend dev-frontend
dev-backend:
@mkdir -p cmd/server/dist
@touch cmd/server/dist/index.html
@if ! command -v air > /dev/null; then \
echo "Air not found. Installing..."; \
go install github.com/air-verse/air@latest; \
fi
@CLICOLOR_FORCE=1 FORCE_COLOR=1 air
dev-frontend:
@cd web && pnpm dev
# OpenAPI Generation
openapi-gen:
@echo "Generating OpenAPI spec..."
@mkdir -p cmd/server/dist
@touch cmd/server/dist/index.html
@go run cmd/server/main.go openapi > openapi.json
@echo "Generating frontend API types..."
@cd web && pnpm openapi:generate
# Build
build: build-frontend build-go
build-frontend: openapi-gen
@echo "Building frontend..."
@cd web && pnpm build
build-go: build-frontend
@echo "Preparing embedded assets..."
@rm -rf cmd/server/dist
@cp -r web/dist cmd/server/dist
@echo "Building backend..."
@mkdir -p $(BIN_DIR)
@CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BINARY_NAME) cmd/server/main.go 2>&1 | grep -v "search path '/usr/local/lib' is not a directory" || true
@echo "✅ Backend build complete: $(BIN_DIR)/$(BINARY_NAME)"
# Run
run: build
@echo "Starting server..."
@./$(BIN_DIR)/$(BINARY_NAME)
# Install
install: install-frontend install-backend
install-frontend:
@echo "Installing frontend dependencies..."
@cd web && pnpm install
install-backend:
@echo "Installing backend dependencies..."
@go mod tidy
# Update
update: update-frontend update-backend
update-frontend:
@echo "Updating frontend dependencies..."
@cd web && pnpm update
@echo "✅ Frontend dependencies updated!"
update-backend:
@echo "Updating backend dependencies..."
@go get -u ./...
@go mod tidy
@echo "✅ Backend dependencies updated!"
# Linting
lint: lint-frontend lint-backend
@echo "✨ All linting passed!"
lint-frontend:
@echo "Linting frontend..."
@cd web && pnpm lint
@echo "✅ Frontend linting passed!"
lint-backend:
@echo "Linting backend..."
@go vet ./...
@echo "✅ Backend linting passed!"
# Formatting
format: format-frontend format-backend
@echo "✨ All formatting complete!"
format-frontend:
@echo "Formatting frontend..."
@cd web && pnpm format
@echo "✅ Frontend formatting complete!"
format-backend:
@echo "Formatting backend..."
@go fmt ./...
@echo "✅ Backend formatting complete!"
# Test
test: test-backend test-frontend
@echo "✨ All tests passed!"
test-backend:
@echo "Testing backend..."
@go test ./... -v -race -coverprofile=coverage.out
@echo "✅ Backend tests passed!"
@echo "Coverage report:"
@go tool cover -func=coverage.out | tail -n 1
test-frontend:
@echo "Testing frontend..."
@cd web && pnpm test:run
@echo "✅ Frontend tests passed!"
# Clean
clean:
@rm -rf $(BIN_DIR)
@rm -rf web/dist
@rm -rf cmd/server/dist
@rm -f coverage.out
# Dead Code Detection
deadcode: deadcode-frontend deadcode-backend
@echo "✨ Dead code check complete!"
deadcode-frontend:
@echo "Checking for dead code in frontend..."
@cd web && pnpm knip
@echo "✅ Frontend dead code check complete!"
deadcode-backend:
@echo "Checking for dead code in backend..."
@if ! command -v deadcode > /dev/null; then \
echo "deadcode not found. Installing..."; \
go install golang.org/x/tools/cmd/deadcode@latest; \
fi
@deadcode ./...
@echo "✅ Backend dead code check complete!"