forked from Lafcadia/NitWiki-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-bundle.py
More file actions
71 lines (60 loc) · 2.45 KB
/
generate-bundle.py
File metadata and controls
71 lines (60 loc) · 2.45 KB
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
import os
import shutil
import subprocess
import platform
import tempfile
from concurrent.futures import ThreadPoolExecutor
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
os.system("python3 -m pip install pyyaml tqdm psutil requests imageio rtoml elevate colorama nuitka ordered-set")
# 准备输出目录
if os.path.exists("dist"):
shutil.rmtree("dist")
os.makedirs("dist", exist_ok=True)
def build(file):
try:
file_path = os.path.join("src", file)
base_name = os.path.splitext(file)[0]
print(f"🏗️ 开始构建 {file}", flush=True)
# 创建临时构建目录
with tempfile.TemporaryDirectory(prefix=f"build_{base_name}_") as temp_dir:
# 构建命令参数
args = [
"python", "-m", "nuitka",
"--onefile",
file_path,
"--assume-yes-for-downloads",
f"--output-dir={temp_dir}",
]
# 平台特定参数
if platform.system() == 'Windows':
args += [
"--windows-icon-from-ico=favicon.png"
]
elif platform.system() == 'Darwin': # 修正MacOS判断
args.append("--macos-app-icon=favicon.png")
elif platform.system() == 'Linux':
args.append("--linux-icon=favicon.png")
# 执行构建命令
subprocess.run(args, check=True)
# 移动生成文件到dist目录
for item in os.listdir(temp_dir):
src = os.path.join(temp_dir, item)
if item.startswith(base_name) and os.path.isfile(src):
dest = os.path.join("dist", item)
shutil.move(src, dest)
print(f"✅ 已移动 {item} 到 dist 目录", flush=True)
print(f"🎉 成功构建 {file}", flush=True)
except Exception as e:
print(f"❌ 构建 {file} 失败: {str(e)}", flush=True)
if __name__ == "__main__":
# 获取需要构建的文件列表
src_files = [
f for f in os.listdir("src")
if f != "utils.py" and os.path.isfile(os.path.join("src", f))
]
with ThreadPoolExecutor(max_workers=os.cpu_count() if platform.system() != 'Windows' else 1) as executor:
executor.map(build, src_files)
print("\n所有构建任务已完成,输出目录: dist/")