am-freescan/scripts/start-backend.ps1

37 lines
2.1 KiB
PowerShell
Raw Normal View History

2026-10-22 16:18:37 +08:00
param([switch]$Build, [string]$MavenCommand = 'mvn')
$ErrorActionPreference = 'Stop'
$taskRoot = Split-Path -Parent $PSScriptRoot
$taskConfigPath = Join-Path $taskRoot '.local/runtime.json'
if (-not (Test-Path -LiteralPath $taskConfigPath)) { throw '缺少 .local/runtime.json,请先完成独立数据库配置。' }
$taskRuntime = Get-Content -LiteralPath $taskConfigPath -Raw | ConvertFrom-Json
if ($taskRuntime.mysql.database -ne 'am-freescan' -or $taskRuntime.mysql.host -ne '192.168.28.10') { throw '数据库配置超出授权范围。' }
$env:AM_FREESCAN_DB_USER = $taskRuntime.mysql.user
$env:AM_FREESCAN_DB_PASSWORD = $taskRuntime.mysql.password
$env:AM_FREESCAN_REDIS_PASSWORD = $taskRuntime.redis.password
if (-not $env:JAVA_HOME) { $env:JAVA_HOME = 'C:/Users/Administrator/.jdks/jdk-17.0.20.1+1' }
$taskJava = Join-Path $env:JAVA_HOME 'bin/java.exe'
if ($Build) {
if (-not (Get-Command $MavenCommand -ErrorAction SilentlyContinue)) {
$taskBundledMaven = 'E:/developmentTool/idea/IntelliJ IDEA 2025.3/plugins/maven/lib/maven3/bin/mvn.cmd'
if (Test-Path -LiteralPath $taskBundledMaven) { $MavenCommand = $taskBundledMaven }
else { throw '未找到 Maven,请添加到 PATH 或通过 -MavenCommand 指定。' }
}
Push-Location (Join-Path $taskRoot 'am-backend')
try {
& $MavenCommand '-DskipTests' '-Dfile.encoding=UTF-8' '-pl' 'yudao-server' '-am' 'package'
if ($LASTEXITCODE -ne 0) { throw '后端构建失败。' }
} finally { Pop-Location }
}
$taskJar = Join-Path $taskRoot 'am-backend/yudao-server/target/yudao-server.jar'
if (-not (Test-Path -LiteralPath $taskJar)) { throw '后端尚未打包,请加 -Build。' }
Set-Location $taskRoot
$taskSimulatorConfig = Join-Path $taskRoot '.local/simulator/settings.json'
if (Test-Path -LiteralPath $taskSimulatorConfig) {
$taskSimulatorSettings = Get-Content -LiteralPath $taskSimulatorConfig -Raw | ConvertFrom-Json
if ($taskSimulatorSettings.enabled) {
& (Join-Path $PSScriptRoot 'manage-simulator.ps1') -Action start
}
}
& $taskJava '-Dfile.encoding=UTF-8' '-jar' $taskJar '--spring.profiles.active=local'
exit $LASTEXITCODE