Files
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

99 lines
4.6 KiB
PowerShell

# ═══════════════════════════════════════════════════════════
# canteen-delivery2 生产环境一键部署脚本
# 用法: 以管理员身份打开 PowerShell,运行此脚本
# .\deploy.ps1
# ═══════════════════════════════════════════════════════════
$ErrorActionPreference = "Stop"
$ProjectRoot = "C:\Users\ADMIN\Desktop\project\canteen-delivery2"
Set-Location $ProjectRoot
Write-Host ""
Write-Host "══════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " canteen-delivery2 生产部署" -ForegroundColor Cyan
Write-Host "══════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
# ═══════ Step 1: 检查前置条件 ═══════
Write-Host "[1/5] 检查环境..." -ForegroundColor Yellow
$nodeVersion = node --version 2>$null
if (-not $nodeVersion) {
Write-Host "ERROR: Node.js 未安装,请从 https://nodejs.org 下载安装" -ForegroundColor Red
exit 1
}
Write-Host " Node.js: $nodeVersion" -ForegroundColor Green
# 检查 .env.production
if (-not (Test-Path ".env.production")) {
Write-Host "ERROR: .env.production 不存在,请先运行 node -e `"console.log(require('crypto').randomBytes(48).toString('base64'))`" 生成密钥" -ForegroundColor Red
exit 1
}
Write-Host " .env.production: 已配置" -ForegroundColor Green
# ═══════ Step 2: 安装依赖 ═══════
Write-Host ""
Write-Host "[2/5] 安装前端依赖..." -ForegroundColor Yellow
npm ci --production=false 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host " 尝试 npm install..." -ForegroundColor Yellow
npm install 2>&1
}
Write-Host " 前端依赖: 完成" -ForegroundColor Green
Write-Host " 安装后端依赖..." -ForegroundColor Yellow
Push-Location server
npm ci --production=false 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
npm install 2>&1
}
Pop-Location
Write-Host " 后端依赖: 完成" -ForegroundColor Green
# ═══════ Step 3: 构建 ═══════
Write-Host ""
Write-Host "[3/5] 构建前端..." -ForegroundColor Yellow
npm run build
if ($LASTEXITCODE -ne 0) { Write-Host "前端构建失败" -ForegroundColor Red; exit 1 }
Write-Host " 前端构建: dist/ 已生成" -ForegroundColor Green
Write-Host " 构建后端..." -ForegroundColor Yellow
Push-Location server
npm run build
Pop-Location
if ($LASTEXITCODE -ne 0) { Write-Host "后端构建失败" -ForegroundColor Red; exit 1 }
Write-Host " 后端构建: server/dist/ 已生成" -ForegroundColor Green
# ═══════ Step 4: 数据库初始化 ═══════
Write-Host ""
Write-Host "[4/5] 初始化数据库..." -ForegroundColor Yellow
Push-Location server
node dist/setup-db.js 2>&1
Write-Host " setup-db: 完成" -ForegroundColor Green
node dist/migrate.js 2>&1
Write-Host " migrate: 完成" -ForegroundColor Green
node dist/seed-permissions.js 2>&1
Write-Host " seed-permissions: 完成" -ForegroundColor Green
Pop-Location
# ═══════ Step 5: 启动 ═══════
Write-Host ""
Write-Host "[5/5] 启动生产服务..." -ForegroundColor Yellow
Write-Host ""
Write-Host "══════════════════════════════════════════" -ForegroundColor Green
Write-Host " 部署完成!请运行以下命令启动服务:" -ForegroundColor Green
Write-Host ""
Write-Host " # 方式1: 直接启动(前台运行)" -ForegroundColor White
Write-Host " cd C:\Users\ADMIN\Desktop\project\canteen-delivery2\server" -ForegroundColor White
Write-Host " node dist/index.js" -ForegroundColor White
Write-Host ""
Write-Host " # 方式2: 使用 PM2(推荐,后台运行+自动重启)" -ForegroundColor White
Write-Host " npm install -g pm2" -ForegroundColor White
Write-Host " cd C:\Users\ADMIN\Desktop\project\canteen-delivery2\server" -ForegroundColor White
Write-Host " pm2 start dist/index.js --name canteen-delivery" -ForegroundColor White
Write-Host " pm2 save" -ForegroundColor White
Write-Host " pm2 startup" -ForegroundColor White
Write-Host ""
Write-Host " # 访问: http://localhost:3001" -ForegroundColor Cyan
Write-Host "══════════════════════════════════════════" -ForegroundColor Green