fundplatform/scripts/build-frontend.sh
zhangjf 8190887de8 feat: 数据库脚本优化、前端部署脚本、租户ID支持
- 数据库脚本优化
  - 新增01_create_user.sql创建fundsp用户
  - 新增02_grant_user.sql授权脚本
  - 新增fund_exp_init.sql、fund_receipt_init.sql
  - 修复SQL脚本与实体类一致性
  - 密码更新为fundSP@123

- 前端部署脚本
  - 新增build-frontend.sh前端构建脚本
  - 新增deploy-frontend-nginx.sh Nginx部署脚本
  - 打包输出到deploy目录

- 租户ID支持
  - fund-admin/fund-mobile支持query参数读取tid
  - 新增tenant.ts store管理租户状态
  - 请求拦截器添加X-Tenant-Id header

- 启动脚本修复
  - 修复INSTANCE_NAME变量替换问题
  - 更新所有service.properties配置

- 配置更新
  - 更新所有服务数据库密码
  - 更新docker-compose.yml配置
2026-02-22 19:45:52 +08:00

188 lines
4.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ============================================
# 前端编译发布脚本
# 用法: ./build-frontend.sh [项目名]
# 示例:
# ./build-frontend.sh # 打包所有前端项目
# ./build-frontend.sh admin # 只打包fund-admin
# ./build-frontend.sh mobile # 只打包fund-mobile
# ============================================
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 项目根目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
DEPLOY_DIR="${PROJECT_ROOT}/deploy"
# 前端项目配置
declare -A FRONTEND_PROJECTS=(
["admin"]="fund-admin"
["mobile"]="fund-mobile"
)
# 创建deploy目录
mkdir -p "${DEPLOY_DIR}"
# 打印帮助信息
print_help() {
echo "用法: $0 [项目名]"
echo ""
echo "可用项目:"
echo " admin - 管理后台 (fund-admin)"
echo " mobile - 移动端 (fund-mobile)"
echo " all - 打包所有前端项目 (默认)"
echo ""
echo "示例:"
echo " $0 # 打包所有前端项目"
echo " $0 admin # 只打包管理后台"
echo " $0 mobile # 只打包移动端"
}
# 检查Node.js环境
check_node() {
if ! command -v node &> /dev/null; then
echo -e "${RED}错误: 未安装Node.js请先安装Node.js${NC}"
exit 1
fi
if ! command -v npm &> /dev/null; then
echo -e "${RED}错误: 未安装npm请先安装npm${NC}"
exit 1
fi
NODE_VERSION=$(node -v)
echo -e "${GREEN}Node.js版本: ${NODE_VERSION}${NC}"
}
# 检查zip命令
check_zip() {
if ! command -v zip &> /dev/null; then
echo -e "${RED}错误: 未安装zip命令请先安装zip${NC}"
exit 1
fi
}
# 构建单个前端项目
build_project() {
local key=$1
local project_name=${FRONTEND_PROJECTS[$key]}
local project_dir="${PROJECT_ROOT}/${project_name}"
local output_file="${DEPLOY_DIR}/${project_name}.zip"
echo ""
echo "=========================================="
echo -e "${YELLOW}开始构建: ${project_name}${NC}"
echo "=========================================="
# 检查项目目录是否存在
if [ ! -d "${project_dir}" ]; then
echo -e "${RED}错误: 项目目录不存在 ${project_dir}${NC}"
return 1
fi
# 检查package.json是否存在
if [ ! -f "${project_dir}/package.json" ]; then
echo -e "${RED}错误: 未找到package.json ${project_dir}/package.json${NC}"
return 1
fi
cd "${project_dir}"
# 安装依赖
echo -e "${YELLOW}正在安装依赖...${NC}"
npm install --silent
# 执行构建
echo -e "${YELLOW}正在编译项目...${NC}"
npm run build:prod
# 检查dist目录是否存在
if [ ! -d "dist" ]; then
echo -e "${RED}错误: 构建失败未生成dist目录${NC}"
return 1
fi
# 删除旧的zip文件
if [ -f "${output_file}" ]; then
rm -f "${output_file}"
echo -e "${YELLOW}已删除旧的打包文件${NC}"
fi
# 打包dist目录
echo -e "${YELLOW}正在打包...${NC}"
cd dist
zip -r "${output_file}" . -x "*.DS_Store" -x "__MACOSX/*"
# 获取文件大小
local file_size=$(du -h "${output_file}" | cut -f1)
echo -e "${GREEN}构建完成: ${output_file} (${file_size})${NC}"
# 返回项目根目录
cd "${PROJECT_ROOT}"
}
# 主函数
main() {
local target=${1:-"all"}
echo "=========================================="
echo " 前端编译发布脚本"
echo "=========================================="
echo "项目根目录: ${PROJECT_ROOT}"
echo "输出目录: ${DEPLOY_DIR}"
echo "目标项目: ${target}"
echo ""
# 环境检查
check_node
check_zip
# 创建deploy目录
mkdir -p "${DEPLOY_DIR}"
local start_time=$(date +%s)
case "${target}" in
admin|mobile)
build_project "${target}"
;;
all)
for key in "${!FRONTEND_PROJECTS[@]}"; do
build_project "${key}"
done
;;
-h|--help|help)
print_help
exit 0
;;
*)
echo -e "${RED}错误: 未知项目 '${target}'${NC}"
print_help
exit 1
;;
esac
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo ""
echo "=========================================="
echo -e "${GREEN}所有构建任务完成!${NC}"
echo "总耗时: ${duration}"
echo "=========================================="
echo ""
echo "打包文件列表:"
ls -lh "${DEPLOY_DIR}"/*.zip 2>/dev/null || echo "无打包文件"
}
main "$@"