-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMakefile
More file actions
272 lines (237 loc) · 11.4 KB
/
Copy pathMakefile
File metadata and controls
272 lines (237 loc) · 11.4 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Makefile for the LFE Website
# ANSI color codes
BLUE := \033[1;34m
GREEN := \033[1;32m
YELLOW := \033[1;33m
RED := \033[1;31m
CYAN := \033[1;36m
RESET := \033[0m
# Variables
PROJECT_NAME := LFE Website
PUBLISH_DIR := site
PORT := 5093
BINARY := lfesite
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
# Default target
.DEFAULT_GOAL := help
# Help target
.PHONY: help
help:
@echo ""
@echo "$(CYAN)╔══════════════════════════════════════════════════════════╗$(RESET)"
@echo "$(CYAN)║$(RESET) $(BLUE)$(PROJECT_NAME) Build System$(RESET) $(CYAN)║$(RESET)"
@echo "$(CYAN)╚══════════════════════════════════════════════════════════╝$(RESET)"
@echo ""
@echo "$(GREEN)Site:$(RESET)"
@echo " $(YELLOW)make build$(RESET) - Build the site (prerender + sass + tailwind + cobalt)"
@echo " $(YELLOW)make serve$(RESET) - Start dev server with file watching (port $(PORT))"
@echo " $(YELLOW)make clean$(RESET) - Remove build output"
@echo ""
@echo "$(GREEN)Development:$(RESET)"
@echo " $(YELLOW)make install$(RESET) - Install $(BINARY) and cobalt"
@echo " $(YELLOW)make prerender$(RESET) - Render _md fields to _html in data files"
@echo " $(YELLOW)make validate$(RESET) - Check data files, front-matter, and layouts"
@echo " $(YELLOW)make version-check$(RESET) - Audit data.written_for version banners on posts"
@echo " $(YELLOW)make version-fix$(RESET) - Fill data.written_for banners on posts (writes files)"
@echo " $(YELLOW)make sync-versions$(RESET) - Regenerate src/_data/lfe_versions.yml from release history"
@echo " $(YELLOW)make update-versions$(RESET) - Pull new LFE/Erlang tags from GitHub and refresh version data"
@echo " $(YELLOW)make update-versions-dry$(RESET) - Preview update-versions without writing"
@echo " $(YELLOW)make migrate$(RESET) - One-shot Zola to Cobalt migration"
@echo ""
@echo "$(GREEN)Testing & Quality:$(RESET)"
@echo " $(YELLOW)make test$(RESET) - Run $(BINARY) tests"
@echo " $(YELLOW)make lint$(RESET) - Run clippy, format check, and tag/category check"
@echo " $(YELLOW)make check-tags-cats$(RESET) - Ensure no spaces in post tags/categories"
@echo " $(YELLOW)make format$(RESET) - Format Rust code"
@echo " $(YELLOW)make check$(RESET) - lint + test + validate + version-check"
@echo ""
@echo "$(GREEN)Spelling:$(RESET)"
@echo " $(YELLOW)make spell-check$(RESET) - Check for spelling errors in markdown"
@echo " $(YELLOW)make spell-suggest$(RESET) - Show spelling suggestions"
@echo " $(YELLOW)make add-word$(RESET) - Add a word to the dictionary (WORD=foo)"
@echo ""
@echo "$(GREEN)Information:$(RESET)"
@echo " $(YELLOW)make info$(RESET) - Show build information"
@echo " $(YELLOW)make check-tools$(RESET) - Verify required tools are installed"
@echo ""
@echo "$(CYAN)Current status:$(RESET) Branch: $(GIT_BRANCH) | Commit: $(GIT_COMMIT)"
@echo ""
#############################################################################
### INFORMATION #########################################################
#############################################################################
.PHONY: info
info:
@echo ""
@echo "$(CYAN)╔══════════════════════════════════════════════════════════╗$(RESET)"
@echo "$(CYAN)║$(RESET) $(BLUE)Build Information$(RESET) $(CYAN)║$(RESET)"
@echo "$(CYAN)╚══════════════════════════════════════════════════════════╝$(RESET)"
@echo ""
@echo "$(GREEN)Project:$(RESET)"
@echo " Name: $(PROJECT_NAME)"
@echo " Workspace: $$(pwd)"
@echo ""
@echo "$(GREEN)Git:$(RESET)"
@echo " Branch: $(GIT_BRANCH)"
@echo " Commit: $(GIT_COMMIT)"
@echo ""
@echo "$(GREEN)Tools:$(RESET)"
@echo " Rust: $$(rustc --version 2>/dev/null || echo 'not found')"
@echo " Cobalt: $$(cobalt --version 2>/dev/null || echo 'not found')"
@echo " $(BINARY): $$($(BINARY) --version 2>/dev/null || echo 'not found')"
@echo " Tailwind: $$(tailwindcss --version 2>/dev/null || echo 'not found')"
@echo ""
.PHONY: check-tools
check-tools:
@echo "$(BLUE)Checking for required tools...$(RESET)"
@command -v rustc >/dev/null 2>&1 && echo "$(GREEN) ✓ rustc found$(RESET)" || echo "$(RED) ✗ rustc not found$(RESET)"
@command -v cargo >/dev/null 2>&1 && echo "$(GREEN) ✓ cargo found$(RESET)" || echo "$(RED) ✗ cargo not found$(RESET)"
@command -v cobalt >/dev/null 2>&1 && echo "$(GREEN) ✓ cobalt found$(RESET)" || echo "$(RED) ✗ cobalt not found (install: cargo install cobalt-bin)$(RESET)"
@command -v $(BINARY) >/dev/null 2>&1 && echo "$(GREEN) ✓ lfesite found$(RESET)" || echo "$(RED) ✗ $(BINARY) not found (install: make install)$(RESET)"
@(command -v tailwindcss >/dev/null 2>&1 || command -v npx >/dev/null 2>&1) && echo "$(GREEN) ✓ tailwindcss found$(RESET)" || echo "$(RED) ✗ tailwindcss not found$(RESET)"
@command -v aspell >/dev/null 2>&1 && echo "$(GREEN) ✓ aspell found$(RESET)" || echo "$(YELLOW) ⊙ aspell not found (optional, for spell checking)$(RESET)"
#############################################################################
### SITE ################################################################
#############################################################################
LFESITE := $(shell command -v $(BINARY) 2>/dev/null)
.PHONY: ensure-lfesite
ensure-lfesite:
ifndef LFESITE
@echo "$(YELLOW)→ Installing $(BINARY)...$(RESET)"
@cargo install --path tools/$(BINARY)
endif
.PHONY: build
build: ensure-lfesite
@echo "$(BLUE)Building $(PROJECT_NAME)...$(RESET)"
@$(BINARY) build
@echo "$(GREEN)✓ Build complete$(RESET)"
.PHONY: serve
serve: ensure-lfesite
@echo "$(BLUE)Starting dev server on port $(PORT)...$(RESET)"
@$(BINARY) serve --port $(PORT)
.PHONY: run
run: serve
.PHONY: clean
clean:
@echo "$(BLUE)Cleaning build output...$(RESET)"
@rm -rf $(PUBLISH_DIR) _site target/*/$(BINARY)
@cargo uninstall $(BINARY) 2>/dev/null || true
@echo "$(GREEN)✓ Clean complete$(RESET)"
#############################################################################
### DEVELOPMENT #########################################################
#############################################################################
.PHONY: install
install:
@echo "$(BLUE)Installing $(BINARY)...$(RESET)"
@cargo install --path tools/$(BINARY)
@echo "$(GREEN)✓ $(BINARY) installed$(RESET)"
@echo "$(BLUE)Installing cobalt...$(RESET)"
@cargo install cobalt-bin
@echo "$(GREEN)✓ cobalt installed$(RESET)"
.PHONY: prerender
prerender:
@echo "$(BLUE)Pre-rendering data files...$(RESET)"
@$(BINARY) prerender
@echo "$(GREEN)✓ Prerender complete$(RESET)"
.PHONY: validate
validate:
@$(BINARY) validate
.PHONY: version-check
version-check:
@$(BINARY) version-check
.PHONY: version-fix
version-fix:
@echo "$(YELLOW)⚠ This will write data.written_for into posts$(RESET)"
@$(BINARY) version-check --fix
.PHONY: sync-versions
sync-versions:
@$(BINARY) sync-versions
.PHONY: update-versions
update-versions:
@$(BINARY) update-versions
.PHONY: update-versions-dry
update-versions-dry:
@$(BINARY) update-versions --dry-run
.PHONY: migrate
migrate:
@echo "$(YELLOW)⚠ This will modify content files in place$(RESET)"
@$(BINARY) migrate
#############################################################################
### TESTING & QUALITY ###################################################
#############################################################################
.PHONY: test
test:
@echo "$(BLUE)Running tests...$(RESET)"
@cargo test --workspace
@echo "$(GREEN)✓ All tests passed$(RESET)"
.PHONY: lint
lint: check-tags-cats
@echo "$(BLUE)Running linter checks...$(RESET)"
@echo "$(CYAN) • Running clippy...$(RESET)"
@cargo clippy --workspace -- -D warnings
@echo "$(GREEN) ✓ Clippy passed$(RESET)"
@echo "$(CYAN) • Checking code formatting...$(RESET)"
@cargo fmt --all -- --check
@echo "$(GREEN) ✓ Format check passed$(RESET)"
# Enforce the no-spaces rule for post tags/categories (spaces break tag URLs,
# e.g. /blog/tags/lfe%20friday/). Scans every tags:/categories: line, strips
# the YAML brackets and comma separators, and fails if any element still
# contains a space. Use hyphens instead (lfe-friday, not "lfe friday").
.PHONY: check-tags-cats
check-tags-cats:
@echo "$(BLUE)Checking post tags/categories for spaces...$(RESET)"
@files=$$(grep -rlE '^(tags|categories):' src/posts/ 2>/dev/null); \
if [ -z "$$files" ]; then echo "$(GREEN) ✓ no tag/category metadata found$(RESET)"; exit 0; fi; \
bad=$$(awk '/^(tags|categories):/{l=$$0; sub(/^[a-z]+: *\[/,"",l); sub(/\].*$$/,"",l); gsub(/ *, */,",",l); gsub(/,/,"",l); if(l ~ / /) print FILENAME":"FNR": "$$0}' $$files); \
if [ -n "$$bad" ]; then \
echo "$(RED) ✗ spaces found in tags/categories (use '-' instead):$(RESET)"; \
echo "$$bad" | sed 's/^/ /'; \
exit 1; \
fi; \
echo "$(GREEN) ✓ no spaces in tags/categories$(RESET)"
.PHONY: format
format:
@echo "$(BLUE)Formatting code...$(RESET)"
@cargo fmt --all
@echo "$(GREEN)✓ Code formatted$(RESET)"
.PHONY: check
check: lint test validate check-tags-cats version-check
@echo ""
@echo "$(GREEN)✓ All checks passed (lint + test + validate + version-check)$(RESET)"
@echo ""
#############################################################################
### SPELLING ############################################################
#############################################################################
.PHONY: spell-check
spell-check:
@echo "$(BLUE)Checking spelling...$(RESET)"
@for FILE in $$(find . -name "*.md" -not -path "./node_modules/*" -not -path "./target/*" -not -path "./workbench/*"); do \
RESULTS=$$(cat $$FILE | aspell -d en_GB --mode=markdown list | sort -u | sed -e ':a' -e 'N;$$!ba' -e 's/\n/, /g'); \
if [[ "$$RESULTS" != "" ]] ; then \
echo "$(YELLOW) ⊙ $$FILE:$(RESET)"; \
echo " $$RESULTS"; \
fi; \
done
@echo "$(GREEN)✓ Spell check complete$(RESET)"
.PHONY: spell-suggest
spell-suggest:
@echo "$(BLUE)Generating spelling suggestions...$(RESET)"
@for FILE in $$(find . -name "*.md" -not -path "./node_modules/*" -not -path "./target/*" -not -path "./workbench/*"); do \
RESULTS=$$(cat $$FILE | aspell -d en_GB --mode=markdown list | sort -u ); \
if [[ "$$RESULTS" != "" ]] ; then \
echo "$(YELLOW) ⊙ $$FILE:$(RESET)"; \
for WORD in $$RESULTS; do \
echo $$WORD| aspell -d en_GB pipe | tail -2|head -1 | sed -e 's/^/ /'; \
done; \
fi; \
done
add-word: WORD ?= ""
add-word:
@echo "*$(WORD)\n#" | aspell -a
add-words: WORDS ?= ""
add-words:
@echo "$(BLUE)Adding words:$(RESET)"
@for WORD in $$(echo $(WORDS)| tr "," "\n"| tr "," "\n" | sed -e 's/^[ ]*//' | sed -e 's/[ ]*$$//'); \
do echo " $(GREEN)✓$(RESET) $$WORD"; \
echo "*$$WORD\n#" | aspell -a > /dev/null; \
done