Skip to content

Commit fd062c5

Browse files
feat: Add frontend build process and static file serving for visual controller
1 parent eafa8ef commit fd062c5

File tree

5 files changed

+107
-743
lines changed

5 files changed

+107
-743
lines changed

.github/workflows/deploy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ jobs:
4141
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
4242
aws-region: ${{ env.AWS_REGION }}
4343

44+
- name: Build visual controller frontend
45+
if: ${{ matrix.service == 'visual-controller' }}
46+
shell: bash
47+
run: |
48+
python scripts/build_frontend.py
49+
4450
- name: Compute package suffix
4551
id: suffix
4652
shell: bash

package.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ print(f"Created {zip_name}")
2727
"@
2828

2929
foreach ($service in $services) {
30+
if ($service.Name -eq 'visual_controller') {
31+
$buildScript = Join-Path $PSScriptRoot 'scripts\build_frontend.py'
32+
if (Test-Path $buildScript) {
33+
Write-Host "Building frontend bundle" -ForegroundColor Cyan
34+
python $buildScript
35+
if ($LASTEXITCODE -ne 0) {
36+
Write-Host "Frontend build failed." -ForegroundColor Red
37+
break
38+
}
39+
} else {
40+
Write-Host "Frontend build script not found at $buildScript" -ForegroundColor Yellow
41+
}
42+
}
43+
3044
$output = $service.Output
3145
$path = $service.Path
3246
if (!(Test-Path $path)) {

scripts/build_frontend.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Build the React frontend and copy the output into the FastAPI static directory.
4+
5+
Usage:
6+
python scripts/build_frontend.py
7+
"""
8+
9+
from __future__ import annotations
10+
11+
import shutil
12+
import subprocess
13+
from pathlib import Path
14+
from typing import Sequence
15+
16+
REPO_ROOT = Path(__file__).resolve().parent.parent
17+
FRONTEND_DIR = REPO_ROOT / "visual_controller" / "frontend"
18+
STATIC_DIR = REPO_ROOT / "visual_controller" / "static"
19+
20+
21+
def run(command: Sequence[str], *, cwd: Path) -> None:
22+
print(f"[build_frontend] Running {' '.join(command)} (cwd={cwd})")
23+
subprocess.run(command, check=True, cwd=cwd)
24+
25+
26+
def main() -> None:
27+
if not FRONTEND_DIR.exists():
28+
raise SystemExit(f"Frontend directory not found: {FRONTEND_DIR}")
29+
30+
run(["npm", "install"], cwd=FRONTEND_DIR)
31+
run(["npm", "run", "build"], cwd=FRONTEND_DIR)
32+
33+
dist_dir = FRONTEND_DIR / "dist"
34+
if not dist_dir.exists():
35+
raise SystemExit("Build output not found (expected dist/ directory).")
36+
37+
if STATIC_DIR.exists():
38+
print(f"[build_frontend] Removing existing static directory: {STATIC_DIR}")
39+
shutil.rmtree(STATIC_DIR)
40+
41+
print(f"[build_frontend] Copying {dist_dir} -> {STATIC_DIR}")
42+
shutil.copytree(dist_dir, STATIC_DIR)
43+
print("[build_frontend] Done.")
44+
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)