import os
import shutil

with open(".version", "r") as version_file:
    version = version_file.read().strip()

print("Building the project...")
print("Cleaning build dir...")
# clear dist directory
if os.path.exists("dist"):
    shutil.rmtree("dist")
    os.makedirs("dist")
print("Build directory cleaned.")
build = input("Include console in  build? (y/n): ").strip().lower()


command = f"uv run python -m nuitka --standalone --output-dir=dist --include-data-dir=./config=config --include-data-dir=./site=site --include-data-dir=./icons=icons --include-data-dir=./mail_vorlagen=mail_vorlagen --enable-plugin=pyside6 --product-name=SemesterApparatsManager --product-version={version}  --output-filename=SAM.exe --windows-icon-from-ico=icons/logo.ico"
executable = "main.py"


if build == 'y':

    os.system(f"{command} {executable}")
else:
    command += " --windows-console-mode=disable"
    os.system(f"{command} {executable}")

# rename main.dist in dist dir to SemesterApparatsManager
os.rename("dist/main.dist", "dist/SemesterApparatsManager")

print("Build complete.")