Fixed build.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2024-05-02 02:29:19 +02:00
parent c0b319e79d
commit 08c44219b0
4 changed files with 10 additions and 6 deletions

46
build.py Normal file
View File

@ -0,0 +1,46 @@
import os
from pathlib import Path
from shutil import copytree, rmtree
CURRENT_DIR = Path(__file__).parent
STATIC_OUTPUT_DIR = CURRENT_DIR / "anime/static"
FRONTEND_DIR = CURRENT_DIR / "frontend"
DIST_DIR = FRONTEND_DIR / "dist"
class DirChanger:
"""Class for changing current directory and returning back after exit."""
def __init__(self, path: Path):
self.path = path
def __enter__(self):
os.chdir(self.path)
def __exit__(self, *args):
os.chdir(CURRENT_DIR)
def build(setup_kwargs):
"""
Build frontend and copy it to the static directory.
This script is useful for packaging the application.
"""
print("Starting building frontend ...")
with DirChanger(CURRENT_DIR / "frontend"):
ret_status = os.system("pnpm build")
if ret_status != 0:
raise Exception("Frontend build failed.")
print("Frontend build finished.")
rmtree(STATIC_OUTPUT_DIR, ignore_errors=True)
copytree(symlinks=True, src=DIST_DIR, dst=STATIC_OUTPUT_DIR)
return setup_kwargs
if __name__ == "__main__":
build({})