generated from nighthawkcoders/portfolio_2025
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Makefile
142 lines (126 loc) · 5.39 KB
/
Makefile
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
# Configuration, override port with usage: make PORT=4200
PORT ?= 4887
REPO_NAME ?= flocker_frontend
LOG_FILE = /tmp/jekyll$(PORT).log
SHELL = /bin/bash -c
.SHELLFLAGS = -e # Exceptions will stop make, works on MacOS
# Phony Targets, makefile housekeeping for below definitions
.PHONY: default server issues convert clean stop
# List all .ipynb files in the _notebooks directory
NOTEBOOK_FILES := $(shell find _notebooks -name '*.ipynb')
CSP_NOTEBOOK_FILES := $(shell find _notebooks/CSP -name '*.ipynb')
# Specify the target directory for the converted Markdown files
DESTINATION_DIRECTORY = _posts
MARKDOWN_FILES := $(patsubst _notebooks/%.ipynb,$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md,$(NOTEBOOK_FILES))
CSP_MARKDOWN_FILES := $(patsubst _notebooks/CSP/%.ipynb,$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md,$(CSP_NOTEBOOK_FILES))
# Call server, then verify and start logging
# ...
# Call server, then verify and start logging
default: server
@echo "Terminal logging starting, watching server..."
@# tail and awk work together to extract Jekyll regeneration messages
@# When a _notebook is detected in the log, call make convert in the background
@# Note: We use the "if ($$0 ~ /_notebooks\/.*\.ipynb/) { system(\"make convert &\") }" to call make convert
@(tail -f $(LOG_FILE) | awk '/Server address: http:\/\/127.0.0.1:$(PORT)\/$(REPO_NAME)\// { serverReady=1 } \
serverReady && /^ *Regenerating:/ { regenerate=1 } \
regenerate { \
if (/^[[:blank:]]*$$/) { regenerate=0 } \
else { \
print; \
if ($$0 ~ /_notebooks\/.*\.ipynb/) { system("make convert &") } \
} \
}') 2>/dev/null &
@# start an infinite loop with timeout to check log status
@for ((COUNTER = 0; ; COUNTER++)); do \
if grep -q "Server address:" $(LOG_FILE); then \
echo "Server started in $$COUNTER seconds"; \
break; \
fi; \
if [ $$COUNTER -eq 60 ]; then \
echo "Server timed out after $$COUNTER seconds."; \
echo "Review errors from $(LOG_FILE)."; \
cat $(LOG_FILE); \
exit 1; \
fi; \
sleep 1; \
done
@# outputs startup log, removes last line ($$d) as ctl-c message is not applicable for background process
@sed '$$d' $(LOG_FILE)
csp: cspserver
@echo "ONLY COMPILED CSP CONTENT"
@echo "Terminal logging starting, watching server..."
@# tail and awk work together to extract Jekyll regeneration messages
@# When a _notebook is detected in the log, call make convert in the background
@# Note: We use the "if ($$0 ~ /_notebooks\/.*\.ipynb/) { system(\"make convert &\") }" to call make convert
@(tail -f $(LOG_FILE) | awk '/Server address: http:\/\/127.0.0.1:$(PORT)\/$(REPO_NAME)\// { serverReady=1 } \
serverReady && /^ *Regenerating:/ { regenerate=1 } \
regenerate { \
if (/^[[:blank:]]*$$/) { regenerate=0 } \
else { \
print; \
if ($$0 ~ /_notebooks\/CSP\/.*\.ipynb/) { system("make convert &") } \
} \
}') 2>/dev/null &
@# start an infinite loop with timeout to check log status
@for ((COUNTER = 0; ; COUNTER++)); do \
if grep -q "Server address:" $(LOG_FILE); then \
echo "Server started in $$COUNTER seconds"; \
break; \
fi; \
if [ $$COUNTER -eq 60 ]; then \
echo "Server timed out after $$COUNTER seconds."; \
echo "Review errors from $(LOG_FILE)."; \
cat $(LOG_FILE); \
exit 1; \
fi; \
sleep 1; \
done
@# outputs startup log, removes last line ($$d) as ctl-c message is not applicable for background process
@sed '$$d' $(LOG_FILE)
# Start the local web server
server: stop convert
@echo "Starting server..."
@@nohup bundle exec jekyll serve -H 127.0.0.1 -P $(PORT) > $(LOG_FILE) 2>&1 & \
PID=$$!; \
echo "Server PID: $$PID"
@@until [ -f $(LOG_FILE) ]; do sleep 1; done
cspserver: stop cspconvert
@echo "Starting server..."
@@nohup bundle exec jekyll serve -H 127.0.0.1 -P $(PORT) > $(LOG_FILE) 2>&1 & \
PID=$$!; \
echo "Server PID: $$PID"
@@until [ -f $(LOG_FILE) ]; do sleep 1; done
# Convert .ipynb files to Markdown with front matter
convert: $(MARKDOWN_FILES)
cspconvert: $(CSP_MARKDOWN_FILES)
# Convert .ipynb files to Markdown with front matter, preserving directory structure
$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md: _notebooks/%.ipynb
@echo "Converting source $< to destination $@"
@mkdir -p $(@D)
@python3 -c 'import sys; from scripts.convert_notebooks import convert_single_notebook; convert_single_notebook(sys.argv[1])' "$<"
$(DESTINATION_DIRECTORY)/%_IPYNB_2_.md: _notebooks/CSP/%.ipynb
@echo "Converting source $< to destination $@"
@mkdir -p $(@D)
@python3 -c 'import sys; from scripts.convert_notebooks import convert_single_notebook; convert_single_notebook(sys.argv[1])' "$<"
# Clean up project derived files, to avoid run issues stop is dependency
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 "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 the server and kill processes
stop:
@echo "Stopping server..."
@# kills process running on port $(PORT)
@@lsof -ti :$(PORT) | xargs kill >/dev/null 2>&1 || true
@echo "Stopping logging process..."
@# kills previously running logging processes
@@ps aux | awk -v log_file=$(LOG_FILE) '$$0 ~ "tail -f " log_file { print $$2 }' | xargs kill >/dev/null 2>&1 || true
@# removes log
@rm -f $(LOG_FILE)