AcuarelaPortraits / setup_frontend.py
Alexramsal's picture
feat: add setup_frontend script to copy pre-built frontend files to daggr installation
8f39e99
#!/usr/bin/env python3
"""
Setup script to prepare the environment before running the app.
This copies pre-built frontend files to the daggr installation.
"""
import os
import sys
import shutil
from pathlib import Path
def setup_frontend():
"""Copy pre-built frontend to daggr installation."""
print("[*] Setting up frontend...")
# The pre-built frontend should be here (in the mounted app directory)
source_dist = Path.cwd() / "AcuarelaPortraits" / "daggr" / "frontend" / "dist"
# But also check if we're running from root directly
if not source_dist.exists():
source_dist = Path.cwd() / "daggr" / "frontend" / "dist"
if not source_dist.exists():
print(f"[WARNING] Frontend source not found at {source_dist}")
return False
# Find daggr installation
try:
import importlib.util
spec = importlib.util.find_spec("daggr")
if not spec or not spec.origin:
print("[ERROR] Could not locate daggr installation")
return False
daggr_root = Path(spec.origin).parent
target_dist = daggr_root / "frontend" / "dist"
print(f"[*] Source: {source_dist}")
print(f"[*] Target: {target_dist}")
# Ensure target frontend directory exists
(daggr_root / "frontend").mkdir(parents=True, exist_ok=True)
# Remove existing dist
if target_dist.exists():
print(f"[*] Removing existing dist...")
shutil.rmtree(target_dist, ignore_errors=True)
# Copy new dist
print(f"[*] Copying frontend...")
shutil.copytree(source_dist, target_dist)
# Verify
if (target_dist / "index.html").exists():
print(f"[OK] Frontend setup successful!")
return True
else:
print(f"[ERROR] Frontend files not copied correctly")
return False
except Exception as e:
print(f"[ERROR] Setup failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
success = setup_frontend()
sys.exit(0 if success else 1)