Files
JayuCloud/scripts/package-release.ps1
T

162 lines
4.8 KiB
PowerShell
Raw Normal View History

param(
[switch]$SkipTests,
[string]$MavenPath = ""
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$releaseRoot = Join-Path $repoRoot "release-packages"
$releaseDir = Join-Path $releaseRoot $timestamp
$backendDir = Join-Path $releaseDir "backend"
$frontendDir = Join-Path $releaseDir "frontend"
$miniProgramDir = Join-Path $releaseDir "miniprograms"
2026-06-29 23:26:43 +08:00
$sqlPath = Join-Path $repoRoot "scripts\sql\init\JayuCloud.sql"
function Resolve-Maven {
param([string]$PreferredPath)
2026-06-22 20:39:51 +08:00
if ($PreferredPath -and (Test-Path -LiteralPath $PreferredPath)) {
return (Resolve-Path -LiteralPath $PreferredPath).Path
}
$fromPath = Get-Command mvn.cmd -ErrorAction SilentlyContinue
if ($fromPath) {
return $fromPath.Source
}
2026-06-22 20:39:51 +08:00
$fromPath = Get-Command mvn -ErrorAction SilentlyContinue
if ($fromPath) {
return $fromPath.Source
}
2026-06-22 20:39:51 +08:00
throw "找不到 Maven,请通过 -MavenPath 传入 Maven 可执行文件绝对路径。"
}
2026-06-22 20:39:51 +08:00
function Invoke-Native {
param(
2026-06-22 20:39:51 +08:00
[string]$FilePath,
[string[]]$Arguments,
[string]$WorkingDirectory
)
2026-06-22 20:39:51 +08:00
Write-Host ">> $FilePath $($Arguments -join ' ')"
$previousLocation = Get-Location
try {
Set-Location -LiteralPath $WorkingDirectory
& $FilePath @Arguments
if ($LASTEXITCODE -ne 0) {
throw "命令执行失败,退出码 ${LASTEXITCODE}:$FilePath"
}
}
finally {
Set-Location $previousLocation
}
}
function Copy-Directory {
param(
[string]$Source,
[string]$Destination
)
2026-06-22 20:39:51 +08:00
if (-not (Test-Path -LiteralPath $Source)) {
throw "缺少待打包目录:$Source"
}
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
2026-06-29 20:58:39 +08:00
Copy-Item -Path (Join-Path $Source "*") -Destination $Destination -Recurse -Force
2026-06-22 20:39:51 +08:00
}
function Copy-RequiredFile {
param(
[string]$Source,
[string]$Destination
)
if (-not (Test-Path -LiteralPath $Source)) {
throw "缺少待打包文件:$Source"
}
Copy-Item -LiteralPath $Source -Destination $Destination -Force
}
function Write-Step {
param([string]$Message)
Write-Host ""
Write-Host "==> $Message"
}
$maven = Resolve-Maven $MavenPath
New-Item -ItemType Directory -Force -Path $backendDir, $frontendDir, $miniProgramDir | Out-Null
$mavenArgs = @("-q", "package")
if ($SkipTests) {
$mavenArgs += "-DskipTests"
}
2026-06-29 23:26:43 +08:00
Write-Step "构建 JY-Core"
Invoke-Native $maven $mavenArgs (Join-Path $repoRoot "JY-Core")
2026-06-29 23:26:43 +08:00
Write-Step "构建 JY-Gateway"
Invoke-Native $maven $mavenArgs (Join-Path $repoRoot "JY-Gateway")
2026-06-29 23:26:43 +08:00
Write-Step "构建 JY-Artist-Frontend"
$frontendRoot = Join-Path $repoRoot "JY-Artist-Frontend"
2026-06-22 20:39:51 +08:00
if (-not (Test-Path -LiteralPath (Join-Path $frontendRoot "node_modules"))) {
Invoke-Native "npm" @("ci") $frontendRoot
}
2026-06-22 20:39:51 +08:00
Invoke-Native "npm" @("run", "build") $frontendRoot
2026-06-29 23:26:43 +08:00
Write-Step "构建 JY-Salon-Front"
$managerMobileRoot = Join-Path $repoRoot "JY-Salon-Front"
2026-06-29 20:58:39 +08:00
if (-not (Test-Path -LiteralPath (Join-Path $managerMobileRoot "node_modules"))) {
Invoke-Native "npm" @("ci") $managerMobileRoot
}
Invoke-Native "npm" @("run", "build") $managerMobileRoot
2026-06-29 23:26:43 +08:00
$coreJar = Join-Path $repoRoot "JY-Core\target\JY-Core.jar"
$gatewayJar = Join-Path $repoRoot "JY-Gateway\target\JY-Gateway.jar"
2026-06-22 20:39:51 +08:00
$frontendDist = Join-Path $frontendRoot "dist"
2026-06-29 20:58:39 +08:00
$managerMobileDist = Join-Path $managerMobileRoot "dist"
2026-06-22 20:39:51 +08:00
2026-06-29 23:26:43 +08:00
Copy-RequiredFile $coreJar (Join-Path $backendDir "JY-Core.jar")
Copy-RequiredFile $gatewayJar (Join-Path $backendDir "JY-Gateway.jar")
2026-06-22 20:39:51 +08:00
Copy-Directory $frontendDist (Join-Path $frontendDir "dist")
2026-06-29 23:26:43 +08:00
Copy-Directory $frontendDist (Join-Path $frontendDir "jy-artist-dist")
Copy-Directory $managerMobileDist (Join-Path $frontendDir "jy-salon-front-dist")
Copy-Directory $managerMobileDist (Join-Path $frontendDir "dist\jy-salon-front")
Copy-Directory (Join-Path $repoRoot "JY-Artist-WeChat") (Join-Path $miniProgramDir "JY-Artist-WeChat")
Copy-Directory (Join-Path $repoRoot "JY-Salon-WeChat") (Join-Path $miniProgramDir "JY-Salon-WeChat")
Copy-RequiredFile $sqlPath (Join-Path $releaseDir "JayuCloud.sql")
$manifest = @(
2026-06-29 23:26:43 +08:00
"# JayuCloud Release $timestamp",
"",
2026-06-29 23:26:43 +08:00
"- backend/JY-Core.jar",
"- backend/JY-Gateway.jar",
"- frontend/dist",
2026-06-29 23:26:43 +08:00
"- frontend/jy-artist-dist",
"- frontend/dist/jy-salon-front",
"- frontend/jy-salon-front-dist",
"- miniprograms/JY-Artist-WeChat",
"- miniprograms/JY-Salon-WeChat",
"- JayuCloud.sql",
"",
2026-06-29 23:26:43 +08:00
"Nacos namespace: jayu-cloud",
"Database initialized by: scripts/sql/init/JayuCloud.sql",
"Database name: jayu_cloud",
2026-06-29 20:58:39 +08:00
"Manager mini program API: https://yunail.art/api/admin",
2026-06-29 23:26:43 +08:00
"Manager mobile web: https://yunail.art/jy-salon-front/"
)
$manifest | Set-Content -Encoding UTF8 (Join-Path $releaseDir "README.md")
$zipPath = "$releaseDir.zip"
Compress-Archive -Path (Join-Path $releaseDir "*") -DestinationPath $zipPath -Force
2026-06-22 20:39:51 +08:00
Write-Host ""
Write-Host "发布目录:$releaseDir"
Write-Host "发布压缩包:$zipPath"