48 lines
3.0 KiB
PowerShell
48 lines
3.0 KiB
PowerShell
|
|
param([string]$SecretsFile = (Join-Path $PSScriptRoot 'secrets.psd1'))
|
||
|
|
. (Join-Path $PSScriptRoot 'common.ps1')
|
||
|
|
$settings = Read-LocalSettings $SecretsFile
|
||
|
|
$runPath = Join-Path $repoPath '.run'
|
||
|
|
New-Item -ItemType Directory -Path $runPath -Force | Out-Null
|
||
|
|
|
||
|
|
# IDEA loads this private run configuration from the project's .run directory.
|
||
|
|
# It contains local credentials and is excluded from Git.
|
||
|
|
[xml]$document = '<component name="ProjectRunConfigurationManager"><configuration default="false" name="ElderYudao Local" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot"><option name="ACTIVE_PROFILES" value="local,desktop" /><module name="yudao-server" /><option name="SPRING_BOOT_MAIN_CLASS" value="cn.iocoder.yudao.server.YudaoServerApplication" /><option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /><option name="VM_PARAMETERS" value="-Dfile.encoding=UTF-8" /><envs /><method v="2"><option name="Make" enabled="true" /></method></configuration></component>'
|
||
|
|
$configuration = $document.component.configuration
|
||
|
|
$environment = @{
|
||
|
|
ELDER_DB_HOST = [string]$settings.DatabaseHost
|
||
|
|
ELDER_DB_PORT = [string]$settings.DatabasePort
|
||
|
|
ELDER_DB_NAME = [string]$settings.DatabaseName
|
||
|
|
ELDER_DB_USER = [string]$settings.DatabaseUser
|
||
|
|
ELDER_DB_PASSWORD = [string]$settings.DatabasePassword
|
||
|
|
ELDER_REDIS_HOST = [string]$settings.RedisHost
|
||
|
|
ELDER_REDIS_PORT = [string]$settings.RedisPort
|
||
|
|
ELDER_REDIS_DATABASE = [string]$settings.RedisDatabase
|
||
|
|
ELDER_SERVER_PORT = [string]$settings.ServerPort
|
||
|
|
ELDER_LOG_FILE = Join-Path $runtimePath 'application.log'
|
||
|
|
}
|
||
|
|
if ($settings.RedisPassword) { $environment.SPRING_REDIS_PASSWORD = [string]$settings.RedisPassword }
|
||
|
|
foreach ($key in ($environment.Keys | Sort-Object)) {
|
||
|
|
$entry = $document.CreateElement('env')
|
||
|
|
$entry.SetAttribute('name', $key)
|
||
|
|
$entry.SetAttribute('value', $environment[$key])
|
||
|
|
$configuration.SelectSingleNode('envs').AppendChild($entry) | Out-Null
|
||
|
|
}
|
||
|
|
if ($settings.JavaExe) {
|
||
|
|
$javaExe = Resolve-LocalProgram $settings.JavaExe 'java.exe'
|
||
|
|
$jdkPath = Split-Path (Split-Path $javaExe -Parent) -Parent
|
||
|
|
foreach ($option in @(@{ name = 'ALTERNATIVE_JRE_PATH'; value = $jdkPath }, @{ name = 'ALTERNATIVE_JRE_PATH_ENABLED'; value = 'true' })) {
|
||
|
|
$entry = $document.CreateElement('option')
|
||
|
|
$entry.SetAttribute('name', $option.name)
|
||
|
|
$entry.SetAttribute('value', $option.value)
|
||
|
|
$configuration.AppendChild($entry) | Out-Null
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$writerSettings = New-Object System.Xml.XmlWriterSettings
|
||
|
|
$writerSettings.Encoding = New-Object System.Text.UTF8Encoding($false)
|
||
|
|
$writerSettings.Indent = $true
|
||
|
|
$writerSettings.OmitXmlDeclaration = $true
|
||
|
|
$writer = [System.Xml.XmlWriter]::Create((Join-Path $runPath 'ElderYudaoLocal.run.xml'), $writerSettings)
|
||
|
|
try { $document.Save($writer) } finally { $writer.Dispose() }
|
||
|
|
Write-Output 'IDEA configuration prepared: ElderYudao Local (profiles: local,desktop).'
|
||
|
|
Write-Output 'Select it in IDEA and run YudaoServerApplication. Reopen the project if the configuration has not appeared.'
|