bundle_build.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2023 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 subprocess
  12. import sys
  13. from pathlib import Path
  14. def build_gui(root_path: Path):
  15. print(f"Building taipy-gui frontend bundle in {root_path}.")
  16. already_exists = (root_path / "taipy" / "gui" / "webapp" / "index.html").exists()
  17. if already_exists:
  18. print(f'Found taipy-gui frontend bundle in {root_path / "taipy" / "gui" / "webapp"}.')
  19. else:
  20. subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui" / "dom", check=True, shell=True)
  21. subprocess.run(["npm", "ci", "--omit=optional"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=True)
  22. subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=True)
  23. def build_taipy(root_path: Path):
  24. print(f"Building taipy frontend bundle in {root_path}.")
  25. already_exists = (root_path / "taipy" / "gui_core" / "lib" / "taipy-gui-core.js").exists()
  26. if already_exists:
  27. print(f'Found taipy frontend bundle in {root_path / "taipy" / "gui_core" / "lib"}.')
  28. else:
  29. # Specify the correct path to taipy-gui in gui/.env file
  30. env_file_path = root_path / "frontend" / "taipy" / ".env"
  31. if not env_file_path.exists():
  32. with open(env_file_path, "w") as env_file:
  33. env_file.write(f"TAIPY_GUI_DIR={root_path}\n")
  34. subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=True)
  35. subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=True)
  36. if __name__ == "__main__":
  37. root_path = Path(__file__).absolute().parent.parent.parent
  38. if len(sys.argv) > 1:
  39. if sys.argv[1] == "gui":
  40. build_gui(root_path)
  41. elif sys.argv[1] == "taipy":
  42. build_taipy(root_path)
  43. else:
  44. build_gui(root_path)
  45. build_taipy(root_path)