|
| 1 | +# Build TypeScript Definition Generator Rider plugin |
| 2 | +# Output: TypeScriptDefinitionGenerator.Rider-<version>.zip |
| 3 | +# Requires: dotnet; Java 17+ for full build (Kotlin context menu) |
| 4 | +# Usage: .\build-rider-plugin.ps1 [Configuration] [Version] [--dotnet-only] |
| 5 | +# Example: .\build-rider-plugin.ps1 Release 1.0.0 |
| 6 | + |
| 7 | +$ErrorActionPreference = "Stop" |
| 8 | +Set-Location $PSScriptRoot |
| 9 | + |
| 10 | +$configArg = $args[0] |
| 11 | +$versionArg = $args[1] |
| 12 | +$thirdArg = $args[2] |
| 13 | + |
| 14 | +$CONFIGURATION = "Release" |
| 15 | +$VERSION = "1.0.0" |
| 16 | +$DOTNET_ONLY = $false |
| 17 | + |
| 18 | +if ($configArg -eq "--dotnet-only") { |
| 19 | + $DOTNET_ONLY = $true |
| 20 | +} elseif ($versionArg -eq "--dotnet-only") { |
| 21 | + $DOTNET_ONLY = $true |
| 22 | +} else { |
| 23 | + if ($null -ne $configArg -and $configArg -ne "") { $CONFIGURATION = $configArg } |
| 24 | + if ($null -ne $versionArg -and $versionArg -ne "") { $VERSION = $versionArg } |
| 25 | +} |
| 26 | +if ($thirdArg -eq "--dotnet-only") { $DOTNET_ONLY = $true } |
| 27 | + |
| 28 | +$PLUGIN_NAME = "TypeScriptDefinitionGenerator.Rider" |
| 29 | +$OUTPUT_DIR = "output" |
| 30 | +$ZIP_NAME = "${PLUGIN_NAME}-${VERSION}.zip" |
| 31 | + |
| 32 | +Write-Host "Building $PLUGIN_NAME ($CONFIGURATION)..." |
| 33 | + |
| 34 | +# 1. Build .NET backend |
| 35 | +Write-Host " Building .NET backend..." |
| 36 | +dotnet build "src\$PLUGIN_NAME\$PLUGIN_NAME.csproj" -c $CONFIGURATION |
| 37 | + |
| 38 | +$PLUGIN_DIR = "$OUTPUT_DIR\$PLUGIN_NAME" |
| 39 | +if (Test-Path $PLUGIN_DIR) { Remove-Item -Path $PLUGIN_DIR -Recurse -Force } |
| 40 | +New-Item -ItemType Directory -Path $PLUGIN_DIR -Force | Out-Null |
| 41 | +New-Item -ItemType Directory -Path "$PLUGIN_DIR\dotnet" -Force | Out-Null |
| 42 | +New-Item -ItemType Directory -Path "$PLUGIN_DIR\META-INF" -Force | Out-Null |
| 43 | + |
| 44 | +# 2. Build Kotlin frontend (Solution View context menu) — requires Java 17+ |
| 45 | +$KOTLIN_BUILT = $false |
| 46 | +if (-not $DOTNET_ONLY) { |
| 47 | + Write-Host " Building Kotlin frontend..." |
| 48 | + $javaCmd = "java" |
| 49 | + if ($env:JAVA_HOME -and (Test-Path "$env:JAVA_HOME\bin\java.exe")) { |
| 50 | + $javaCmd = "$env:JAVA_HOME\bin\java.exe" |
| 51 | + } |
| 52 | + try { |
| 53 | + $javaVersionOutput = & $javaCmd -version 2>&1 | Out-String |
| 54 | + $hasJava17 = $javaVersionOutput -match 'version "1[7-9]|version "2[0-9]' |
| 55 | + } catch { |
| 56 | + $hasJava17 = $false |
| 57 | + } |
| 58 | + |
| 59 | + if (-not $hasJava17) { |
| 60 | + # Try common Java 17 locations on Windows |
| 61 | + $jdkPaths = @( |
| 62 | + "$env:JAVA_HOME", |
| 63 | + "C:\Program Files\Eclipse Adoptium\jdk-17*", |
| 64 | + "C:\Program Files\Microsoft\jdk-17*", |
| 65 | + "C:\Program Files\Java\jdk-17*", |
| 66 | + "C:\Program Files\OpenJDK\jdk-17*" |
| 67 | + ) |
| 68 | + foreach ($j in $jdkPaths) { |
| 69 | + if (-not $j) { continue } |
| 70 | + $resolved = $ExecutionContext.InvokeCommand.ExpandString($j) |
| 71 | + $javaExe = Get-ChildItem -Path $resolved -Filter "java.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 72 | + if ($javaExe) { |
| 73 | + $env:JAVA_HOME = $javaExe.Directory.Parent.FullName |
| 74 | + $javaCmd = $javaExe.FullName |
| 75 | + try { |
| 76 | + $javaVersionOutput = & $javaCmd -version 2>&1 | Out-String |
| 77 | + $hasJava17 = $javaVersionOutput -match 'version "1[7-9]|version "2[0-9]' |
| 78 | + } catch { $hasJava17 = $false } |
| 79 | + if ($hasJava17) { break } |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + if ($hasJava17 -and (Test-Path "rider\gradlew.bat")) { |
| 85 | + Push-Location rider |
| 86 | + try { |
| 87 | + & .\gradlew.bat buildPlugin "-Pversion=$VERSION" -q |
| 88 | + if ($LASTEXITCODE -eq 0) { $KOTLIN_BUILT = $true } else { Write-Host " Kotlin build failed. Run: cd rider; .\gradlew.bat buildPlugin" } |
| 89 | + } finally { |
| 90 | + Pop-Location |
| 91 | + } |
| 92 | + } elseif ($hasJava17 -and (Test-Path "rider\gradlew")) { |
| 93 | + # Unix gradlew — try running via Git Bash or WSL if available |
| 94 | + Push-Location rider |
| 95 | + try { |
| 96 | + if (Get-Command "bash" -ErrorAction SilentlyContinue) { |
| 97 | + $env:JAVA_HOME = $env:JAVA_HOME |
| 98 | + bash -c "./gradlew buildPlugin -Pversion=$VERSION -q" |
| 99 | + if ($LASTEXITCODE -eq 0) { $KOTLIN_BUILT = $true } |
| 100 | + } |
| 101 | + if (-not $KOTLIN_BUILT) { Write-Host " Skipping Kotlin (use gradlew.bat or run build-rider-plugin.sh in Git Bash/WSL)." } |
| 102 | + } finally { |
| 103 | + Pop-Location |
| 104 | + } |
| 105 | + } else { |
| 106 | + if (-not $hasJava17) { Write-Host " Skipping Kotlin (Java 17+ required). Set JAVA_HOME or use --dotnet-only." } |
| 107 | + elseif (-not (Test-Path "rider\gradlew.bat")) { Write-Host " Skipping Kotlin (rider\gradlew.bat not found; add it or use build-rider-plugin.sh on Unix)." } |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +# 3. Assemble plugin |
| 112 | +if ($KOTLIN_BUILT) { |
| 113 | + $riderZip = $null |
| 114 | + foreach ($candidate in @( |
| 115 | + "rider\build\distributions\${PLUGIN_NAME}-${VERSION}.zip", |
| 116 | + "rider\build\distributions\${PLUGIN_NAME}-1.0.0.zip" |
| 117 | + )) { |
| 118 | + if (Test-Path $candidate) { $riderZip = $candidate; break } |
| 119 | + } |
| 120 | + if (-not $riderZip -and (Test-Path "rider\build\distributions")) { |
| 121 | + $firstZip = Get-ChildItem "rider\build\distributions\*.zip" -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 122 | + if ($firstZip) { $riderZip = $firstZip.FullName } |
| 123 | + } |
| 124 | + if ($riderZip) { |
| 125 | + $tmpExtract = "$OUTPUT_DIR\.tmp_extract" |
| 126 | + if (Test-Path $tmpExtract) { Remove-Item -Path $tmpExtract -Recurse -Force } |
| 127 | + Expand-Archive -Path $riderZip -DestinationPath $tmpExtract -Force |
| 128 | + $extracted = Get-ChildItem -Path $tmpExtract -Directory -Filter "${PLUGIN_NAME}*" | Select-Object -First 1 |
| 129 | + if ($extracted) { |
| 130 | + Copy-Item -Path "$($extracted.FullName)\*" -Destination $PLUGIN_DIR -Recurse -Force |
| 131 | + } elseif (Test-Path "$tmpExtract\META-INF") { |
| 132 | + Copy-Item -Path "$tmpExtract\META-INF\*" -Destination "$PLUGIN_DIR\META-INF" -Recurse -Force |
| 133 | + if (Test-Path "$tmpExtract\lib") { Copy-Item -Path "$tmpExtract\lib" -Destination $PLUGIN_DIR -Recurse -Force } |
| 134 | + } |
| 135 | + Remove-Item -Path $tmpExtract -Recurse -Force |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +# Use plugin.xml: Kotlin version (with actions) or minimal .NET-only version |
| 140 | +$pluginMetaInf = Join-Path $PLUGIN_DIR 'META-INF' |
| 141 | +if ($KOTLIN_BUILT) { |
| 142 | + Copy-Item "rider\src\main\resources\META-INF\plugin.xml" $pluginMetaInf -Force |
| 143 | +} else { |
| 144 | + Copy-Item "src\$PLUGIN_NAME\META-INF\plugin.xml" $pluginMetaInf -Force |
| 145 | + Write-Host ' Note: Kotlin frontend not included - use Find Action (Ctrl+Shift+A) or External Tool.' |
| 146 | +} |
| 147 | + |
| 148 | +# Add dotnet backend |
| 149 | +$binPath = Join-Path (Join-Path (Join-Path (Join-Path 'src' $PLUGIN_NAME) 'bin') $CONFIGURATION) 'netstandard2.0' |
| 150 | +$pluginDotnet = Join-Path $PLUGIN_DIR 'dotnet' |
| 151 | +Copy-Item (Join-Path $binPath ($PLUGIN_NAME + '.dll')) $pluginDotnet -Force |
| 152 | +$pdbPath = Join-Path $binPath ($PLUGIN_NAME + '.pdb') |
| 153 | +if (Test-Path $pdbPath) { Copy-Item $pdbPath $pluginDotnet -Force } |
| 154 | + |
| 155 | +# Create zip |
| 156 | +$zipPath = Join-Path $OUTPUT_DIR $ZIP_NAME |
| 157 | +if (Test-Path $zipPath) { Remove-Item $zipPath -Force } |
| 158 | +Push-Location $OUTPUT_DIR |
| 159 | +try { |
| 160 | + Compress-Archive -Path $PLUGIN_NAME -DestinationPath $ZIP_NAME -Force |
| 161 | +} finally { |
| 162 | + Pop-Location |
| 163 | +} |
| 164 | +Remove-Item -Path $PLUGIN_DIR -Recurse -Force |
| 165 | + |
| 166 | +Write-Host ('Plugin built: ' + $OUTPUT_DIR + '\' + $ZIP_NAME) |
| 167 | +Write-Host 'Install: Settings -> Plugins -> Gear icon -> Install Plugin from Disk' |
0 commit comments