mirror of
https://github.com/Radiquum/YAMPD.git
synced 2025-05-19 23:29:34 +05:00
feat: add one-file build
This commit is contained in:
parent
7f704ec75a
commit
3ef10c07cf
5 changed files with 71 additions and 11 deletions
49
build.py
49
build.py
|
@ -12,7 +12,12 @@ parser = argparse.ArgumentParser(
|
||||||
description="Create and Download mod packs with ease",
|
description="Create and Download mod packs with ease",
|
||||||
epilog="",
|
epilog="",
|
||||||
)
|
)
|
||||||
parser.add_argument("--no-rebuild", help="don't rebuild Next.js gui", action="store_true", default=False)
|
parser.add_argument(
|
||||||
|
"--no-rebuild", help="don't rebuild Next.js frontend", action="store_true", default=False
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--exe", help="create an executable file", action="store_true", default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -63,5 +68,43 @@ if __name__ == "__main__":
|
||||||
print(f"Copied app: './src' -> '{OUT_DIR}'")
|
print(f"Copied app: './src' -> '{OUT_DIR}'")
|
||||||
shutil.copytree("./src", f"{OUT_DIR}/", dirs_exist_ok=True)
|
shutil.copytree("./src", f"{OUT_DIR}/", dirs_exist_ok=True)
|
||||||
|
|
||||||
if os.path.exists(f"{OUT_DIR}/__pycache__") and os.path.isdir(f"{OUT_DIR}/__pycache__"):
|
print(
|
||||||
shutil.rmtree(f"{OUT_DIR}/__pycache__")
|
f"Copied requirements.txt: './requirements.txt' -> '{OUT_DIR}/requirements.txt'"
|
||||||
|
)
|
||||||
|
shutil.copyfile(f"./requirements.txt", f"{OUT_DIR}/requirements.txt")
|
||||||
|
|
||||||
|
if args.exe:
|
||||||
|
build = subprocess.call(
|
||||||
|
[
|
||||||
|
"pyinstaller",
|
||||||
|
"main.py",
|
||||||
|
"-F",
|
||||||
|
"--add-data",
|
||||||
|
"static:static",
|
||||||
|
"--add-data",
|
||||||
|
"templates:templates",
|
||||||
|
],
|
||||||
|
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/main.exe"):
|
||||||
|
shutil.move(f"{OUT_DIR}/dist/main.exe", f"{OUT_DIR}/yamcpack.exe")
|
||||||
|
elif os.path.exists(f"{OUT_DIR}/dist/main"):
|
||||||
|
shutil.move(f"{OUT_DIR}/dist/main", f"{OUT_DIR}/yamcpack")
|
||||||
|
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}/main.spec")
|
||||||
|
|
||||||
|
if os.path.exists(f"{OUT_DIR}/__pycache__") and os.path.isdir(
|
||||||
|
f"{OUT_DIR}/__pycache__"
|
||||||
|
):
|
||||||
|
shutil.rmtree(f"{OUT_DIR}/__pycache__")
|
1
requirements.build.txt
Normal file
1
requirements.build.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pyinstaller
|
1
requirements.dev.txt
Normal file
1
requirements.dev.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
flask-cors
|
|
@ -3,4 +3,3 @@ flaskwebgui
|
||||||
requests
|
requests
|
||||||
Pillow
|
Pillow
|
||||||
flask-socketio
|
flask-socketio
|
||||||
flask-cors
|
|
30
src/main.py
30
src/main.py
|
@ -1,14 +1,30 @@
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import render_template, redirect, url_for, send_file, abort
|
from flask import render_template, send_file, abort
|
||||||
from flaskwebgui import FlaskUI # import FlaskUI
|
from flaskwebgui import FlaskUI # import FlaskUI
|
||||||
import os
|
import os
|
||||||
from flask_cors import CORS
|
import sys
|
||||||
|
|
||||||
|
|
||||||
from api import api
|
from api import api
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
def resource_path(relative_path):
|
||||||
|
if hasattr(sys, "_MEIPASS"):
|
||||||
|
return os.path.join(sys._MEIPASS, relative_path)
|
||||||
|
return os.path.join(os.path.abspath("."), relative_path)
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(
|
||||||
|
__name__,
|
||||||
|
static_folder=resource_path("static"),
|
||||||
|
template_folder=resource_path("templates"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
app.register_blueprint(api)
|
app.register_blueprint(api)
|
||||||
CORS(app, resources={r"/*": {"origins": "*"}})
|
if os.getenv("is_dev") == "True":
|
||||||
|
from flask_cors import CORS
|
||||||
|
CORS(app, resources={r"/*": {"origins": "*"}})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
@ -18,9 +34,9 @@ def index():
|
||||||
|
|
||||||
@app.route("/<path:path>")
|
@app.route("/<path:path>")
|
||||||
def rewrite_next(path):
|
def rewrite_next(path):
|
||||||
if os.path.exists(f"./static/{path}"):
|
if os.path.exists(f"{resource_path("static")}/{path}"):
|
||||||
return send_file(f"./static/{path}")
|
return send_file(f"{resource_path("static")}/{path}")
|
||||||
if os.path.exists(f"./templates/{path}.html"):
|
if os.path.exists(f"{resource_path("templates")}/{path}.html"):
|
||||||
return render_template(f"{path}.html")
|
return render_template(f"{path}.html")
|
||||||
return abort(404)
|
return abort(404)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue