forked from yeongpin/cursor-free-vip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
113 lines (91 loc) · 3.29 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import warnings
import os
import platform
import subprocess
import time
import threading
import shutil
from logo import print_logo
from dotenv import load_dotenv
# 忽略特定警告
warnings.filterwarnings("ignore", category=SyntaxWarning)
class LoadingAnimation:
def __init__(self):
self.is_running = False
self.animation_thread = None
def start(self, message="Building"):
self.is_running = True
self.animation_thread = threading.Thread(target=self._animate, args=(message,))
self.animation_thread.start()
def stop(self):
self.is_running = False
if self.animation_thread:
self.animation_thread.join()
print("\r" + " " * 70 + "\r", end="", flush=True)
def _animate(self, message):
animation = "|/-\\"
idx = 0
while self.is_running:
print(f"\r{message} {animation[idx % len(animation)]}", end="", flush=True)
idx += 1
time.sleep(0.1)
def progress_bar(progress, total, prefix="", length=50):
filled = int(length * progress // total)
bar = "█" * filled + "░" * (length - filled)
percent = f"{100 * progress / total:.1f}"
print(f"\r{prefix} |{bar}| {percent}% Complete", end="", flush=True)
if progress == total:
print()
def simulate_progress(message, duration=1.0, steps=20):
print(f"\033[94m{message}\033[0m")
for i in range(steps + 1):
time.sleep(duration / steps)
progress_bar(i, steps, prefix="Progress:", length=40)
def build():
# 清理屏幕
os.system("cls" if platform.system().lower() == "windows" else "clear")
# 顯示 logo
print_logo()
# 清理 PyInstaller 緩存
print("\033[93m🧹 清理構建緩存...\033[0m")
if os.path.exists('build'):
shutil.rmtree('build')
# 重新加載環境變量以確保獲取最新版本
load_dotenv(override=True)
version = os.getenv('VERSION', '1.0.0')
print(f"\033[93m📦 正在構建版本: v{version}\033[0m")
try:
simulate_progress("Preparing build environment...", 0.5)
loading = LoadingAnimation()
loading.start("Building in progress")
# 根据系统类型设置输出名称
system = platform.system().lower()
if system == "windows":
os_type = "windows"
ext = ".exe"
elif system == "linux":
os_type = "linux"
ext = ""
else: # Darwin
os_type = "mac"
ext = ""
output_name = f"CursorFreeVIP_{version}_{os_type}"
# 构建命令
build_command = f'pyinstaller --clean --noconfirm build.spec'
output_path = os.path.join('dist', f'{output_name}{ext}')
os.system(build_command)
loading.stop()
if os.path.exists(output_path):
print(f"\n\033[92m✅ 構建完成!")
print(f"📦 可執行文件位於: {output_path}\033[0m")
else:
print("\n\033[91m❌ 構建失敗:未找到輸出文件\033[0m")
return False
except Exception as e:
if loading:
loading.stop()
print(f"\n\033[91m❌ 構建過程出錯: {str(e)}\033[0m")
return False
return True
if __name__ == "__main__":
build()