76 lines
1.5 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
# 构建脚本 - 自动加载 nvm 并执行构建
set -e # 遇到错误立即退出
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 打印带颜色的消息
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
print_info "开始构建项目..."
# 加载 nvm
if [ -s "$HOME/.nvm/nvm.sh" ]; then
print_info "加载 nvm..."
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
else
print_warn "未找到 nvm尝试使用系统 Node.js..."
fi
# 检查 Node.js 是否可用
if ! command -v node &> /dev/null; then
print_error "Node.js 未找到!请确保已安装 Node.js 或配置了 nvm。"
exit 1
fi
# 显示 Node.js 版本
NODE_VERSION=$(node --version)
print_info "使用 Node.js 版本: $NODE_VERSION"
# 检查 pnpm 是否可用
if ! command -v pnpm &> /dev/null; then
print_error "pnpm 未找到!请先安装 pnpm: npm install -g pnpm"
exit 1
fi
# 显示 pnpm 版本
PNPM_VERSION=$(pnpm --version)
print_info "使用 pnpm 版本: $PNPM_VERSION"
# 执行构建
print_info "执行构建命令: pnpm run build"
echo ""
pnpm run build
# 检查构建结果
if [ $? -eq 0 ]; then
print_info "构建成功完成!"
print_info "构建产物位于: $SCRIPT_DIR/dist"
exit 0
else
print_error "构建失败!"
exit 1
fi