|
|
# ============================================================
|
|
|
# deploy-admin.ps1 — 一键编译后端+前端并部署到 admin 目录
|
|
|
# 用法:在项目根目录执行 .\deploy-admin.ps1
|
|
|
# ============================================================
|
|
|
|
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
$projectRoot = $PSScriptRoot
|
|
|
|
|
|
Write-Host ""
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
|
Write-Host " CNC 系统一键部署脚本" -ForegroundColor Cyan
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
|
Write-Host ""
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
# 第1步:编译后端
|
|
|
# --------------------------------------------------
|
|
|
Write-Host "[1/2] 编译后端 API ..." -ForegroundColor Yellow
|
|
|
dotnet build "$projectRoot\CncDataSystem.sln"
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
Write-Host "后端编译失败!" -ForegroundColor Red
|
|
|
exit 1
|
|
|
}
|
|
|
Write-Host "后端编译完成 ✓" -ForegroundColor Green
|
|
|
Write-Host ""
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
# 第2步:编译前端并输出到 admin 目录
|
|
|
# --------------------------------------------------
|
|
|
Write-Host "[2/2] 编译前端(输出到 src\CncWebApi\admin\)..." -ForegroundColor Yellow
|
|
|
|
|
|
$frontendDir = Join-Path $projectRoot "frontend"
|
|
|
|
|
|
# 安装依赖(如果 node_modules 不存在)
|
|
|
if (-not (Test-Path "$frontendDir\node_modules")) {
|
|
|
Write-Host " 安装前端依赖 ..." -ForegroundColor Gray
|
|
|
npm install --prefix $frontendDir
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
Write-Host "前端依赖安装失败!" -ForegroundColor Red
|
|
|
exit 1
|
|
|
}
|
|
|
}
|
|
|
|
|
|
# 构建前端(vite.config.ts 已配置 outDir 指向 ../src/CncWebApi/admin)
|
|
|
npm run build --prefix $frontendDir
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
Write-Host "前端编译失败!" -ForegroundColor Red
|
|
|
exit 1
|
|
|
}
|
|
|
|
|
|
$adminDir = Join-Path $projectRoot "src\CncWebApi\admin"
|
|
|
$fileCount = (Get-ChildItem $adminDir -Recurse -File).Count
|
|
|
Write-Host "前端编译完成 ✓($fileCount 个文件)" -ForegroundColor Green
|
|
|
Write-Host ""
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
# 完成
|
|
|
# --------------------------------------------------
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
|
Write-Host " 部署完成!" -ForegroundColor Cyan
|
|
|
Write-Host " 后端 API:http://192.168.1.202/api/health" -ForegroundColor White
|
|
|
Write-Host " 前端页面:http://192.168.1.202/admin/" -ForegroundColor White
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
|
Write-Host ""
|