feat: add CLI build

This commit is contained in:
Kentai Radiquum 2025-05-16 15:04:09 +05:00
parent 5d6f654b69
commit 8baab91e60
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
4 changed files with 64 additions and 45 deletions

View file

@ -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()

View file

@ -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: {
<AccordionPanel key={`mod-${mod.slug}`}>
<AccordionTitle>
<div className="flex gap-2 items-center text-2xl">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img alt="" src={mod.icon} className="w-8 h-8 rounded-lg" />
{mod.title} ({mod.slug})
</div>
@ -141,6 +142,7 @@ export const ModTable = (props: {
className="bg-[#f3f4f6] dark:bg-[#1f2937] p-4 rounded-lg"
>
<div className="flex gap-2 items-center text-xl">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
alt=""
src={dep.icon}

View file

@ -1,6 +1,7 @@
import os
from sys import exit
os.environ["is_dev"] = "True"
# os.environ["is_dev"] = "True"
os.environ["is_cli"] = "True"
import argparse
@ -31,7 +32,7 @@ console = Console()
if __name__ == "__main__":
args = parser.parse_args()
if os.environ["is_dev"]:
if os.getenv("is_dev"):
console.print("--- DEBUG MODE ---", style="bold red")
console.print("Provided arguments:", args)
console.print(f"{'-':-<18}", style="bold red")
@ -57,36 +58,3 @@ if __name__ == "__main__":
if args.command == "pack" and args.subcommand is None:
pack_parser.print_help()
exit(1)
# if args.command == "packs":
# if args.packs_command == "new":
# title = input("Pack title: ")
# author = input("Pack author: ")
# game_version = input("Game version: ")
# mod_loader = input("Mod loader (fabric, forge, neoforge, quilt): ")
# if title == "" or author == "" or game_version == "" or mod_loader == "":
# print("some parameters weren't provided")
# exit(1)
# if len(game_version.split(".")) == 1:
# print("wrong version format. should be int.int or int.int.int")
# exit(1)
# if mod_loader.lower() not in ["fabric", "forge", "neoforge", "quilt"]:
# print("wrong mod loader is provided")
# exit(1)
# pack, is_exists = createPack(title, author, game_version, mod_loader)
# if is_exists:
# print(f"Pack {pack.title} already exists")
# else:
# print(f"Pack {pack.title} was created")
# elif args.packs_command == "delete":
# deletePack
# print("Del Pack")
# else:
# packs_parser.print_help()
# print("---------------")
# print(args)

View file

@ -1,6 +1,7 @@
import os
import sys
import json
from sys import exit
from config import PACKS_FOLDER
from shared.packs import getPacks, createPack, deletePack