-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuildfrontend.py
More file actions
65 lines (55 loc) · 1.68 KB
/
buildfrontend.py
File metadata and controls
65 lines (55 loc) · 1.68 KB
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
Import("env")
import os
import subprocess
import shutil
print("=" * 50)
print("Building frontend with Vite...")
print("=" * 50)
project_dir = env.get("PROJECT_DIR")
frontend_dir = os.path.join(project_dir, "frontend")
data_dir = os.path.join(project_dir, "data")
# Check if frontend directory exists
if not os.path.exists(frontend_dir):
print("Frontend directory not found, skipping build")
env.Exit(1)
# Install dependencies if needed
node_modules = os.path.join(frontend_dir, "node_modules")
if not os.path.exists(node_modules):
print("Installing dependencies...")
if os.name == 'nt':
subprocess.run(["npm.cmd", "install"], cwd=frontend_dir, check=True)
else:
subprocess.run(["npm", "install"], cwd=frontend_dir, check=True)
# Build with Vite (outputs directly to ../data)
print("Running Vite build...")
if os.name == 'nt':
result = subprocess.run(
["npm.cmd", "run", "build:all"],
cwd=frontend_dir,
capture_output=True,
text=True
)
else:
result = subprocess.run(
["npm", "run", "build:all"],
cwd=frontend_dir,
capture_output=True,
text=True
)
if result.returncode != 0:
print("Build failed:")
print(result.stderr)
env.Exit(1)
print(result.stdout)
# List built files
if os.path.exists(data_dir):
print("\nBuilt files:")
for root, dirs, files in os.walk(data_dir):
for file in files:
filepath = os.path.join(root, file)
size = os.path.getsize(filepath)
rel_path = os.path.relpath(filepath, data_dir)
print(f" {rel_path} ({size} bytes)")
print("=" * 50)
print("Frontend build complete!")
print("=" * 50)