Skip to content

Commit 4c1c84f

Browse files
committed
build: add local CI/CD tools (Makefile, build scripts, pre-commit)
- Add Makefile for simple build commands (make, make serve, make ai) - Add build.bat/build.sh scripts mirroring CI/CD pipeline - Add .pre-commit-config.yaml for automatic mindmap regeneration - Update docs/GITHUB_PAGES_SETUP.md with all local build options Local build options: - make (recommended): Simple, universal - act: Run actual GitHub Actions locally - build scripts: Platform-specific - pre-commit: Auto-trigger on commit
1 parent b5938fa commit 4c1c84f

File tree

5 files changed

+561
-16
lines changed

5 files changed

+561
-16
lines changed

.pre-commit-config.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Pre-commit hooks configuration
2+
# Install: pip install pre-commit && pre-commit install
3+
# Manual run: pre-commit run --all-files
4+
#
5+
# This ensures mindmaps are regenerated before each commit
6+
# when ontology or meta files change.
7+
8+
repos:
9+
# Standard hooks
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v4.5.0
12+
hooks:
13+
- id: trailing-whitespace
14+
exclude: '\.md$'
15+
- id: end-of-file-fixer
16+
exclude: '\.md$'
17+
- id: check-yaml
18+
- id: check-toml
19+
20+
# Local hooks for mindmap generation
21+
- repo: local
22+
hooks:
23+
# Regenerate mindmaps when source files change
24+
- id: generate-mindmaps
25+
name: Generate Mindmaps
26+
entry: leetcode/Scripts/python.exe tools/generate_mindmaps.py
27+
language: system
28+
files: ^(ontology/|meta/problems/|tools/generate_mindmaps\.py)
29+
pass_filenames: false
30+
stages: [commit]
31+
32+
# Run solution format check
33+
- id: check-solutions
34+
name: Check Solution Format
35+
entry: leetcode/Scripts/python.exe tools/check_solutions.py
36+
language: system
37+
files: ^solutions/.*\.py$
38+
pass_filenames: false
39+
stages: [commit]
40+

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# ============================================
2+
# NeetCode Build System
3+
# ============================================
4+
# Usage:
5+
# make - Build site (same as CI/CD)
6+
# make serve - Build and serve locally
7+
# make clean - Clean generated files
8+
# make ai - Generate AI mindmaps
9+
# make help - Show all commands
10+
# ============================================
11+
12+
.PHONY: help build serve clean ai mindmaps html mkdocs test
13+
14+
# Default Python (adjust if needed)
15+
PYTHON := leetcode/Scripts/python.exe
16+
ifeq ($(OS),Windows_NT)
17+
PYTHON := leetcode/Scripts/python.exe
18+
else
19+
PYTHON := leetcode/bin/python
20+
endif
21+
22+
# Directories
23+
SITE_DIR := site
24+
MINDMAPS_MD := docs/mindmaps
25+
MINDMAPS_HTML := docs/pages/mindmaps
26+
27+
help:
28+
@echo ""
29+
@echo "NeetCode Build System"
30+
@echo "====================="
31+
@echo ""
32+
@echo "Usage: make [target]"
33+
@echo ""
34+
@echo "Targets:"
35+
@echo " build Build site (mirrors CI/CD pipeline)"
36+
@echo " serve Build and serve locally at http://127.0.0.1:8000"
37+
@echo " clean Remove generated files"
38+
@echo " ai Generate AI mindmaps (requires OPENAI_API_KEY)"
39+
@echo " test Run all tests"
40+
@echo " help Show this help"
41+
@echo ""
42+
43+
# Main build target (mirrors CI/CD)
44+
build: mindmaps html mkdocs copy-html
45+
@echo ""
46+
@echo "============================================"
47+
@echo " Build complete!"
48+
@echo "============================================"
49+
@echo " Output: $(SITE_DIR)/"
50+
@echo " Preview: make serve"
51+
@echo "============================================"
52+
53+
# Generate Markdown mindmaps
54+
mindmaps:
55+
@echo "[1/4] Generating Markdown mindmaps..."
56+
@$(PYTHON) tools/generate_mindmaps.py
57+
58+
# Generate HTML mindmaps
59+
html:
60+
@echo "[2/4] Generating HTML mindmaps..."
61+
@$(PYTHON) tools/generate_mindmaps.py --html
62+
63+
# Build MkDocs site
64+
mkdocs:
65+
@echo "[3/4] Building MkDocs site..."
66+
@$(PYTHON) -m mkdocs build
67+
68+
# Copy HTML to site directory
69+
copy-html:
70+
@echo "[4/4] Copying HTML mindmaps to site..."
71+
@mkdir -p $(SITE_DIR)/pages/mindmaps
72+
@cp -r $(MINDMAPS_HTML)/* $(SITE_DIR)/pages/mindmaps/ 2>/dev/null || true
73+
@if [ -d "docs/pages/assets" ]; then \
74+
mkdir -p $(SITE_DIR)/pages/assets; \
75+
cp -r docs/pages/assets/* $(SITE_DIR)/pages/assets/ 2>/dev/null || true; \
76+
fi
77+
78+
# Build and serve
79+
serve: build
80+
@echo ""
81+
@echo "[Serve] Starting local server..."
82+
@echo " http://127.0.0.1:8000"
83+
@echo " Press Ctrl+C to stop"
84+
@$(PYTHON) -m mkdocs serve
85+
86+
# Clean generated files
87+
clean:
88+
@echo "Cleaning build artifacts..."
89+
@rm -rf $(SITE_DIR)
90+
@echo "Cleaning generated mindmaps..."
91+
@find $(MINDMAPS_MD) -name "*.md" \
92+
! -name "index.md" \
93+
! -name "README.md" \
94+
! -name "*neetcode_ontology_ai*" \
95+
-delete 2>/dev/null || true
96+
@find $(MINDMAPS_HTML) -name "*.html" \
97+
! -name "*neetcode_ontology_ai*" \
98+
-delete 2>/dev/null || true
99+
@echo "Clean complete!"
100+
101+
# Generate AI mindmaps
102+
ai:
103+
@echo "Generating AI mindmaps..."
104+
@$(PYTHON) tools/generate_mindmaps_ai.py
105+
@echo "Rebuilding site..."
106+
@$(MAKE) build
107+
108+
# Run tests
109+
test:
110+
@echo "Running tests..."
111+
@$(PYTHON) -m pytest .dev/tests -q
112+

build.bat

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
@echo off
2+
REM ============================================
3+
REM Local Build Script (mirrors CI/CD pipeline)
4+
REM ============================================
5+
REM Usage:
6+
REM build.bat - Build only
7+
REM build.bat serve - Build and serve locally
8+
REM build.bat clean - Clean build artifacts
9+
REM build.bat ai - Generate AI mindmaps (requires OPENAI_API_KEY)
10+
REM ============================================
11+
12+
setlocal enabledelayedexpansion
13+
14+
REM Configuration
15+
set VENV_PATH=leetcode\Scripts\python.exe
16+
set SITE_DIR=site
17+
set MINDMAPS_MD=docs\mindmaps
18+
set MINDMAPS_HTML=docs\pages\mindmaps
19+
20+
REM Check if virtual environment exists
21+
if not exist "%VENV_PATH%" (
22+
echo [ERROR] Virtual environment not found at %VENV_PATH%
23+
echo Please run: py -3.11 -m venv leetcode
24+
exit /b 1
25+
)
26+
27+
REM Parse command
28+
set CMD=%1
29+
if "%CMD%"=="" set CMD=build
30+
31+
if "%CMD%"=="clean" goto :clean
32+
if "%CMD%"=="serve" goto :build_and_serve
33+
if "%CMD%"=="ai" goto :ai
34+
if "%CMD%"=="build" goto :build
35+
if "%CMD%"=="help" goto :help
36+
37+
echo [ERROR] Unknown command: %CMD%
38+
goto :help
39+
40+
:help
41+
echo.
42+
echo Usage: build.bat [command]
43+
echo.
44+
echo Commands:
45+
echo build - Generate mindmaps and build MkDocs site (default)
46+
echo serve - Build and serve locally at http://127.0.0.1:8000
47+
echo clean - Remove generated files
48+
echo ai - Generate AI mindmaps (requires OPENAI_API_KEY)
49+
echo help - Show this help message
50+
echo.
51+
exit /b 0
52+
53+
:clean
54+
echo.
55+
echo [1/3] Cleaning build artifacts...
56+
if exist "%SITE_DIR%" rmdir /s /q "%SITE_DIR%"
57+
echo Removed %SITE_DIR%/
58+
59+
echo [2/3] Cleaning generated mindmaps (keeping AI and manual files)...
60+
for %%f in (%MINDMAPS_MD%\*.md) do (
61+
set "filename=%%~nxf"
62+
if not "!filename!"=="index.md" (
63+
if not "!filename!"=="README.md" (
64+
echo !filename! | findstr /i "neetcode_ontology_ai" >nul
65+
if errorlevel 1 (
66+
del "%%f" 2>nul
67+
echo Removed %%f
68+
)
69+
)
70+
)
71+
)
72+
73+
echo [3/3] Cleaning generated HTML (keeping AI files)...
74+
for %%f in (%MINDMAPS_HTML%\*.html) do (
75+
set "filename=%%~nxf"
76+
echo !filename! | findstr /i "neetcode_ontology_ai" >nul
77+
if errorlevel 1 (
78+
del "%%f" 2>nul
79+
echo Removed %%f
80+
)
81+
)
82+
83+
echo.
84+
echo [OK] Clean complete!
85+
exit /b 0
86+
87+
:build
88+
echo.
89+
echo ============================================
90+
echo Local Build (mirrors CI/CD pipeline)
91+
echo ============================================
92+
echo.
93+
94+
echo [1/4] Generating Markdown mindmaps...
95+
%VENV_PATH% tools/generate_mindmaps.py
96+
if errorlevel 1 (
97+
echo [ERROR] Failed to generate Markdown mindmaps
98+
exit /b 1
99+
)
100+
echo Done!
101+
102+
echo [2/4] Generating HTML mindmaps...
103+
%VENV_PATH% tools/generate_mindmaps.py --html
104+
if errorlevel 1 (
105+
echo [ERROR] Failed to generate HTML mindmaps
106+
exit /b 1
107+
)
108+
echo Done!
109+
110+
echo [3/4] Building MkDocs site...
111+
%VENV_PATH% -m mkdocs build
112+
if errorlevel 1 (
113+
echo [ERROR] Failed to build MkDocs site
114+
exit /b 1
115+
)
116+
echo Done!
117+
118+
echo [4/4] Copying HTML mindmaps to site...
119+
if not exist "%SITE_DIR%\pages\mindmaps" mkdir "%SITE_DIR%\pages\mindmaps"
120+
xcopy /s /y /q "%MINDMAPS_HTML%\*" "%SITE_DIR%\pages\mindmaps\" >nul
121+
if exist "docs\pages\assets" (
122+
if not exist "%SITE_DIR%\pages\assets" mkdir "%SITE_DIR%\pages\assets"
123+
xcopy /s /y /q "docs\pages\assets\*" "%SITE_DIR%\pages\assets\" >nul
124+
)
125+
echo Done!
126+
127+
echo.
128+
echo ============================================
129+
echo Build complete!
130+
echo ============================================
131+
echo Output: %SITE_DIR%\
132+
echo Preview: build.bat serve
133+
echo ============================================
134+
exit /b 0
135+
136+
:build_and_serve
137+
call :build
138+
if errorlevel 1 exit /b 1
139+
140+
echo.
141+
echo [Serve] Starting local server...
142+
echo http://127.0.0.1:8000
143+
echo Press Ctrl+C to stop
144+
echo.
145+
%VENV_PATH% -m mkdocs serve
146+
exit /b 0
147+
148+
:ai
149+
echo.
150+
echo ============================================
151+
echo AI Mind Map Generation
152+
echo ============================================
153+
echo.
154+
155+
if "%OPENAI_API_KEY%"=="" (
156+
echo [ERROR] OPENAI_API_KEY environment variable not set
157+
echo.
158+
echo Please set it first:
159+
echo $env:OPENAI_API_KEY = "sk-..."
160+
echo.
161+
echo Or generate prompt only and copy to ChatGPT:
162+
echo The prompt will be saved to tools\prompts\generated\mindmap_prompt.md
163+
echo.
164+
)
165+
166+
echo [1/2] Generating AI mindmaps...
167+
%VENV_PATH% tools/generate_mindmaps_ai.py
168+
if errorlevel 1 (
169+
echo [WARNING] AI generation may have failed or was skipped
170+
echo Check tools\prompts\generated\mindmap_prompt.md for manual use
171+
)
172+
173+
echo [2/2] Rebuilding site with new AI mindmaps...
174+
call :build
175+
exit /b 0
176+

0 commit comments

Comments
 (0)