bundle_build.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 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(
  24. ["npm", "ci", "--omit=optional"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell
  25. )
  26. subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell)
  27. def build_taipy(root_path: Path):
  28. print(f"Building taipy frontend bundle in {root_path}.") # noqa: T201
  29. already_exists = (root_path / "taipy" / "gui_core" / "lib" / "taipy-gui-core.js").exists()
  30. if already_exists:
  31. print(f'Found taipy frontend bundle in {root_path / "taipy" / "gui_core" / "lib"}.') # noqa: T201
  32. else:
  33. # Specify the correct path to taipy-gui in gui/.env file
  34. env_file_path = root_path / "frontend" / "taipy" / ".env"
  35. if not env_file_path.exists():
  36. with open(env_file_path, "w") as env_file:
  37. env_file.write(f"TAIPY_DIR={root_path}\n")
  38. subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
  39. subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
  40. if __name__ == "__main__":
  41. root_path = Path(__file__).absolute().parent.parent.parent
  42. if len(sys.argv) > 1:
  43. if sys.argv[1] == "gui":
  44. build_gui(root_path)
  45. elif sys.argv[1] == "taipy":
  46. build_taipy(root_path)
  47. else:
  48. build_gui(root_path)
  49. build_taipy(root_path)