bundle_build.py 2.7 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 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. # does not work in GH Action :-(
  21. # subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui" / "dom", check=True, shell=True)
  22. os.system(f'cd {root_path / "frontend" / "taipy-gui" / "dom"}; npm ci')
  23. # subprocess.run(
  24. # ["npm", "ci", "--omit=optional"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=True
  25. # )
  26. # subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=True)
  27. os.system(f'cd {root_path / "frontend" / "taipy-gui"}; npm ci --omit=optional && npm run build')
  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=True)
  40. # subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=True)
  41. os.system(f'cd {root_path / "frontend" / "taipy"}; npm ci && npm run build')
  42. if __name__ == "__main__":
  43. root_path = Path(__file__).absolute().parent.parent.parent
  44. if len(sys.argv) > 1:
  45. if sys.argv[1] == "gui":
  46. build_gui(root_path)
  47. elif sys.argv[1] == "taipy":
  48. build_taipy(root_path)
  49. else:
  50. build_gui(root_path)
  51. build_taipy(root_path)