mirror of
https://github.com/Radiquum/YAMPD.git
synced 2025-05-19 23:29:34 +05:00
feat: add CLI build
This commit is contained in:
parent
5d6f654b69
commit
8baab91e60
4 changed files with 64 additions and 45 deletions
60
build.py
60
build.py
|
@ -19,8 +19,29 @@ parser.add_argument(
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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__":
|
if __name__ == "__main__":
|
||||||
|
@ -75,8 +96,9 @@ if __name__ == "__main__":
|
||||||
f"Copied requirements.txt: './requirements.txt' -> '{OUT_DIR}/requirements.txt'"
|
f"Copied requirements.txt: './requirements.txt' -> '{OUT_DIR}/requirements.txt'"
|
||||||
)
|
)
|
||||||
shutil.copyfile(f"./requirements.txt", f"{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(
|
build = subprocess.call(
|
||||||
[
|
[
|
||||||
"pyinstaller",
|
"pyinstaller",
|
||||||
|
@ -106,8 +128,34 @@ if __name__ == "__main__":
|
||||||
shutil.rmtree(f"{OUT_DIR}/dist")
|
shutil.rmtree(f"{OUT_DIR}/dist")
|
||||||
shutil.rmtree(f"{OUT_DIR}/build")
|
shutil.rmtree(f"{OUT_DIR}/build")
|
||||||
os.remove(f"{OUT_DIR}/main.spec")
|
os.remove(f"{OUT_DIR}/main.spec")
|
||||||
|
clearCache()
|
||||||
|
|
||||||
if os.path.exists(f"{OUT_DIR}/__pycache__") and os.path.isdir(
|
if args.exe and not args.no_cli:
|
||||||
f"{OUT_DIR}/__pycache__"
|
build = subprocess.call(
|
||||||
):
|
[
|
||||||
shutil.rmtree(f"{OUT_DIR}/__pycache__")
|
"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()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { MOD_ENDPOINT } from "@/api/ENDPOINTS";
|
import { MOD_ENDPOINT } from "@/api/ENDPOINTS";
|
||||||
import { Mod } from "@/types/mod";
|
import { Mod } from "@/types/mod";
|
||||||
import { Button } from "flowbite-react";
|
import { Button } from "flowbite-react";
|
||||||
import { useState } from "react";
|
// import { useState } from "react";
|
||||||
import { HiDownload, HiTrash } from "react-icons/hi";
|
import { HiDownload, HiTrash } from "react-icons/hi";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import {
|
import {
|
||||||
|
@ -17,10 +17,10 @@ export const ModTable = (props: {
|
||||||
packID: string;
|
packID: string;
|
||||||
downloadMods: (mods: string[]) => void;
|
downloadMods: (mods: string[]) => void;
|
||||||
}) => {
|
}) => {
|
||||||
function bytesToSize(bytes) {
|
function bytesToSize(bytes: number) {
|
||||||
var sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
||||||
if (bytes == 0) return "n/a";
|
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];
|
if (i == 0) return bytes + " " + sizes[i];
|
||||||
return (bytes / Math.pow(1024, i)).toFixed(1) + " " + 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}`}>
|
<AccordionPanel key={`mod-${mod.slug}`}>
|
||||||
<AccordionTitle>
|
<AccordionTitle>
|
||||||
<div className="flex gap-2 items-center text-2xl">
|
<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" />
|
<img alt="" src={mod.icon} className="w-8 h-8 rounded-lg" />
|
||||||
{mod.title} ({mod.slug})
|
{mod.title} ({mod.slug})
|
||||||
</div>
|
</div>
|
||||||
|
@ -141,6 +142,7 @@ export const ModTable = (props: {
|
||||||
className="bg-[#f3f4f6] dark:bg-[#1f2937] p-4 rounded-lg"
|
className="bg-[#f3f4f6] dark:bg-[#1f2937] p-4 rounded-lg"
|
||||||
>
|
>
|
||||||
<div className="flex gap-2 items-center text-xl">
|
<div className="flex gap-2 items-center text-xl">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img
|
<img
|
||||||
alt=""
|
alt=""
|
||||||
src={dep.icon}
|
src={dep.icon}
|
||||||
|
|
38
src/cli.py
38
src/cli.py
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
from sys import exit
|
||||||
|
|
||||||
os.environ["is_dev"] = "True"
|
# os.environ["is_dev"] = "True"
|
||||||
os.environ["is_cli"] = "True"
|
os.environ["is_cli"] = "True"
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -31,7 +32,7 @@ console = Console()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if os.environ["is_dev"]:
|
if os.getenv("is_dev"):
|
||||||
console.print("--- DEBUG MODE ---", style="bold red")
|
console.print("--- DEBUG MODE ---", style="bold red")
|
||||||
console.print("Provided arguments:", args)
|
console.print("Provided arguments:", args)
|
||||||
console.print(f"{'-':-<18}", style="bold red")
|
console.print(f"{'-':-<18}", style="bold red")
|
||||||
|
@ -57,36 +58,3 @@ if __name__ == "__main__":
|
||||||
if args.command == "pack" and args.subcommand is None:
|
if args.command == "pack" and args.subcommand is None:
|
||||||
pack_parser.print_help()
|
pack_parser.print_help()
|
||||||
exit(1)
|
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)
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
from sys import exit
|
||||||
|
|
||||||
from config import PACKS_FOLDER
|
from config import PACKS_FOLDER
|
||||||
from shared.packs import getPacks, createPack, deletePack
|
from shared.packs import getPacks, createPack, deletePack
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue