bundle_build.py 2.5 KB

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