2025-07-23 16:01:45 +07:00
|
|
|
"""Main file to build the frontend."""
|
2025-07-22 20:01:22 +07:00
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
2025-07-22 20:20:47 +07:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def get_npm_command():
|
|
|
|
"""Get the appropriate npm command for the current OS."""
|
|
|
|
if sys.platform == "win32":
|
|
|
|
return "npm.cmd"
|
|
|
|
return "npm"
|
2025-07-22 20:01:22 +07:00
|
|
|
|
|
|
|
|
|
|
|
def build_frontend():
|
|
|
|
"""Build the frontend."""
|
|
|
|
frontend_dir = "cdrm-frontend"
|
2025-07-22 20:20:47 +07:00
|
|
|
npm_cmd = get_npm_command()
|
2025-07-22 20:01:22 +07:00
|
|
|
|
2025-07-22 20:20:47 +07:00
|
|
|
# Check and install dependencies if node_modules doesn't exist
|
2025-07-22 20:01:22 +07:00
|
|
|
if not os.path.exists(f"{frontend_dir}/node_modules"):
|
2025-07-22 20:20:47 +07:00
|
|
|
print("📦 Installing dependencies...")
|
|
|
|
subprocess.run([npm_cmd, "install"], cwd=frontend_dir, check=True)
|
2025-07-22 20:01:22 +07:00
|
|
|
|
2025-07-22 20:20:47 +07:00
|
|
|
# Always build the frontend to ensure it's up to date
|
|
|
|
print("🔨 Building frontend...")
|
|
|
|
subprocess.run([npm_cmd, "run", "build"], cwd=frontend_dir, check=True)
|
2025-07-22 20:01:22 +07:00
|
|
|
|
|
|
|
# Move dist to frontend-dist
|
|
|
|
if os.path.exists("frontend-dist"):
|
|
|
|
shutil.rmtree("frontend-dist")
|
|
|
|
shutil.copytree(f"{frontend_dir}/dist", "frontend-dist")
|
|
|
|
|
|
|
|
print("✅ Build complete. Run the application with 'python main.py'")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
build_frontend()
|