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 = '' $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.'