You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Curriculum_Design/quick_build_macos.sh

106 lines
2.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# MagicWord macOS快速打包脚本
echo "=== MagicWord macOS打包脚本 ==="
echo "开始打包进程..."
# 检查Python版本
python_version=$(python3 --version 2>/dev/null || python --version)
echo "Python版本: $python_version"
# 安装依赖
echo "安装依赖..."
pip3 install -r requirements.txt
pip3 install pyinstaller
# 清理旧的构建文件
echo "清理旧的构建文件..."
rm -rf build dist __pycache__ *.spec
find src -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
# 构建应用
echo "构建macOS应用..."
python3 -m pyinstaller \\
--name "MagicWord" \\
--distpath "dist" \\
--workpath "build" \\
--add-data "resources:resources" \\
--hidden-import "PyQt5" \\
--hidden-import "PyQt5.QtCore" \\
--hidden-import "PyQt5.QtGui" \\
--hidden-import "PyQt5.QtWidgets" \\
--hidden-import "requests" \\
--hidden-import "beautifulsoup4" \\
--hidden-import "python-docx" \\
--hidden-import "PyPDF2" \\
--hidden-import "ebooklib" \\
--hidden-import "chardet" \\
--hidden-import "PIL" \\
--windowed \\
--osx-bundle-identifier "com.magicword.app" \\
--target-architecture arm64 \\
--noconfirm \\
src/main.py
# 检查构建结果
if [ -d "dist/MagicWord.app" ]; then
echo "✅ 构建成功!"
echo "应用位置: dist/MagicWord.app"
echo ""
echo "安装步骤:"
echo "1. 将 MagicWord.app 拖拽到 Applications 文件夹"
echo "2. 首次运行时,右键点击应用选择'打开'"
echo "3. 或者在 系统设置 > 隐私与安全性 中允许应用运行"
else
echo "❌ 构建失败!"
exit 1
fi
# 可选创建DMG
read -p "是否创建DMG安装包(y/n): " create_dmg
if [[ $create_dmg =~ ^[Yy]$ ]]; then
echo "创建DMG安装包..."
# 创建发布目录
release_dir="macos_release"
rm -rf "$release_dir"
mkdir -p "$release_dir"
# 复制应用
cp -r "dist/MagicWord.app" "$release_dir/"
# 创建Applications链接
ln -s "/Applications" "$release_dir/Applications"
# 创建README
cat > "$release_dir/README.txt" << 'EOF'
MagicWord for macOS
安装说明:
1. 将 MagicWord.app 拖拽到 Applications 文件夹
2. 首次运行时,右键点击应用选择"打开"
3. 或者在 系统设置 > 隐私与安全性 中允许应用运行
系统要求:
- macOS Big Sur (11.0) 或更高版本
- Apple Silicon (M1/M2/M3) 推荐
功能特性:
- 隐私学习:通过打字练习来学习文档内容
- 支持多种文档格式TXT, DOCX, PDF
- 智能打字模式
- 美观的Word风格界面
EOF
# 创建DMG
dmg_name="MagicWord-0.3.0-macOS-arm64.dmg"
hdiutil create -volname "MagicWord" -srcfolder "$release_dir" -ov -format UDZO "$dmg_name"
if [ -f "$dmg_name" ]; then
echo "✅ DMG创建成功: $dmg_name"
else
echo "⚠️ DMG创建失败但应用包已准备就绪"
fi
fi
echo "=== 打包完成 ==="