43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import os
|
|
import subprocess
|
|
import frappe
|
|
from .utils import create_module
|
|
|
|
def after_install():
|
|
create_module()
|
|
build_frontend()
|
|
|
|
def after_migrate():
|
|
build_frontend()
|
|
|
|
def build_frontend():
|
|
app_package_path = frappe.get_app_path("custom_ui")
|
|
app_root = os.path.dirname(app_package_path)
|
|
candidates = [
|
|
os.path.join(app_root, "frontend"),
|
|
os.path.join(app_package_path, "frontend")
|
|
]
|
|
|
|
frontend_path = None
|
|
for p in candidates:
|
|
if os.path.exists(p):
|
|
frontend_path = p
|
|
break
|
|
|
|
if not frontend_path:
|
|
frappe.log_error(message="No frontend directory found for custom_ui", title="Frontend Build Skipped")
|
|
print(f"⚠️ Frontend directory does not exist. Skipping build. Path was {frontend_path}")
|
|
return
|
|
|
|
dist_path = os.path.join(app_root, "custom_ui", "public", "dist")
|
|
should_build = True
|
|
|
|
if should_build:
|
|
print("\n📦 Building frontend for custom_ui...\n")
|
|
try:
|
|
subprocess.check_call(["npm", "install"], cwd=frontend_path)
|
|
subprocess.check_call(["npm", "run", "build"], cwd=frontend_path)
|
|
print("\n✅ Frontend build completed successfully.\n")
|
|
except subprocess.CalledProcessError as e:
|
|
frappe.log_error(message=str(e), title="Frontend Build Failed")
|
|
print(f"\n❌ Frontend build failed: {e}\n") |