Merge branch 'leonvanzyl:master' into master

This commit is contained in:
mmereu
2026-01-19 22:03:29 +01:00
committed by GitHub
28 changed files with 1994 additions and 541 deletions

View File

@@ -146,13 +146,90 @@ def install_npm_deps() -> bool:
def build_frontend() -> bool:
"""Build the React frontend if dist doesn't exist."""
dist_dir = UI_DIR / "dist"
"""Build the React frontend if dist doesn't exist or is stale.
if dist_dir.exists():
print(" Frontend already built")
Staleness is determined by comparing modification times of:
- Source files in ui/src/
- Config files (package.json, vite.config.ts, etc.)
Against the newest file in ui/dist/
Includes a 2-second tolerance for FAT32 filesystem compatibility.
"""
dist_dir = UI_DIR / "dist"
src_dir = UI_DIR / "src"
# FAT32 has 2-second timestamp precision, so we add tolerance to avoid
# false negatives when projects are on USB drives or SD cards
TIMESTAMP_TOLERANCE = 2
# Config files that should trigger a rebuild when changed
CONFIG_FILES = [
"package.json",
"package-lock.json",
"vite.config.ts",
"tailwind.config.ts",
"tsconfig.json",
"tsconfig.node.json",
"postcss.config.js",
"index.html",
]
# Check if build is needed
needs_build = False
trigger_file = None
if not dist_dir.exists():
needs_build = True
trigger_file = "dist/ directory missing"
elif src_dir.exists():
# Find the newest file in dist/ directory
newest_dist_mtime = 0
for dist_file in dist_dir.rglob("*"):
try:
if dist_file.is_file():
file_mtime = dist_file.stat().st_mtime
if file_mtime > newest_dist_mtime:
newest_dist_mtime = file_mtime
except (FileNotFoundError, PermissionError, OSError):
# File was deleted or became inaccessible during iteration
continue
if newest_dist_mtime > 0:
# Check config files first (these always require rebuild)
for config_name in CONFIG_FILES:
config_path = UI_DIR / config_name
try:
if config_path.exists():
if config_path.stat().st_mtime > newest_dist_mtime + TIMESTAMP_TOLERANCE:
needs_build = True
trigger_file = config_name
break
except (FileNotFoundError, PermissionError, OSError):
continue
# Check source files if no config triggered rebuild
if not needs_build:
for src_file in src_dir.rglob("*"):
try:
if src_file.is_file():
if src_file.stat().st_mtime > newest_dist_mtime + TIMESTAMP_TOLERANCE:
needs_build = True
trigger_file = str(src_file.relative_to(UI_DIR))
break
except (FileNotFoundError, PermissionError, OSError):
# File was deleted or became inaccessible during iteration
continue
else:
# No files found in dist, need to rebuild
needs_build = True
trigger_file = "dist/ directory is empty"
if not needs_build:
print(" Frontend already built (up to date)")
return True
if trigger_file:
print(f" Rebuild triggered by: {trigger_file}")
print(" Building React frontend...")
npm_cmd = "npm.cmd" if sys.platform == "win32" else "npm"
return run_command([npm_cmd, "run", "build"], cwd=UI_DIR)