迁移旧版题库 EXAM_DATA,实现单选/多选/判断/填空/连线/排序/归类/材料/作图/写作/代码等题型引擎,Pinia 作答状态、计时器、答题卡与交卷结果页,deploy.ps1 一键部署
158 lines
6.0 KiB
PowerShell
158 lines
6.0 KiB
PowerShell
# CCGO 前端部署脚本:备份原站页面 → 全量编译 → 同步产物到生产目录(TempLate/CCGO)
|
||
#
|
||
# 用途:
|
||
# 1. 备份已被 Vue 页面替换的 TempLate/CCGO 原始文件到 backup/ccgo
|
||
# 2. 全量重新构建(vue-tsc 类型检查 + vite build)
|
||
# 3. 同步 dist 产物到 TempLate/CCGO(index.html + CCGO 资产)
|
||
# 4. 校验产物一致性
|
||
#
|
||
# 前置条件:
|
||
# 1. gvsds/apps/core/views.py 中 SUBDOMAIN_CONFIG 已配置 'ccgo': {'dir': 'CCGO', 'root_is_index': True}
|
||
# 2. CCGO 路由使用 createWebHistory(支持干净 URL)
|
||
#
|
||
# 用法:
|
||
# PowerShell 中执行: .\deploy.ps1
|
||
# (若报执行策略限制: Set-ExecutionPolicy -Scope Process Bypass 后再执行)
|
||
|
||
$ErrorActionPreference = 'Stop'
|
||
|
||
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path # d:\SMANAGE\CCGO
|
||
$DistDir = Join-Path $ProjectRoot 'dist'
|
||
$TemplateRoot = Join-Path (Split-Path -Parent $ProjectRoot) 'TempLate' # d:\SMANAGE\TempLate
|
||
$BackupRoot = Join-Path (Split-Path -Parent $ProjectRoot) 'backup\ccgo' # d:\SMANAGE\backup\ccgo
|
||
|
||
Write-Host "`n===== CCGO 部署开始 =====" -ForegroundColor Cyan
|
||
Write-Host "工程目录: $ProjectRoot"
|
||
Write-Host "生产目录: $TemplateRoot\CCGO"
|
||
Write-Host "备份目录: $BackupRoot"
|
||
Write-Host ""
|
||
|
||
# =====================
|
||
# 0. 前置检查
|
||
# =====================
|
||
Write-Host '[0/5] 前置检查...' -ForegroundColor Yellow
|
||
$ViewsPy = Join-Path (Split-Path -Parent $ProjectRoot) 'gvsds\apps\core\views.py'
|
||
if (Test-Path $ViewsPy) {
|
||
$ViewsContent = Get-Content $ViewsPy -Raw
|
||
if ($ViewsContent -match "'ccgo':\s*\{'dir':\s*'CCGO',\s*'root_is_index':\s*True\s*\}") {
|
||
Write-Host ' ccgo 子域配置检查通过' -ForegroundColor Green
|
||
} else {
|
||
Write-Warning ' ccgo 子域配置可能未匹配,请检查 views.py 的 SUBDOMAIN_CONFIG'
|
||
}
|
||
} else {
|
||
Write-Warning " 未找到 $ViewsPy,跳过子域配置检查"
|
||
}
|
||
Write-Host ''
|
||
|
||
# =====================
|
||
# 1. 备份被替换的原始页面
|
||
# =====================
|
||
Write-Host '[1/5] 备份被替换的 CCGO 原始页面...' -ForegroundColor Yellow
|
||
$ProdCcgo = Join-Path $TemplateRoot 'CCGO'
|
||
if (Test-Path $ProdCcgo) {
|
||
if (-not (Test-Path $BackupRoot)) {
|
||
New-Item -ItemType Directory -Path $BackupRoot -Force | Out-Null
|
||
}
|
||
# 备份所有旧文件(除构建产物目录外的全部内容)
|
||
Get-ChildItem -Path $ProdCcgo -Force | ForEach-Object {
|
||
$dest = Join-Path $BackupRoot $_.Name
|
||
Copy-Item -Path $_.FullName -Destination $dest -Recurse -Force
|
||
Write-Host " 已备份: $($_.Name)"
|
||
}
|
||
} else {
|
||
Write-Host " TempLate/CCGO 不存在,跳过备份" -ForegroundColor DarkGray
|
||
}
|
||
Write-Host ''
|
||
|
||
# =====================
|
||
# 2. 清理旧构建产物与旧页面
|
||
# =====================
|
||
Write-Host '[2/5] 清理旧构建产物...' -ForegroundColor Yellow
|
||
if (Test-Path $DistDir) {
|
||
Remove-Item -Recurse -Force $DistDir
|
||
Write-Host " 已删除: $DistDir"
|
||
}
|
||
# 清理 TempLate/CCGO 旧产物目录(构建产物统一收敛到该子目录)
|
||
if (Test-Path $ProdCcgo) {
|
||
Get-ChildItem -Path $ProdCcgo -Recurse -Force | Remove-Item -Recurse -Force
|
||
Write-Host " 已清理旧产物目录: CCGO/"
|
||
} else {
|
||
New-Item -ItemType Directory -Path $ProdCcgo -Force | Out-Null
|
||
Write-Host " 已创建生产目录: CCGO/"
|
||
}
|
||
Write-Host ''
|
||
|
||
# =====================
|
||
# 3. 全量构建
|
||
# =====================
|
||
Write-Host '[3/5] 执行 npm run build(类型检查 + 全量编译)...' -ForegroundColor Yellow
|
||
Push-Location $ProjectRoot
|
||
try {
|
||
npm run build
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "构建失败,exit code = $LASTEXITCODE"
|
||
}
|
||
} finally {
|
||
Pop-Location
|
||
}
|
||
Write-Host ' 构建成功'
|
||
Write-Host ''
|
||
|
||
# =====================
|
||
# 4. 同步产物到生产目录
|
||
# =====================
|
||
Write-Host '[4/5] 同步产物到 ccgo 生产目录...' -ForegroundColor Yellow
|
||
|
||
# 复制 CCGO 构建产物到生产目录 CCGO/(vite assetsDir=CCGO,产物位于 dist/CCGO/,相对引用 CCGO/...)
|
||
$DistAssets = Join-Path $DistDir 'CCGO'
|
||
if (Test-Path $DistAssets) {
|
||
Copy-Item -Recurse -Force (Join-Path $DistAssets '*') $ProdCcgo
|
||
Write-Host " 已同步: CCGO/ 资产"
|
||
} else {
|
||
Write-Warning " dist 中未找到 CCGO,请检查 vite.config.ts 的 assetsDir 配置"
|
||
}
|
||
|
||
# 复制 index.html(产物引用为 /CCGO/...,与部署位置 CCGO/ 一致,无需改写)
|
||
$DistIndex = Join-Path $DistDir 'index.html'
|
||
$ProdIndex = Join-Path $ProdCcgo 'index.html'
|
||
if (Test-Path $DistIndex) {
|
||
Copy-Item -Force $DistIndex $ProdIndex
|
||
Write-Host " 已同步: index.html"
|
||
}
|
||
|
||
Write-Host ' 同步完成'
|
||
Write-Host ''
|
||
|
||
# =====================
|
||
# 5. 校验产物一致性
|
||
# =====================
|
||
Write-Host '[5/5] 校验产物一致性...' -ForegroundColor Yellow
|
||
|
||
if (-not (Test-Path $ProdIndex)) {
|
||
throw "index.html 不存在于生产目录: $ProdIndex"
|
||
}
|
||
|
||
$indexContent = Get-Content $ProdIndex -Raw
|
||
$entryMatch = [regex]::Match($indexContent, 'src="([^"]+\.js)"')
|
||
if ($entryMatch.Success) {
|
||
$entryPath = Join-Path $TemplateRoot ($entryMatch.Groups[1].Value.TrimStart('/'))
|
||
if (Test-Path $entryPath) {
|
||
Write-Host " 入口 JS 校验通过: $($entryMatch.Groups[1].Value)" -ForegroundColor Green
|
||
} else {
|
||
throw "index.html 引用的入口 JS 不存在: $entryPath"
|
||
}
|
||
} else {
|
||
throw 'index.html 中未找到入口 JS 引用'
|
||
}
|
||
|
||
Write-Host ''
|
||
Write-Host "===== CCGO 部署完成 =====" -ForegroundColor Cyan
|
||
Write-Host "备份位置: $BackupRoot" -ForegroundColor Cyan
|
||
Write-Host "请浏览器强制刷新(Ctrl+F5)加载新产物。" -ForegroundColor Cyan
|
||
Write-Host ''
|
||
Write-Host '===== 部署后提醒 =====' -ForegroundColor Magenta
|
||
Write-Host ' - ccgo.gvsds.com 现在使用 CCGO SPA(createWebHistory)'
|
||
Write-Host ' - 原始文件已备份到 backup/ccgo,可随时恢复'
|
||
Write-Host ' - 如需回退:删除 TempLate/CCGO/index.html 与 CCGO 资产,恢复 backup/ccgo 中的文件'
|
||
Write-Host '================================================================================' -ForegroundColor Magenta
|