# Copyright 2021-2024 Avaiga Private Limited # # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. # -------------------------------------------------------------------------------------------------- # Builds the Taipy GUI or Taipy frontend bundle. # # Invoked from the workflows: # actions\install\action.yml # workflows\build-and-release.yml # workflows\build-and-release-single-package.yml # workflows\packaging.yml # workflows\partial-tests.yml # workflows\prebuild.yml # -------------------------------------------------------------------------------------------------- import platform import subprocess import sys from pathlib import Path with_shell = platform.system() == "Windows" def usage() -> None: print(f"Usage: {sys.argv[0]} []") # noqa: T201 print(" Builds the Taipy frontend bundles.") # noqa: T201 print(" If is 'gui', only the Taipy GUI bundle is built.") # noqa: T201 print(" If is 'taipy', only the Taipy bundle is built (expecting Taipy GUI's to exist).") # noqa: T201 print(" In all other cases, both bundles are built.") # noqa: T201 def build_gui(root_path: Path): print(f"Building taipy-gui frontend bundle in {root_path}.") # noqa: T201 already_exists = (root_path / "taipy" / "gui" / "webapp" / "index.html").exists() if already_exists: print(f'Found taipy-gui frontend bundle in {root_path / "taipy" / "gui" / "webapp"}.') # noqa: T201 else: subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui" / "dom", check=True, shell=with_shell) subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell) subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy-gui", check=True, shell=with_shell) def build_taipy(root_path: Path): print(f"Building taipy frontend bundle in {root_path}.") # noqa: T201 already_exists = (root_path / "taipy" / "gui_core" / "lib" / "taipy-gui-core.js").exists() if already_exists: print(f'Found taipy frontend bundle in {root_path / "taipy" / "gui_core" / "lib"}.') # noqa: T201 else: # Specify the correct path to taipy-gui in gui/.env file env_file_path = root_path / "frontend" / "taipy" / ".env" if not env_file_path.exists(): with open(env_file_path, "w") as env_file: env_file.write(f"TAIPY_DIR={root_path}\n") subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell) subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell) if __name__ == "__main__": root_path = Path(__file__).absolute().parent.parent.parent if len(sys.argv) > 1: if sys.argv[1] == "gui": build_gui(root_path) exit(0) elif sys.argv[1] == "taipy": build_taipy(root_path) exit(0) build_gui(root_path) build_taipy(root_path)