|
| 1 | + |
| 2 | +<#PSScriptInfo |
| 3 | +
|
| 4 | +.VERSION 1.0.0 |
| 5 | +
|
| 6 | +.GUID 6312d879-4b8c-4d88-aa39-bf245069148e |
| 7 | +
|
| 8 | +.AUTHOR Markus Szumovski |
| 9 | +
|
| 10 | +.COMPANYNAME - |
| 11 | +
|
| 12 | +.COPYRIGHT 2021 |
| 13 | +
|
| 14 | +.TAGS |
| 15 | +
|
| 16 | +.LICENSEURI |
| 17 | +
|
| 18 | +.PROJECTURI |
| 19 | +
|
| 20 | +.ICONURI |
| 21 | +
|
| 22 | +.EXTERNALMODULEDEPENDENCIES |
| 23 | +
|
| 24 | +.REQUIREDSCRIPTS |
| 25 | +
|
| 26 | +.EXTERNALSCRIPTDEPENDENCIES |
| 27 | +
|
| 28 | +.RELEASENOTES |
| 29 | +V 1.0.0: Initial version |
| 30 | +
|
| 31 | +.PRIVATEDATA |
| 32 | +
|
| 33 | +#> |
| 34 | + |
| 35 | +<# |
| 36 | +
|
| 37 | +.SYNOPSIS |
| 38 | + Will build the extension. |
| 39 | +.DESCRIPTION |
| 40 | + Will build the extension. |
| 41 | +.PARAMETER ExtensionRepositoryRoot |
| 42 | + The path to the extension repository root from where to build the extension from. |
| 43 | + Will default to parent directory of script if no path or $null was provided. |
| 44 | +.PARAMETER BuildEnvironment |
| 45 | + Set to "Release" for production environment or set to anything else (for example "Development") for development environment. |
| 46 | + If nothing was provided the Release environment will be built. |
| 47 | +.PARAMETER BuildVersion |
| 48 | + If provided will set the version number. |
| 49 | + If not provided the version number will not be changed. |
| 50 | +.PARAMETER NoPackaging |
| 51 | + If the switch was provided, the built extension will not be packaged up into a vsix file. |
| 52 | +.OUTPUTS |
| 53 | + Building and packaging progress |
| 54 | + |
| 55 | +.EXAMPLE |
| 56 | + Build-Extension -BuildVersion "6.1.0.1" -BuildEnvironment "Release" |
| 57 | +#> |
| 58 | +[CmdletBinding(SupportsShouldProcess=$True)] |
| 59 | +Param |
| 60 | +( |
| 61 | + [Parameter(Position=0)] |
| 62 | + [string] $ExtensionRepositoryRoot = $null, |
| 63 | + [Parameter(Position=1)] |
| 64 | + [string] $BuildEnvironment = "Release", |
| 65 | + [Parameter(Position=2)] |
| 66 | + [string] $BuildVersion = $null, |
| 67 | + [Parameter(Position=3)] |
| 68 | + [switch] $NoPackaging |
| 69 | + |
| 70 | +) |
| 71 | + |
| 72 | +### --- START --- functions |
| 73 | +### --- END --- functions |
| 74 | + |
| 75 | +### --- START --- main script ### |
| 76 | +try { |
| 77 | + Write-Host "--- Build extension script started ---`r`n`r`n" -ForegroundColor DarkGreen |
| 78 | + |
| 79 | + if([string]::IsNullOrWhiteSpace($ExtensionRepositoryRoot)) { |
| 80 | + Write-Host "No extension repository root provided, determining path now..." |
| 81 | + $ExtensionRepositoryRoot = Split-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Path -Parent -ErrorAction Stop) -Parent -ErrorAction Stop |
| 82 | + Write-Host "" |
| 83 | + } |
| 84 | + else { |
| 85 | + $ExtensionRepositoryRoot = Resolve-Path -Path $ExtensionRepositoryRoot -ErrorAction Ignore |
| 86 | + } |
| 87 | + |
| 88 | + if([string]::IsNullOrWhiteSpace($BuildEnvironment)) { |
| 89 | + $BuildEnvironment = "Release" |
| 90 | + } |
| 91 | + |
| 92 | + # Set build env vars |
| 93 | + if ($BuildEnvironment -eq "Release") { |
| 94 | + $TaskId = "47EA1F4A-57BA-414A-B12E-C44F42765E72" |
| 95 | + $TaskName = "dependency-check-build-task" |
| 96 | + $VssExtensionName = "vss-extension.prod.json" |
| 97 | + } |
| 98 | + else { |
| 99 | + $TaskId = "04450B31-9F11-415A-B37A-514D69EF69A1" |
| 100 | + $TaskName = "dependency-check-build-task-dev" |
| 101 | + $VssExtensionName = "vss-extension.dev.json" |
| 102 | + } |
| 103 | + |
| 104 | + $ExtensionRepositoryRootExists = Test-Path -Path $ExtensionRepositoryRoot -ErrorAction Ignore |
| 105 | + |
| 106 | + if($ExtensionRepositoryRootExists) { |
| 107 | + $TaskFolderPath = Join-Path -Path $ExtensionRepositoryRoot -ChildPath "src\Tasks\dependency-check-build-task" -ErrorAction Stop |
| 108 | + |
| 109 | + $TaskDefPath = Join-Path -Path $TaskFolderPath -ChildPath "task.json" -ErrorAction Stop |
| 110 | + $TaskDefExists = Test-Path -Path $TaskDefPath -ErrorAction Ignore |
| 111 | + |
| 112 | + $VssExtensionPath = Join-Path -Path $ExtensionRepositoryRoot -ChildPath $VssExtensionName -ErrorAction Stop |
| 113 | + $VssExtensionExists = Test-Path -Path $VssExtensionPath -ErrorAction Ignore |
| 114 | + } |
| 115 | + else { |
| 116 | + $TaskFolderPath = $null |
| 117 | + $TaskDefPath = $null |
| 118 | + $TaskDefExists = $false |
| 119 | + $VssExtensionPath = $null |
| 120 | + $VssExtensionExists = $false |
| 121 | + } |
| 122 | + |
| 123 | + #Parse version vars |
| 124 | + $VerPatchRevision = $null |
| 125 | + if(![string]::IsNullOrWhiteSpace($BuildVersion)) { |
| 126 | + $VerMajor,$VerMinor,$VerPatch,$VerRevision = $BuildVersion.Split('.') |
| 127 | + if($null -eq $VerMajor) { |
| 128 | + $VerMajor = 0 |
| 129 | + } |
| 130 | + if($null -eq $VerMinor) { |
| 131 | + $VerMinor = 0 |
| 132 | + } |
| 133 | + if($null -eq $VerPatch) { |
| 134 | + $VerPatch = 0 |
| 135 | + } |
| 136 | + if($null -eq $VerRevision) { |
| 137 | + $VerRevision = 0 |
| 138 | + } |
| 139 | + $VerPatchRevision = [string]::Format("{0}{1}", $VerPatch, $VerRevision.PadLeft(3, '0')) |
| 140 | + $BuildVersion = "$VerMajor.$VerMinor.$VerPatch.$VerRevision" |
| 141 | + $BuildTaskVersion = "$VerMajor.$VerMinor.$VerPatchRevision" |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + Write-Host "------------------------------" |
| 146 | + |
| 147 | + Write-Host "Extension repository root: ""$ExtensionRepositoryRoot"" (" -NoNewline |
| 148 | + if($ExtensionRepositoryRootExists) { |
| 149 | + Write-Host "exists" -ForegroundColor Green -NoNewline |
| 150 | + } |
| 151 | + else { |
| 152 | + Write-Host "missing" -ForegroundColor Red -NoNewline |
| 153 | + } |
| 154 | + Write-Host ")" |
| 155 | + |
| 156 | + Write-Host "Task definition JSON: ""$TaskDefPath"" (" -NoNewline |
| 157 | + if($TaskDefExists) { |
| 158 | + Write-Host "exists" -ForegroundColor Green -NoNewline |
| 159 | + } |
| 160 | + else { |
| 161 | + Write-Host "missing" -ForegroundColor Red -NoNewline |
| 162 | + } |
| 163 | + Write-Host ")" |
| 164 | + |
| 165 | + Write-Host "VSS extension JSON: ""$VssExtensionPath"" (" -NoNewline |
| 166 | + if($VssExtensionExists) { |
| 167 | + Write-Host "exists" -ForegroundColor Green -NoNewline |
| 168 | + } |
| 169 | + else { |
| 170 | + Write-Host "missing" -ForegroundColor Red -NoNewline |
| 171 | + } |
| 172 | + Write-Host ")" |
| 173 | + |
| 174 | + Write-Host "Build environment: $BuildEnvironment" |
| 175 | + if([string]::IsNullOrWhiteSpace($BuildVersion)) { |
| 176 | + Write-Host "Build version: <none defined>" |
| 177 | + } |
| 178 | + else { |
| 179 | + Write-Host "Build version: $BuildVersion" |
| 180 | + Write-Host "Build-Task version: $BuildTaskVersion" |
| 181 | + } |
| 182 | + |
| 183 | + Write-Host "Task-Id: $TaskId" |
| 184 | + Write-Host "Task-Name: $TaskName" |
| 185 | + Write-Host "VSS extension JSON: $VssExtensionName" |
| 186 | + |
| 187 | + Write-Host "------------------------------`r`n" |
| 188 | + |
| 189 | + if($ExtensionRepositoryRootExists) { |
| 190 | + if($TaskDefExists) { |
| 191 | + |
| 192 | + Write-Host "Reading task.json..." |
| 193 | + $TaskJson = Get-Content -Path $TaskDefPath -Raw | ConvertFrom-Json |
| 194 | + |
| 195 | + Write-Host "Setting task definition id and name..." |
| 196 | + $TaskJson.id = $TaskId |
| 197 | + $TaskJson.name = $TaskName |
| 198 | + |
| 199 | + if([string]::IsNullOrWhiteSpace($BuildVersion)) { |
| 200 | + Write-Host "(Skipping setting of task definition version since no version was provided)" |
| 201 | + } |
| 202 | + else { |
| 203 | + Write-Host "Setting task definition version..." |
| 204 | + $TaskJson.version.Major = $VerMajor |
| 205 | + $TaskJson.version.Minor = $VerMinor |
| 206 | + $TaskJson.version.Patch = $VerPatchRevision |
| 207 | + } |
| 208 | + |
| 209 | + Write-Host "Saving new task definition..." |
| 210 | + $TaskJson | ConvertTo-Json -Depth 100 | Set-Content -Path $TaskDefPath |
| 211 | + |
| 212 | + if([string]::IsNullOrWhiteSpace($BuildVersion)) { |
| 213 | + Write-Host "(Skipping setting of extension version since no version was provided)" |
| 214 | + } |
| 215 | + else { |
| 216 | + Write-Host "Reading ""$VssExtensionName""..." |
| 217 | + $VssExtensionJson = Get-Content -Path $VssExtensionPath -Raw | ConvertFrom-Json |
| 218 | + |
| 219 | + Write-Host "Setting version" |
| 220 | + $VssExtensionJson.version = $BuildVersion |
| 221 | + |
| 222 | + Write-Host "Saving new extension definition..." |
| 223 | + $VssExtensionJson | ConvertTo-Json -Depth 100 | Set-Content $VssExtensionPath |
| 224 | + } |
| 225 | + |
| 226 | + Write-Host "`r`nBuilding task..." |
| 227 | + Write-Host "------------------------------" |
| 228 | + Push-Location |
| 229 | + Set-Location -Path $TaskFolderPath |
| 230 | + &"npm" install |
| 231 | + &"npm" run build |
| 232 | + Pop-Location |
| 233 | + Write-Host "------------------------------" |
| 234 | + Write-Host "`r`nBuilding extension..." |
| 235 | + Write-Host "------------------------------" |
| 236 | + &"npm" install |
| 237 | + &"npm" run build |
| 238 | + Write-Host "------------------------------" |
| 239 | + |
| 240 | + if(!$NoPackaging.IsPresent) { |
| 241 | + Write-Host "`r`nPackaging..." |
| 242 | + if($BuildEnvironment -eq "Release") { |
| 243 | + &"npm" run package-prod |
| 244 | + } |
| 245 | + else { |
| 246 | + &"npm" run package-dev |
| 247 | + } |
| 248 | + |
| 249 | + Write-Host "`r`nBuilding and packaging extension..." -NoNewline |
| 250 | + } |
| 251 | + else { |
| 252 | + Write-Host "`r`nBuilding extension..." -NoNewline |
| 253 | + } |
| 254 | + |
| 255 | + Write-Host "DONE" -ForegroundColor Green |
| 256 | + } |
| 257 | + else { |
| 258 | + Write-Warning "Task.json not found, cannot continue" |
| 259 | + } |
| 260 | + } |
| 261 | + else { |
| 262 | + Write-Warning "Extension repository root not found, cannot continue" |
| 263 | + } |
| 264 | +} |
| 265 | +finally { |
| 266 | + Write-Host "`r`n`r`n--- Build extension script ended ---" -ForegroundColor DarkGreen |
| 267 | +} |
| 268 | + |
| 269 | +#and we're at the end |
| 270 | + |
| 271 | +### --- END --- main script ### |
0 commit comments