diff --git a/build.py b/build.py index 1813132..c49ada6 100644 --- a/build.py +++ b/build.py @@ -19,8 +19,29 @@ parser.add_argument( default=False, ) parser.add_argument( - "--exe", help="create an executable file", action="store_true", default=False + "--exe", help="build an executable files", action="store_true", default=False ) +parser.add_argument( + "--no-gui", help="ignore the GUI build", action="store_true", default=False +) +parser.add_argument( + "--no-cli", help="ignore the CLI build", action="store_true", default=False +) + + +def clearCache(): + if os.path.exists(f"{OUT_DIR}/__pycache__"): + shutil.rmtree(f"{OUT_DIR}/__pycache__") + if os.path.exists(f"{OUT_DIR}/api/__pycache__"): + shutil.rmtree(f"{OUT_DIR}/api/__pycache__") + if os.path.exists(f"{OUT_DIR}/api/source/__pycache__"): + shutil.rmtree(f"{OUT_DIR}/api/source/__pycache__") + if os.path.exists(f"{OUT_DIR}/cli/__pycache__"): + shutil.rmtree(f"{OUT_DIR}/cli/__pycache__") + if os.path.exists(f"{OUT_DIR}/shared/__pycache__"): + shutil.rmtree(f"{OUT_DIR}/shared/__pycache__") + if os.path.exists(f"{OUT_DIR}/type/__pycache__"): + shutil.rmtree(f"{OUT_DIR}/type/__pycache__") if __name__ == "__main__": @@ -75,8 +96,9 @@ if __name__ == "__main__": f"Copied requirements.txt: './requirements.txt' -> '{OUT_DIR}/requirements.txt'" ) shutil.copyfile(f"./requirements.txt", f"{OUT_DIR}/requirements.txt") + clearCache() - if args.exe: + if args.exe and not args.no_gui: build = subprocess.call( [ "pyinstaller", @@ -106,8 +128,34 @@ if __name__ == "__main__": shutil.rmtree(f"{OUT_DIR}/dist") shutil.rmtree(f"{OUT_DIR}/build") os.remove(f"{OUT_DIR}/main.spec") + clearCache() - if os.path.exists(f"{OUT_DIR}/__pycache__") and os.path.isdir( - f"{OUT_DIR}/__pycache__" - ): - shutil.rmtree(f"{OUT_DIR}/__pycache__") + if args.exe and not args.no_cli: + build = subprocess.call( + [ + "pyinstaller", + "cli.py", + "-F", + "--add-data", + "mc_version.json:.", + ], + cwd="./dist", + shell=True, + ) + if build != 0: + print("[ERROR] pyinstaller has failed to build an app") + raise + + if os.path.exists(f"{OUT_DIR}/dist/cli.exe"): + shutil.move(f"{OUT_DIR}/dist/cli.exe", f"{OUT_DIR}/yamcpack-cli.exe") + elif os.path.exists(f"{OUT_DIR}/dist/cli"): + shutil.move(f"{OUT_DIR}/dist/cli", f"{OUT_DIR}/yamcpack-cli") + else: + print("[ERROR] no executable found") + raise + + print("cleanup...") + shutil.rmtree(f"{OUT_DIR}/dist") + shutil.rmtree(f"{OUT_DIR}/build") + os.remove(f"{OUT_DIR}/cli.spec") + clearCache() diff --git a/gui/app/components/ModTable.tsx b/gui/app/components/ModTable.tsx index 81f4376..23cb464 100644 --- a/gui/app/components/ModTable.tsx +++ b/gui/app/components/ModTable.tsx @@ -1,7 +1,7 @@ import { MOD_ENDPOINT } from "@/api/ENDPOINTS"; import { Mod } from "@/types/mod"; import { Button } from "flowbite-react"; -import { useState } from "react"; +// import { useState } from "react"; import { HiDownload, HiTrash } from "react-icons/hi"; import { toast } from "react-toastify"; import { @@ -17,10 +17,10 @@ export const ModTable = (props: { packID: string; downloadMods: (mods: string[]) => void; }) => { - function bytesToSize(bytes) { - var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; + function bytesToSize(bytes: number) { + const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; if (bytes == 0) return "n/a"; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + const i = Math.floor(Math.log(bytes) / Math.log(1024)); if (i == 0) return bytes + " " + sizes[i]; return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i]; } @@ -55,6 +55,7 @@ export const ModTable = (props: {
+ {/* eslint-disable-next-line @next/next/no-img-element */} {mod.title} ({mod.slug})
@@ -141,6 +142,7 @@ export const ModTable = (props: { className="bg-[#f3f4f6] dark:bg-[#1f2937] p-4 rounded-lg" >
+ {/* eslint-disable-next-line @next/next/no-img-element */}