From 9cf32caea36a0d0c819700b22814227b3f7ca747 Mon Sep 17 00:00:00 2001 From: Radiquum Date: Sun, 4 May 2025 06:16:06 +0500 Subject: [PATCH] feat: add build script --- build.py | 30 ++++++++++++++++++++++++++++++ src/main.py | 2 -- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 build.py diff --git a/build.py b/build.py new file mode 100644 index 0000000..4e0fdde --- /dev/null +++ b/build.py @@ -0,0 +1,30 @@ +import subprocess +import os +import shutil + +OUT_DIR = "./dist" + +if __name__ == "__main__": + + if os.path.exists(OUT_DIR) and os.path.isdir(OUT_DIR): + shutil.rmtree(OUT_DIR) + + os.makedirs(OUT_DIR) + + subprocess.call(["bun", "run", "build"], cwd="./gui", shell=True) + files = [f.name for f in os.scandir("./gui/out") if f.is_file()] + dirs = [f.name for f in os.scandir("./gui/out") if f.is_dir()] + + os.makedirs(f"{OUT_DIR}/static") + os.makedirs(f"{OUT_DIR}/templates") + + for file in files: + if file.endswith(".html"): + shutil.copyfile(f"./gui/out/{file}", f"{OUT_DIR}/templates/{file}") + continue + shutil.copyfile(f"./gui/out/{file}", f"{OUT_DIR}/static/{file}") + + for dir in dirs: + shutil.copytree(f"./gui/out/{dir}", f"{OUT_DIR}/static/{dir}", dirs_exist_ok=True) + + shutil.copytree("./src", f"{OUT_DIR}/", dirs_exist_ok=True) \ No newline at end of file diff --git a/src/main.py b/src/main.py index 36ed039..69115b8 100644 --- a/src/main.py +++ b/src/main.py @@ -6,13 +6,11 @@ import os app = Flask(__name__) -# TODO: auto copy next html files to templates folder @app.route("/") def index(): return render_template("index.html") -# TODO: auto copy next static out on build to static folder @app.route("/") def rewrite_next(path): if os.path.exists(f"./static/{path}"):