-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
321 lines (286 loc) Β· 12.7 KB
/
Makefile
File metadata and controls
321 lines (286 loc) Β· 12.7 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# Makefile for Technical Documentation Build System
# Builds diagrams, colors, PDF, and HTML with dark mode support
# Supports multiple projects
.PHONY: all clean colors diagrams pdf html help check test example technical-documentation rebuild install-hook build-project build-summary check-outputs clean-outputs clean-generated server-start server-stop server-status version bump-patch bump-minor bump-major
# Default project (matches the actual source directory)
PROJECT ?= docs
# Theme toggle configuration
# Set to "yes" to include theme toggle button, "no" to use auto (system settings only)
THEME_TOGGLE ?= yes
# Project configurations
TECH_DOC_SRC = docs/main.typ
TECH_DOC_OUT = build/technical-documentation
EXAMPLE_SRC = example/docs/main.typ
EXAMPLE_OUT = example/build/technical-documentation
# Default target - builds the technical-documentation project
all: technical-documentation
# Internal: Build a project (called with SRC, OUT, and PROJECT parameters)
build-project:
@$(MAKE) colors
@$(MAKE) diagrams PROJECT=$(PROJECT)
@$(MAKE) pdf-only SRC=$(SRC) OUT=$(OUT)
@$(MAKE) html-only SRC=$(SRC) OUT=$(OUT)
# Internal: Show build completion summary
build-summary:
@echo ""
@echo "=================================================="
@echo "β
Build Complete!"
@echo "=================================================="
@echo "π PDF: $(OUT).pdf"
@echo "π HTML: http://localhost:8000/$(OUT).html"
@echo ""
@echo "π‘ Click the HTML link above to open in browser"
# Build technical-documentation project (the default for real work)
technical-documentation:
@echo "=================================================="
@echo "π Building Technical Documentation Project"
@echo "=================================================="
@$(MAKE) build-project SRC=$(TECH_DOC_SRC) OUT=$(TECH_DOC_OUT) PROJECT=docs
@$(MAKE) server-start
@$(MAKE) build-summary OUT=$(TECH_DOC_OUT)
@echo "π Toggle dark mode with the button in top-right"
# Build example project (uses same build process as technical-documentation)
example:
@echo "=================================================="
@echo "π¨ Building Example Project"
@echo "=================================================="
@$(MAKE) colors
@$(MAKE) diagrams PROJECT=example
@$(MAKE) python-diagrams
@$(MAKE) python-api
@$(MAKE) python-tests
@$(MAKE) pdf-only SRC=$(EXAMPLE_SRC) OUT=$(EXAMPLE_OUT)
@$(MAKE) html-only SRC=$(EXAMPLE_SRC) OUT=$(EXAMPLE_OUT)
@$(MAKE) server-start
@$(MAKE) build-summary OUT=$(EXAMPLE_OUT)
@echo "π Toggle dark mode with the button in top-right"
# Generate color files (CSS and Typst) from colors.json
colors:
@echo "π¨ Generating color files..."
@python3 scripts/build-colors.py
# Build python-project API documentation
python-api:
@echo "π Generating Python API documentation..."
@cd example/python-project && python3 -m src.doc_generator.extract_api
# Build python-project test reports
python-tests:
@echo "π§ͺ Generating Python test reports..."
@cd example/python-project && python3 -m src.doc_generator.test_report
# Build python-project diagrams (including v-model and build-pipeline)
# Note: These diagrams are in example/docs/diagrams but need theme-aware compilation
python-diagrams:
@echo "π Compiling additional diagrams..."
@mkdir -p example/build/diagrams
@typst compile --root . --input theme=light --format svg example/docs/diagrams/v-model.typ example/build/diagrams/v-model-light.svg
@typst compile --root . --input theme=dark --format svg example/docs/diagrams/v-model.typ example/build/diagrams/v-model-dark.svg
@cp example/build/diagrams/v-model-light.svg example/build/diagrams/v-model.svg
@typst compile --root . --input theme=light --format svg example/docs/diagrams/build-pipeline.typ example/build/diagrams/build-pipeline-light.svg
@typst compile --root . --input theme=dark --format svg example/docs/diagrams/build-pipeline.typ example/build/diagrams/build-pipeline-dark.svg
@cp example/build/diagrams/build-pipeline-light.svg example/build/diagrams/build-pipeline.svg
@echo "β Additional diagrams created"
# Compile diagrams to SVG (with project parameter)
diagrams: colors
@echo "π Compiling diagrams for $(PROJECT)..."
@python3 scripts/build-diagrams.py $(PROJECT)
# Internal target: Compile PDF (called with SRC and OUT parameters)
pdf-only:
@echo "π Compiling PDF: $(OUT).pdf..."
@mkdir -p $$(dirname $(OUT).pdf)
@typst compile --root . $(SRC) $(OUT).pdf
@echo "β PDF created: $(OUT).pdf"
# Internal target: Compile HTML (called with SRC and OUT parameters)
html-only:
@echo "π Compiling HTML with Bootstrap: $(OUT).html..."
@mkdir -p $$(dirname $(OUT).html)
ifeq ($(THEME_TOGGLE),yes)
@python3 scripts/build-html-bootstrap.py $(SRC) $(OUT).html
else
@python3 scripts/build-html-bootstrap.py $(SRC) $(OUT).html --no-theme-toggle
endif
@echo "β Bootstrap HTML created: $(OUT).html"
# User-friendly targets for building just PDF or HTML
pdf:
@$(MAKE) colors
@$(MAKE) diagrams PROJECT=$(PROJECT)
@$(MAKE) pdf-only SRC=$(TECH_DOC_SRC) OUT=$(TECH_DOC_OUT)
html:
@$(MAKE) colors
@$(MAKE) diagrams PROJECT=$(PROJECT)
@$(MAKE) html-only SRC=$(TECH_DOC_SRC) OUT=$(TECH_DOC_OUT)
# Check for errors without building
check:
@echo "π Checking configuration..."
@python3 -c "import json; json.load(open('lib/colors.json')); print('β lib/colors.json is valid')"
@python3 -c "from pathlib import Path; assert Path('lib/technical-documentation-package.typ').exists(); print('β Package exists')"
@python3 -c "from pathlib import Path; assert Path('docs/main.typ').exists(); print('β Main document exists')"
@echo "β
All checks passed"
# Internal: Check that build outputs exist
check-outputs:
@test -f build/technical-documentation.pdf && echo "β Technical doc PDF exists" || echo "β Technical doc PDF missing"
@test -f build/technical-documentation.html && echo "β Technical doc HTML exists" || echo "β Technical doc HTML missing"
@test -f example/build/technical-documentation.pdf && echo "β Example PDF exists" || echo "β Example PDF missing"
@test -f example/build/technical-documentation.html && echo "β Example HTML exists" || echo "β Example HTML missing"
@test -f lib/generated/colors.css && echo "β Colors generated" || echo "β Colors missing"
# Quick test - compile everything and check outputs exist
test: technical-documentation example
@echo "π§ͺ Testing build outputs..."
@$(MAKE) check-outputs
@echo "β
All tests passed"
# Internal: Remove PDF and HTML outputs
clean-outputs:
@rm -rf build/
@rm -rf example/build/
@rm -rf example/python-project/build/
@rm -f *_temp*.html
# Internal: Remove generated files
clean-generated:
@rm -f colors.css
@rm -f styles-bootstrap.css
@rm -f lib/generated/colors.css
@rm -f lib/generated/colors.typ
# Clean build artifacts
clean:
@echo "π§Ή Cleaning build artifacts..."
@$(MAKE) server-stop 2>/dev/null || true
@$(MAKE) clean-outputs
@$(MAKE) clean-generated
@rm -f .server.pid
@echo "β Clean complete"
# Clean and rebuild everything
rebuild: clean all
# Show help
help:
@echo "Technical Documentation Build System"
@echo "===================================="
@echo ""
@echo "Main targets:"
@echo " make - Build technical-documentation (default)"
@echo " make example - Build the example project"
@echo " make test - Build and validate all projects"
@echo ""
@echo "Component targets:"
@echo " make colors - Generate color files from colors.json"
@echo " make diagrams PROJECT=xxx - Compile diagrams for specific project"
@echo " make pdf - Compile PDF for default project"
@echo " make html - Compile HTML (Bootstrap styling)"
@echo ""
@echo "Configuration:"
@echo " THEME_TOGGLE=yes|no - Include theme toggle button (default: yes)"
@echo " Set to 'no' to use auto (system settings only)"
@echo ""
@echo "Utility targets:"
@echo " make check - Validate configuration files"
@echo " make test - Build and test all outputs"
@echo " make clean - Remove all build artifacts"
@echo " make rebuild - Clean and rebuild everything"
@echo " make help - Show this help message"
@echo ""
@echo "Server targets:"
@echo " make server-start - Start dev server (live-server or Python fallback) on port 8000"
@echo " make server-stop - Stop the HTTP server"
@echo " make server-status - Check server status"
@echo ""
@echo "Version management:"
@echo " make version - Show current version from pyproject.toml"
@echo " make bump-patch - Bump patch version (0.3.2 β 0.3.3)"
@echo " make bump-minor - Bump minor version (0.3.2 β 0.4.0)"
@echo " make bump-major - Bump major version (0.3.2 β 1.0.0)"
@echo ""
@echo "Pre-commit hook:"
@echo " make install-hook - Install git pre-commit hook"
@echo ""
@echo "Examples:"
@echo " make # Build technical-documentation (starts server)"
@echo " make example # Build example project (starts server)"
@echo " make server-stop # Stop the HTTP server"
@echo " make THEME_TOGGLE=no # Build without theme toggle (auto only)"
@echo " make diagrams PROJECT=example # Just compile example diagrams"
@echo " make rebuild # Clean and rebuild"
# Install pre-commit hook
install-hook:
@echo "π Installing pre-commit hook..."
@mkdir -p .git/hooks
@cp scripts/build-hooks/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "β Pre-commit hook installed"
@echo ""
@echo "The hook will:"
@echo " 1. Check if colors.json was modified"
@echo " 2. Check if diagram .typ files were modified"
@echo " 3. Rebuild affected components"
@echo " 4. Stage updated files for commit"
# HTTP Server Management
server-start:
@if [ -f .server.pid ] && kill -0 $$(cat .server.pid) 2>/dev/null; then \
echo "β
Server already running (PID: $$(cat .server.pid))"; \
else \
rm -f .server.pid; \
if command -v live-server >/dev/null 2>&1; then \
echo "π Starting live-server..."; \
live-server --port=8000 --no-browser --quiet --wait=100 > /dev/null 2>&1 & echo $$! > .server.pid; \
else \
echo "β οΈ live-server not found, falling back to Python server"; \
python3 scripts/dev-server.py -p 8000 > /dev/null 2>&1 & echo $$! > .server.pid; \
fi; \
sleep 1; \
if [ -f .server.pid ] && kill -0 $$(cat .server.pid) 2>/dev/null; then \
echo "π Server started (PID: $$(cat .server.pid))"; \
echo "π http://localhost:8000/build/technical-documentation.html"; \
else \
echo "β Failed to start server (port may be in use)"; \
rm -f .server.pid; \
exit 1; \
fi; \
fi
server-stop:
@if [ -f .server.pid ]; then \
if kill -0 $$(cat .server.pid) 2>/dev/null; then \
kill $$(cat .server.pid) 2>/dev/null && echo "π Server stopped (PID: $$(cat .server.pid))"; \
else \
echo "βΉοΈ Server not running (stale PID file)"; \
fi; \
rm -f .server.pid; \
else \
echo "βΉοΈ No PID file found (.server.pid)"; \
echo " If server is still running, kill it manually"; \
fi
server-status:
@if [ -f .server.pid ]; then \
if kill -0 $$(cat .server.pid) 2>/dev/null; then \
echo "β
Server is running (PID: $$(cat .server.pid))"; \
echo "π http://localhost:8000/"; \
else \
echo "β Server not running (stale PID file found)"; \
rm -f .server.pid; \
fi; \
else \
echo "βΉοΈ Server not running (no PID file)"; \
echo " Start with: make server-start"; \
fi
# ==============================================================================
# Version Management
# ==============================================================================
# Show current version from pyproject.toml
version:
@echo "Current version: $$(python3 scripts/get_version.py)"
# Bump patch version (0.3.2 β 0.3.3)
bump-patch:
@echo "π Bumping patch version..."
@python3 scripts/bump_version.py patch
@echo ""
@echo "π Next: Review and update CHANGELOG.md with actual changes"
@echo "πΎ Then: git add pyproject.toml CHANGELOG.md && git commit -m 'chore(release): bump version'"
# Bump minor version (0.3.2 β 0.4.0)
bump-minor:
@echo "π Bumping minor version..."
@python3 scripts/bump_version.py minor
@echo ""
@echo "π Next: Review and update CHANGELOG.md with actual changes"
@echo "πΎ Then: git add pyproject.toml CHANGELOG.md && git commit -m 'chore(release): bump version'"
# Bump major version (0.3.2 β 1.0.0)
bump-major:
@echo "π Bumping major version..."
@python3 scripts/bump_version.py major
@echo ""
@echo "π Next: Review and update CHANGELOG.md with actual changes"
@echo "πΎ Then: git add pyproject.toml CHANGELOG.md && git commit -m 'chore(release): bump version'"