104 lines
3.4 KiB
PowerShell
104 lines
3.4 KiB
PowerShell
# Pinnovate Cloud 部署脚本
|
|
# 支持多种部署方式
|
|
|
|
param(
|
|
[Parameter(Mandatory=$false)]
|
|
[ValidateSet("vercel", "netlify", "github", "docker", "static")]
|
|
[string]$Platform = "static"
|
|
)
|
|
|
|
Write-Host "🚀 开始部署 Pinnovate Cloud 到 $Platform..." -ForegroundColor Green
|
|
|
|
# 检查 Node.js 和 npm
|
|
try {
|
|
$nodeVersion = node --version
|
|
$npmVersion = npm --version
|
|
Write-Host "✅ Node.js 版本: $nodeVersion" -ForegroundColor Green
|
|
Write-Host "✅ npm 版本: $npmVersion" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "❌ 请先安装 Node.js 和 npm" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 安装依赖
|
|
Write-Host "📦 安装依赖..." -ForegroundColor Yellow
|
|
npm ci
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "❌ 依赖安装失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 根据平台执行不同的部署
|
|
switch ($Platform) {
|
|
"static" {
|
|
Write-Host "🏗️ 构建静态网站..." -ForegroundColor Yellow
|
|
npm run build:static
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "✅ 静态网站构建成功!" -ForegroundColor Green
|
|
Write-Host "📁 静态文件位于: ./out 目录" -ForegroundColor Cyan
|
|
Write-Host "🌐 可以直接部署到任何静态文件服务器" -ForegroundColor Cyan
|
|
} else {
|
|
Write-Host "❌ 静态网站构建失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
"vercel" {
|
|
Write-Host "🏗️ 构建项目..." -ForegroundColor Yellow
|
|
npm run build
|
|
|
|
Write-Host "🚀 部署到 Vercel..." -ForegroundColor Yellow
|
|
npx vercel --prod
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "✅ Vercel 部署成功!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "❌ Vercel 部署失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
"netlify" {
|
|
Write-Host "🏗️ 构建静态网站..." -ForegroundColor Yellow
|
|
npm run build:static
|
|
|
|
Write-Host "🚀 部署到 Netlify..." -ForegroundColor Yellow
|
|
npx netlify deploy --prod --dir=out
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "✅ Netlify 部署成功!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "❌ Netlify 部署失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
"github" {
|
|
Write-Host "🏗️ 构建静态网站..." -ForegroundColor Yellow
|
|
npm run build:static
|
|
|
|
Write-Host "🚀 部署到 GitHub Pages..." -ForegroundColor Yellow
|
|
Write-Host "请确保已配置 GitHub Actions 工作流" -ForegroundColor Cyan
|
|
Write-Host "推送代码到 main 分支将自动触发部署" -ForegroundColor Cyan
|
|
}
|
|
|
|
"docker" {
|
|
Write-Host "🏗️ 构建 Docker 镜像..." -ForegroundColor Yellow
|
|
docker build -t pinnovate-cloud .
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "✅ Docker 镜像构建成功!" -ForegroundColor Green
|
|
Write-Host "🐳 运行容器: docker run -p 80:80 pinnovate-cloud" -ForegroundColor Cyan
|
|
Write-Host "🐳 使用 Docker Compose: docker-compose up -d" -ForegroundColor Cyan
|
|
} else {
|
|
Write-Host "❌ Docker 镜像构建失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host "🎉 部署完成!" -ForegroundColor Green
|
|
Write-Host "📖 更多部署选项请查看 README.md" -ForegroundColor Cyan
|