-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathMakefile
More file actions
487 lines (435 loc) · 17.6 KB
/
Makefile
File metadata and controls
487 lines (435 loc) · 17.6 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
HOST ?= localhost
PORT ?= 4500
LOG_FILE = /tmp/jekyll$(PORT).log
PYTHON := venv/bin/python3
SHELL = /bin/bash -c
.SHELLFLAGS = -e
NOTEBOOK_FILES := $(shell find _notebooks -name '*.ipynb')
DESTINATION_DIRECTORY = _posts
MARKDOWN_FILES := $(patsubst _notebooks/%.ipynb,$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md,$(NOTEBOOK_FILES))
default: serve-current
@touch /tmp/.notebook_watch_marker
@make watch-notebooks &
@make watch-files &
@echo "Server running in background on http://localhost:$(PORT)"
@echo " View logs: tail -f $(LOG_FILE)"
@echo " Stop: make stop"
# File watcher - monitors log for file changes and triggers conversion
watch-files:
@echo "Watching for file changes (auto-convert on save)..."
@(tail -f $(LOG_FILE) | while read line; do \
if echo "$$line" | grep -q "Regenerating:"; then \
echo "$$line"; \
echo $$(date +%s) > /tmp/.jekyll_regenerating; \
elif echo "$$line" | grep -q "\.\.\.done in"; then \
rm -f /tmp/.jekyll_regenerating; \
echo " ✓ $$line"; \
elif echo "$$line" | grep -q "_notebooks/.*\.ipynb"; then \
echo "$$line"; \
notebook=$$(echo "$$line" | grep -o '_notebooks/[^[:space:]]*\.ipynb'); \
make convert-single NOTEBOOK_FILE="$$notebook" & \
elif echo "$$line" | grep -q "_docx/.*\.docx"; then \
echo "$$line"; \
docx=$$(echo "$$line" | grep -o '_docx/[^[:space:]]*\.docx'); \
make convert-docx-single DOCX_FILE="$$docx" & \
fi; \
done) 2>/dev/null & \
sleep 2; \
while true; do \
if [ -f /tmp/.jekyll_regenerating ]; then \
START=$$(cat /tmp/.jekyll_regenerating); \
NOW=$$(date +%s); \
ELAPSED=$$((NOW - START)); \
if [ $$((ELAPSED % 10)) -eq 0 ] && [ $$ELAPSED -gt 0 ]; then \
echo " Still regenerating... ($$ELAPSED seconds elapsed)"; \
fi; \
fi; \
sleep 1; \
done
use-minima:
@echo "Switching to Minima theme..."
@cp _themes/minima/_config.yml _config.yml
@cp _themes/minima/Gemfile Gemfile
@cp _themes/minima/opencs.html _layouts/opencs.html
@cp _themes/minima/page.html _layouts/page.html
@cp _themes/minima/post.html _layouts/post.html
@$(PYTHON) scripts/update_color_map.py minima || echo "⚠ Color map update failed, continuing..."
@echo "✓ Minima theme activated"
use-cayman:
@echo "Switching to Cayman theme..."
@cp _themes/cayman/_config.yml _config.yml
@cp _themes/cayman/Gemfile Gemfile
@cp _themes/cayman/opencs.html _layouts/opencs.html
@cp _themes/cayman/page.html _layouts/page.html
@cp _themes/cayman/post.html _layouts/post.html
@$(PYTHON) scripts/update_color_map.py cayman || echo "⚠ Color map update failed, continuing..."
@echo "✓ Cayman theme activated"
use-hydejack:
@echo "Switching to Hydejack theme..."
@cp _themes/hydejack/_config.yml _config.yml
@cp _themes/hydejack/Gemfile Gemfile
@cp _themes/hydejack/opencs.html _layouts/opencs.html
@cp _themes/hydejack/page.html _layouts/page.html
@cp _themes/hydejack/post.html _layouts/post.html
@$(PYTHON) scripts/update_color_map.py hydejack || echo "⚠ Color map update failed, continuing..."
@echo "✓ Hydejack theme activated"
use-so-simple:
@cp _themes/so-simple/_config.yml _config.yml
@cp _themes/so-simple/Gemfile Gemfile
@cp _themes/so-simple/opencs.html _layouts/opencs.html
@cp _themes/so-simple/page.html _layouts/page.html
@cp _themes/so-simple/post.html _layouts/post.html
@cp _themes/so-simple/navigation.yml _data/navigation.yml
use-yat:
@cp _themes/yat/_config.yml _config.yml
@cp _themes/yat/Gemfile Gemfile
@cp _themes/yat/opencs.html _layouts/opencs.html
@cp _themes/yat/page.html _layouts/page.html
@cp _themes/yat/post.html _layouts/post.html
serve-hydejack: use-hydejack clean
@make serve-current
build-tactile: use-tactile build-current
# Serve with selected theme
serve-minima: use-minima clean
@make serve-current
serve-text: use-text clean
@make serve-current
serve-cayman: use-cayman clean
@make serve-current
serve-so-simple: use-so-simple clean
@make serve-current
serve-yat: use-yat clean
@make serve-current
# Build all registered projects (game assets, not docs)
build-registered-projects:
@if [ -f _projects/.makeprojects ]; then \
grep -v '^\#' _projects/.makeprojects | grep -v '^$$' | while read proj; do \
if [ -f "_projects/$$proj/Makefile" ]; then \
echo "📦 Building project: $$proj"; \
make -C "_projects/$$proj" build 2>/dev/null || echo " ⚠️ Build failed for $$proj"; \
fi; \
done; \
fi
# Convert notebooks for all registered projects (dev mode initial build)
convert-registered-notebooks:
@if [ -f _projects/.makeprojects ]; then \
find _notebooks/projects -name '*.ipynb' 2>/dev/null | while read notebook; do \
echo "Converting project notebook: $$notebook"; \
make convert-single NOTEBOOK_FILE="$$notebook" 2>&1; \
done; \
fi
# Build documentation for all registered projects (serve mode only)
build-registered-docs:
@if [ -f _projects/.makeprojects ]; then \
grep -v '^\#' _projects/.makeprojects | grep -v '^$$' | while read proj; do \
if [ -f "_projects/$$proj/Makefile" ]; then \
echo "📚 Building docs for: $$proj"; \
make -C "_projects/$$proj" docs 2>/dev/null || true; \
fi; \
done; \
fi
# Watch all registered projects for changes (dev mode)
watch-registered-projects:
@if [ -f _projects/.makeprojects ]; then \
grep -v '^\#' _projects/.makeprojects | grep -v '^$$' | while read proj; do \
if [ -f "_projects/$$proj/Makefile" ]; then \
echo "👀 Starting watcher for: $$proj"; \
make -C "_projects/$$proj" watch & \
fi; \
done; \
fi
# Clean all registered project distributions
clean-registered-projects:
@if [ -f _projects/.makeprojects ]; then \
grep -v '^\#' _projects/.makeprojects | grep -v '^$$' | while read proj; do \
if [ -f "_projects/$$proj/Makefile" ]; then \
make -C "_projects/$$proj" clean 2>/dev/null || true; \
make -C "_projects/$$proj" docs-clean 2>/dev/null || true; \
fi; \
done; \
fi
# General serve target (uses whatever is in _config.yml/Gemfile)
serve-current: stop build-registered-projects convert split-courses build-registered-docs jekyll-serve
# Build with selected theme
build-minima: use-minima build-current
build-text: use-text build-current
build-cayman: use-cayman build-current
build-so-simple: use-so-simple build-current
build-yat: use-yat build-current
build-current: clean convert split-courses
@bundle install
@bundle exec jekyll clean
@bundle exec jekyll build
# General serve/build for whatever is current
serve: serve-current
build: build-current
# Multi-course file splitting
split-courses:
@echo " ------ Splitting multi-course files... -------"
@python3 scripts/split_multi_course_files.py
clean-courses:
@echo "🧹 Cleaning course-specific files..."
@python3 scripts/split_multi_course_files.py clean
# Notebook and DOCX conversion
convert: $(MARKDOWN_FILES) convert-docx
$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md: _notebooks/%.ipynb
@mkdir -p $(@D)
@$(PYTHON) -c "from scripts.convert_notebooks import convert_notebooks; convert_notebooks()"
# Single notebook conversion (faster for development)
convert-single:
@if [ -z "$(NOTEBOOK_FILE)" ]; then \
echo "Error: NOTEBOOK_FILE variable not set"; \
exit 1; \
fi
@echo "Converting: $(NOTEBOOK_FILE)"
@$(PYTHON) scripts/convert_notebooks.py "$(NOTEBOOK_FILE)"
# DOCX conversion
convert-docx:
@if [ -d "_docx" ] && [ "$(shell ls -A _docx 2>/dev/null)" ]; then \
$(PYTHON) scripts/convert_docx.py; \
else \
echo "No DOCX files found in _docx directory"; \
fi
# DOCX conversion for specific config change
convert-docx-config:
@if [ -d "_docx" ] && [ "$(shell ls -A _docx 2>/dev/null)" ]; then \
if [ -n "$(CONFIG_FILE)" ]; then \
echo "🔧 Config file changed: $(CONFIG_FILE)"; \
$(PYTHON) scripts/convert_docx.py --config-changed "$(CONFIG_FILE)"; \
else \
$(PYTHON) scripts/convert_docx.py; \
fi; \
else \
echo "No DOCX files found in _docx directory"; \
fi
# Clean only DOCX-converted files (safe)
clean-docx:
@echo "Cleaning DOCX-converted files..."
@find _posts -type f -name '*_DOCX_.md' -exec rm {} + 2>/dev/null || true
@echo "Cleaning extracted DOCX images..."
@rm -rf images/docx/*.png images/docx/*.jpg images/docx/*.jpeg images/docx/*.gif 2>/dev/null || true
@echo "Cleaning DOCX index page..."
@rm -f docx-index.md 2>/dev/null || true
@echo "DOCX cleanup complete"
# Color mapping
update-colors:
@echo "Updating local color map..."
@$(PYTHON) scripts/update_color_map.py
@echo "Color map updated successfully"
@echo "Generated files:"
@echo " - _sass/root-color-map.scss"
@echo " - local-color-usage-report.md"
@echo " - colors.json"
# Update colors and preview
update-colors-preview: update-colors
@echo "Starting server to preview color changes..."
@make serve-current
clean: stop
@echo "Cleaning converted IPYNB files..."
@find _posts -type f -name '*_IPYNB_2_.md' -exec rm {} +
@echo "Cleaning Github Issue files..."
@find _posts -type f -name '*_GithubIssue_.md' -exec rm {} +
@echo "Cleaning converted DOCX files..."
@find _posts -type f -name '*_DOCX_.md' -exec rm {} + 2>/dev/null || true
@echo "Cleaning course-specific files..."
@make clean-courses
@echo "Cleaning project distributions..."
@make clean-registered-projects
@echo "Cleaning extracted DOCX images..."
@rm -rf images/docx/*.png images/docx/*.jpg images/docx/*.jpeg images/docx/*.gif 2>/dev/null || true
@echo "Cleaning DOCX index page..."
@rm -f docx-index.md 2>/dev/null || true
@echo "Removing empty directories in _posts..."
@while [ $$(find _posts -type d -empty | wc -l) -gt 0 ]; do \
find _posts -type d -empty -exec rmdir {} +; \
done
@echo "Removing _site directory..."
@rm -rf _site
stop:
@echo "Stopping server..."
@@lsof -ti :$(PORT) | xargs kill >/dev/null 2>&1 || true
@echo "Stopping logging process..."
@@ps aux | awk -v log_file=$(LOG_FILE) '$$0 ~ "tail -f " log_file { print $$2 }' | xargs kill >/dev/null 2>&1 || true
@echo "Stopping notebook watcher..."
@@ps aux | grep "watch-notebooks" | grep -v grep | awk '{print $$2}' | xargs kill >/dev/null 2>&1 || true
@@ps aux | grep "find _notebooks" | grep -v grep | awk '{print $$2}' | xargs kill >/dev/null 2>&1 || true
@echo "Stopping project watchers..."
@@ps aux | grep "fswatch.*_projects" | grep -v grep | awk '{print $$2}' | xargs kill >/dev/null 2>&1 || true
@@ps aux | grep "make -C _projects" | grep -v grep | awk '{print $$2}' | xargs kill >/dev/null 2>&1 || true
@rm -f $(LOG_FILE) /tmp/.notebook_watch_marker /tmp/.jekyll_regenerating
reload:
@make stop
@make
refresh:
@make stop
@make clean
@make
# Development mode: clean start, no conversion, converts files on save
# Runs in background - use 'make stop' to stop, 'tail -f /tmp/jekyll4500.log' to view logs
dev: stop clean
@echo "📦 Building registered projects..."
@make build-registered-projects
@make convert-registered-notebooks
@make jekyll-serve
@make watch-notebooks &
@make watch-files &
@make watch-registered-projects &
@echo "Dev server running in background on http://localhost:$(PORT)"
@echo " View logs: tail -f $(LOG_FILE)"
@echo " Stop: make stop"
# Watch notebooks directory for changes (since Jekyll excludes _notebooks)
# Converts immediately (async), Jekyll serve handles regeneration batching
# Excludes _notebooks/projects/* (handled by project-specific watchers)
watch-notebooks:
@echo "Watching _notebooks for changes..."
@while true; do \
find _notebooks -path "_notebooks/projects" -prune -o -name '*.ipynb' -newer /tmp/.notebook_watch_marker -print 2>/dev/null | while read notebook; do \
echo "Notebook changed: $$notebook"; \
make convert-single NOTEBOOK_FILE="$$notebook" & \
done; \
touch /tmp/.notebook_watch_marker; \
sleep 2; \
done
# Bundle install (only runs if Gemfile changed)
bundle-install:
@if [ ! -f .bundle/install_marker ] || [ Gemfile -nt .bundle/install_marker ]; then \
echo "Installing bundle..."; \
bundle install; \
mkdir -p .bundle && touch .bundle/install_marker; \
fi
# Start Jekyll server (incremental for development, production is GitHub Actions)
# Supports optional _config.local.yml override for local settings (e.g. baseurl)
jekyll-serve: bundle-install
@touch /tmp/.notebook_watch_marker
@if [ -f _config.local.yml ]; then \
echo "Using local config override: _config.local.yml"; \
bundle exec jekyll serve -H $(HOST) -P $(PORT) --incremental --config _config.yml,_config.local.yml > $(LOG_FILE) 2>&1 & \
echo "Server PID: $$!"; \
else \
bundle exec jekyll serve -H $(HOST) -P $(PORT) --incremental > $(LOG_FILE) 2>&1 & \
echo "Server PID: $$!"; \
fi
@make wait-for-server
# Common server wait logic
wait-for-server:
@until [ -f $(LOG_FILE) ]; do sleep 1; done
@for ((COUNTER = 0; ; COUNTER++)); do \
if grep -q "Server address:" $(LOG_FILE); then \
echo "Server started in $$COUNTER seconds"; \
grep "Server address:" $(LOG_FILE); \
break; \
fi; \
if [ $$COUNTER -eq 300 ]; then \
echo "Server timed out after $$COUNTER seconds."; \
echo "Review errors from $(LOG_FILE)."; \
cat $(LOG_FILE); \
exit 1; \
fi; \
if [ $$COUNTER -gt 5 ] && grep -E -qi "\bfatal\b|\bexception\b" $(LOG_FILE); then \
echo "Fatal error detected during startup!"; \
cat $(LOG_FILE); \
exit 1; \
fi; \
if [ $$((COUNTER % 10)) -eq 0 ] && [ $$COUNTER -gt 0 ]; then \
echo "Still starting... ($$COUNTER seconds elapsed)"; \
fi; \
sleep 1; \
done
# Single DOCX file conversion (for dev mode)
convert-docx-single:
@if [ -z "$(DOCX_FILE)" ]; then \
echo "Error: DOCX_FILE variable not set"; \
exit 1; \
fi
@echo "Converting: $(DOCX_FILE)"
@$(PYTHON) scripts/convert_docx.py --single "$(DOCX_FILE)" 2>/dev/null || $(PYTHON) scripts/convert_docx.py
docx-only: convert-docx
@echo "DOCX conversion complete - ready for preview"
preview-docx: clean-docx convert-docx
@echo "Converting DOCX and starting preview server..."
@make serve-current
help:
@echo "Available Makefile commands:"
@echo ""
@echo "Theme Serve Commands:"
@echo " make serve-minima - Switch to Minima and serve"
@echo " make serve-text - Switch to TeXt and serve"
@echo " make serve-cayman - Switch to Cayman and serve"
@echo " make serve-so-simple - Switch to So Simple and serve"
@echo " make serve-yat - Switch to Yat and serve"
@echo " make serve-hydejack - Switch to HydeJack and serve"
@echo ""
@echo "Theme Build Commands:"
@echo " make build-minima - Switch to Minima and build"
@echo " make build-text - Switch to TeXt and build"
@echo " make build-cayman - Switch to Cayman and build"
@echo " make build-so-simple - Switch to So Simple and build"
@echo " make build-yat - Switch to Yat and build"
@echo ""
@echo "Color Mapping Commands:"
@echo " make update-colors - Update local color map"
@echo " make update-colors-preview - Update colors and start server"
@echo ""
@echo "Server Commands:"
@echo " make - Full conversion, serve, and watch for file changes (auto-convert on save)"
@echo " make dev - Fast dev mode: clean start, no conversion, file watching, only convert files on save (quick)"
@echo " make serve - Convert and serve (no auto-convert watching)"
@echo " make build - Convert and build _site/ for deployment (no server)"
@echo " make stop - Stop server and logging"
@echo " make reload - Stop and restart server"
@echo " make refresh - Stop, clean, and restart server"
@echo ""
@echo "Conversion Commands:"
@echo " make convert - Convert notebooks and DOCX files"
@echo " make convert-docx - Convert DOCX files only"
@echo " make split-courses - Split multi-course files automatically"
@echo " make docx-only - Convert DOCX and prepare for preview"
@echo " make preview-docx - Clean, convert DOCX, and serve"
@echo ""
@echo "Cleanup Commands:"
@echo " make clean - Remove all generated files"
@echo " make clean-docx - Remove DOCX-generated files only"
@echo " make clean-courses - Remove course-specific split files only"
@echo ""
@echo "Diagnostic Commands:"
@echo " make convert-check - Check notebooks for conversion warnings"
@echo " make convert-fix - Fix identified notebook conversion issues"
# Notebook diagnostic and fix targets
convert-check:
@echo "Running conversion diagnostics..."
@echo "Checking for notebook conversion warnings or errors..."
@$(PYTHON) scripts/check_conversion_warnings.py
convert-fix:
@echo "Running conversion fixes..."
@echo "️Fixing notebooks with known warnings or errors..."
@$(PYTHON) scripts/check_conversion_warnings.py --fix
###########################################
# Project Auto-Registration
###########################################
# Projects are registered in _projects/.makeprojects (one per line)
# Each project must have: _projects/<name>/Makefile with generic targets: build, clean, docs, watch
# Main Makefile calls projects via: make -C _projects/<name> <target>
# List all registered projects
list-projects:
@echo "📦 Registered Projects:"
@if [ -f _projects/.makeprojects ]; then \
grep -v '^\#' _projects/.makeprojects | grep -v '^$$' | while read proj; do \
if [ -f "_projects/$$proj/Makefile" ]; then \
echo " ✅ $$proj (active)"; \
else \
echo " ⚠️ $$proj (missing Makefile)"; \
fi; \
done; \
else \
echo " No _projects/.makeprojects file found"; \
fi
@echo ""
@echo "Available projects (in _projects/ directory):"
@ls -d _projects/*/ 2>/dev/null | sed 's|_projects/||' | sed 's|/||' | while read proj; do \
if grep -q "^$$proj$$" _projects/.makeprojects 2>/dev/null; then \
echo " • $$proj (registered)"; \
else \
echo " • $$proj (not registered)"; \
fi; \
done || echo " None found"
.PHONY: list-projects build-registered-projects convert-registered-notebooks build-registered-docs watch-registered-projects clean-registered-projects