bundle_build.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright 2021-2025 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import platform
  12. import subprocess
  13. import sys
  14. from pathlib import Path
  15. with_shell = platform.system() == "Windows"
  16. def build_gui(root_path: Path):
  17. print(f"Building taipy-gui frontend bundle in {root_path}.") # noqa: T201
  18. already_exists = (root_path / "taipy" / "gui" / "webapp" / "index.html").exists()
  19. if already_exists:
  20. print(f'Found taipy-gui frontend bundle in {root_path / "taipy" / "gui" / "webapp"}.') # noqa: T201
  21. else:
  22. subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui" / "dom", check=True, shell=with_shell)
  23. subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell)
  24. subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell)
  25. def build_taipy(root_path: Path):
  26. print(f"Building taipy frontend bundle in {root_path}.") # noqa: T201
  27. already_exists = (root_path / "taipy" / "gui_core" / "lib" / "taipy-gui-core.js").exists()
  28. if already_exists:
  29. print(f'Found taipy frontend bundle in {root_path / "taipy" / "gui_core" / "lib"}.') # noqa: T201
  30. else:
  31. # Specify the correct path to taipy-gui in gui/.env file
  32. env_file_path = root_path / "frontend" / "taipy" / ".env"
  33. if not env_file_path.exists():
  34. with open(env_file_path, "w") as env_file:
  35. env_file.write(f"TAIPY_DIR={root_path}\n")
  36. subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
  37. subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
  38. if __name__ == "__main__":
  39. root_path = Path(__file__).absolute().parent.parent.parent
  40. if len(sys.argv) > 1:
  41. if sys.argv[1] == "gui":
  42. build_gui(root_path)
  43. elif sys.argv[1] == "taipy":
  44. build_taipy(root_path)
  45. else:
  46. build_gui(root_path)
  47. build_taipy(root_path)