52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
|
|
|
|
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 ...")
|
|
pnpm_path = shutil.which("pnpm")
|
|
if pnpm_path is None:
|
|
raise Exception("pnpm command is not available. PLease install pnpm.")
|
|
|
|
subprocess.run(
|
|
[pnpm_path, "build"],
|
|
cwd=CURRENT_DIR / "frontend",
|
|
check=True,
|
|
)
|
|
|
|
print("Frontend build finished.")
|
|
shutil.rmtree(STATIC_OUTPUT_DIR, ignore_errors=True)
|
|
shutil.copytree(symlinks=True, src=DIST_DIR, dst=STATIC_OUTPUT_DIR)
|
|
|
|
return setup_kwargs
|
|
|
|
|
|
if __name__ == "__main__":
|
|
build({})
|