TorqueWrench/backend/build_backend.sh

65 lines
1.8 KiB
Bash
Raw Blame History

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
# 电动扳手后端 API 打包脚本Linux/Mac
echo "========================================"
echo "电动扳手后端 API 打包脚本"
echo "========================================"
echo ""
# 确保在 backend 目录下执行
cd "$(dirname "$0")"
# 检查 PyInstaller 是否已安装
if ! python3 -c "import PyInstaller" 2>/dev/null; then
echo "[错误] PyInstaller 未安装"
echo "正在安装 PyInstaller..."
pip3 install pyinstaller
if [ $? -ne 0 ]; then
echo "[错误] PyInstaller 安装失败,请手动执行: pip3 install pyinstaller"
exit 1
fi
fi
echo "[信息] PyInstaller 已安装"
echo ""
# 清理之前的构建文件
echo "[信息] 清理之前的构建文件..."
rm -rf build dist
echo ""
echo "[信息] 当前目录: $(pwd)"
echo "[信息] 开始打包后端 API 服务..."
echo ""
# 使用 onedir 模式打包,并显式包含父目录中的 wrench_controller 模块
# --paths .. 把项目根目录加入模块搜索路径
# --hidden-import ... 确保 wrench_controller 被打包进可执行文件
pyinstaller --name backend_api --console --paths .. --hidden-import wrench_controller app.py
if [ $? -ne 0 ]; then
echo ""
echo "[错误] 打包失败!"
exit 1
fi
echo ""
echo "========================================"
echo "后端打包完成!"
echo "========================================"
echo ""
echo "可执行文件位置: dist/backend_api/backend_api"
echo ""
echo "下一步操作:"
echo "1. 如果已有生产用数据库,可将当前目录的 wrench.db 复制到 dist/backend_api/ 目录:"
echo " cp wrench.db dist/backend_api/wrench.db"
echo ""
echo "2. 运行后端服务:"
echo " ./dist/backend_api/backend_api"
echo ""
echo "3. 确保前端或第三方程序访问的地址仍为:"
echo " http://localhost:5000"
echo ""