bundle_build.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import sys
  3. from pathlib import Path
  4. def build_gui(root_path):
  5. print(f"Building taipy-gui frontend bundle in {root_path}.")
  6. already_exists = (root_path / "taipy" / "gui" / "webapp" / "index.html").exists()
  7. if already_exists:
  8. print(f'Found taipy-gui frontend bundle in {root_path / "taipy" / "gui" / "webapp"}.')
  9. else:
  10. os.system("cd frontend/taipy-gui/dom && npm ci")
  11. os.system("cd frontend/taipy-gui && npm ci --omit=optional && npm run build")
  12. def build_taipy(root_path):
  13. print(f"Building taipy frontend bundle in {root_path}.")
  14. already_exists = (root_path / "taipy" / "gui_core" / "lib" / "taipy-gui-core.js").exists()
  15. if already_exists:
  16. print(f'Found taipy frontend bundle in {root_path / "taipy" / "gui_core" / "lib"}.')
  17. else:
  18. # Specify the correct path to taipy-gui in gui/.env file
  19. env_file_path = root_path / "frontend" / "taipy" / ".env"
  20. if not os.path.exists(env_file_path):
  21. with open(env_file_path, "w") as env_file:
  22. env_file.write(f"TAIPY_GUI_DIR={root_path}\n")
  23. os.system("cd frontend/taipy && npm ci && npm run build")
  24. if __name__ == "__main__":
  25. root_path = Path(__file__).absolute().parent.parent.parent
  26. if len(sys.argv) > 1:
  27. if sys.argv[1] == "gui":
  28. build_gui(root_path)
  29. elif sys.argv[1] == "taipy":
  30. build_taipy(root_path)
  31. else:
  32. build_gui(root_path)
  33. build_taipy(root_path)