|
| 1 | +#requires -Module InvokeBuild, PSScriptAnalyzer, Pester, PlatyPS -Version 5.1 |
| 2 | +[CmdletBinding()] |
| 3 | +param( |
| 4 | + [ValidateSet('Debug', 'Release')] |
| 5 | + [string] $Configuration = 'Debug' |
| 6 | +) |
| 7 | + |
| 8 | +$moduleName = 'EditorServicesCommandSuite' |
| 9 | +$manifest = Test-ModuleManifest -Path $PSScriptRoot\module\$moduleName.psd1 -ErrorAction Ignore -WarningAction Ignore |
| 10 | + |
| 11 | +$script:Settings = @{ |
| 12 | + Name = $moduleName |
| 13 | + Manifest = $manifest |
| 14 | + Version = $manifest.Version |
| 15 | + ShouldAnalyze = $true |
| 16 | + ShouldTest = $true |
| 17 | +} |
| 18 | + |
| 19 | +$script:Folders = @{ |
| 20 | + PowerShell = "$PSScriptRoot\module" |
| 21 | + Release = '{0}\Release\{1}\{2}' -f $PSScriptRoot, $moduleName, $manifest.Version |
| 22 | + Docs = "$PSScriptRoot\docs" |
| 23 | + Test = "$PSScriptRoot\test" |
| 24 | + PesterCC = "$PSScriptRoot\*.psm1", "$PSScriptRoot\Public\*.ps1", "$PSScriptRoot\Private\*.ps1" |
| 25 | +} |
| 26 | + |
| 27 | +$script:Discovery = @{ |
| 28 | + HasDocs = Test-Path ('{0}\{1}\*.md' -f $Folders.Docs, $PSCulture) |
| 29 | + HasTests = Test-Path ('{0}\*.Test.ps1' -f $Folders.Test) |
| 30 | +} |
| 31 | + |
| 32 | +task Clean { |
| 33 | + $releaseFolder = $Folders.Release |
| 34 | + if (Test-Path $releaseFolder) { |
| 35 | + Remove-Item $releaseFolder -Recurse |
| 36 | + } |
| 37 | + New-Item -ItemType Directory $releaseFolder | Out-Null |
| 38 | + New-Item -ItemType Directory $releaseFolder/bin/Desktop | Out-Null |
| 39 | + New-Item -ItemType Directory $releaseFolder/bin/Core | Out-Null |
| 40 | + New-Item -ItemType Directory $releaseFolder/RefactorCmdlets | Out-Null |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +task BuildDocs -If { $Discovery.HasDocs } { |
| 45 | + $output = '{0}\{1}' -f $Folders.Release, $PSCulture |
| 46 | + $null = New-ExternalHelp -Path $PSScriptRoot\docs\$PSCulture -OutputPath $output |
| 47 | +} |
| 48 | + |
| 49 | +task AssertDependencies AssertPSES, AssertPSRL |
| 50 | + |
| 51 | +task AssertPSES { |
| 52 | + & "$PSScriptRoot\tools\AssertPSES.ps1" |
| 53 | +} |
| 54 | + |
| 55 | +task AssertPSRL { |
| 56 | + & "$PSScriptRoot\tools\AssertPSRL.ps1" |
| 57 | +} |
| 58 | + |
| 59 | +task AssertPSResGen { |
| 60 | + # Download the ResGen tool used by PowerShell core internally. This will need to be replaced |
| 61 | + # when the dotnet cli gains support for it. |
| 62 | + # The SHA in the uri's are for the 6.0.2 release commit. |
| 63 | + if (-not (Test-Path $PSScriptRoot/tools/ResGen)) { |
| 64 | + New-Item -ItemType Directory $PSScriptRoot/tools/ResGen | Out-Null |
| 65 | + } |
| 66 | + |
| 67 | + if (-not (Test-Path $PSScriptRoot/tools/ResGen/Program.cs)) { |
| 68 | + $programUri = 'https://raw.githubusercontent.com/PowerShell/PowerShell/36b71ba39e36be3b86854b3551ef9f8e2a1de5cc/src/ResGen/Program.cs' |
| 69 | + Invoke-WebRequest $programUri -OutFile $PSScriptRoot/tools/ResGen/Program.cs -ErrorAction Stop |
| 70 | + } |
| 71 | + |
| 72 | + if (-not (Test-Path $PSScriptRoot/tools/ResGen/ResGen.csproj)) { |
| 73 | + $projUri = 'https://raw.githubusercontent.com/PowerShell/PowerShell/36b71ba39e36be3b86854b3551ef9f8e2a1de5cc/src/ResGen/ResGen.csproj' |
| 74 | + Invoke-WebRequest $projUri -OutFile $PSScriptRoot/tools/ResGen/ResGen.csproj -ErrorAction Stop |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +task ResGenImpl { |
| 79 | + Push-Location $PSScriptRoot/src/EditorServicesCommandSuite |
| 80 | + try { |
| 81 | + dotnet run --project $PSScriptRoot/tools/ResGen/ResGen.csproj |
| 82 | + } finally { |
| 83 | + Pop-Location |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +task BuildManaged { |
| 88 | + $script:dotnet = $dotnet = & $PSScriptRoot\tools\GetDotNet.ps1 -Unix:$Discover.IsUnix |
| 89 | + if (!$Discovery.IsUnix) { |
| 90 | + & $dotnet build --framework net462 --configuration $Configuration --verbosity q -nologo |
| 91 | + } |
| 92 | + |
| 93 | + & $dotnet build --framework netcoreapp2.0 --configuration $Configuration --verbosity q -nologo |
| 94 | +} |
| 95 | + |
| 96 | +task BuildRefactorModule { |
| 97 | + $releaseFolder = $Folders.Release |
| 98 | + $dllToImport = if ('Core' -eq $PSEdition) { |
| 99 | + "$PSScriptRoot/src/EditorServicesCommandSuite/bin/$Configuration/netcoreapp2.0/EditorServicesCommandSuite.dll" |
| 100 | + } else { |
| 101 | + "$PSScriptRoot/src/EditorServicesCommandSuite/bin/$Configuration/net462/EditorServicesCommandSuite.dll" |
| 102 | + } |
| 103 | + |
| 104 | + $script = { |
| 105 | + Add-Type -Path '{0}' |
| 106 | + [EditorServicesCommandSuite.Internal.CommandSuite]::WriteRefactorModule('{1}') |
| 107 | + }.ToString() -f $dllToImport, "$releaseFolder\RefactorCmdlets\RefactorCmdlets.cdxml" |
| 108 | + |
| 109 | + $encodedScript = [convert]::ToBase64String( |
| 110 | + [System.Text.Encoding]::Unicode.GetBytes($script)) |
| 111 | + |
| 112 | + if ('Core' -eq $PSEdition) { |
| 113 | + pwsh -NoProfile -EncodedCommand $encodedScript |
| 114 | + } else { |
| 115 | + powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encodedScript |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +task CopyToRelease { |
| 120 | + $moduleName = $Settings.Name |
| 121 | + & "$PSScriptRoot\tools\BuildMonolith.ps1" -OutputPath $Folders.Release -ModuleName $Settings.Name |
| 122 | + |
| 123 | + "$moduleName.psd1", |
| 124 | + 'en-US' | ForEach-Object { |
| 125 | + Join-Path $Folders.PowerShell -ChildPath $PSItem | |
| 126 | + Copy-Item -Destination $Folders.Release -Recurse |
| 127 | + } |
| 128 | + |
| 129 | + $releaseFolder = $Folders.Release |
| 130 | + Copy-Item $PSScriptRoot/src/EditorServicesCommandSuite/bin/$Configuration/net462/EditorServicesCommandSuite.* -Destination $releaseFolder/bin/Desktop |
| 131 | + Copy-Item $PSScriptRoot/src/EditorServicesCommandSuite.EditorServices/bin/$Configuration/net462/EditorServicesCommandSuite.* -Destination $releaseFolder/bin/Desktop |
| 132 | + Copy-Item $PSScriptRoot/src/EditorServicesCommandSuite.PSReadLine/bin/$Configuration/net462/EditorServicesCommandSuite.* -Destination $releaseFolder/bin/Desktop |
| 133 | + Copy-Item $PSScriptRoot/src/EditorServicesCommandSuite/bin/$Configuration/netcoreapp2.0/EditorServicesCommandSuite.* -Destination $releaseFolder/bin/Core |
| 134 | + Copy-Item $PSScriptRoot/src/EditorServicesCommandSuite.EditorServices/bin/$Configuration/netcoreapp2.0/EditorServicesCommandSuite.* -Destination $releaseFolder/bin/Core |
| 135 | + Copy-Item $PSScriptRoot/src/EditorServicesCommandSuite.PSReadLine/bin/$Configuration/netcoreapp2.0/EditorServicesCommandSuite.* -Destination $releaseFolder/bin/Core |
| 136 | +} |
| 137 | + |
| 138 | +task Analyze -If { $Settings.ShouldAnalyze } { |
| 139 | + Invoke-ScriptAnalyzer -Path $Folders.Release -Settings $PSScriptRoot\ScriptAnalyzerSettings.psd1 -Recurse |
| 140 | +} |
| 141 | + |
| 142 | +task Test -If { $Discovery.HasTests -and $Settings.ShouldTest } { |
| 143 | + Invoke-Pester -PesterOption @{ IncludeVSCodeMarker = $true } |
| 144 | +} |
| 145 | + |
| 146 | +task DoInstall { |
| 147 | + $installBase = $Home |
| 148 | + if ($profile) { $installBase = $profile | Split-Path } |
| 149 | + $installPath = '{0}\Modules\{1}\{2}' -f $installBase, $Settings.Name, $Settings.Version |
| 150 | + |
| 151 | + if (-not (Test-Path $installPath)) { |
| 152 | + $null = New-Item $installPath -ItemType Directory |
| 153 | + } |
| 154 | + |
| 155 | + Copy-Item -Path ('{0}\*' -f $Folders.Release) -Destination $installPath -Force -Recurse |
| 156 | +} |
| 157 | + |
| 158 | +task DoPublish { |
| 159 | + if (-not (Test-Path $env:USERPROFILE\.PSGallery\apikey.xml)) { |
| 160 | + throw 'Could not find PSGallery API key!' |
| 161 | + } |
| 162 | + |
| 163 | + $apiKey = (Import-Clixml $env:USERPROFILE\.PSGallery\apikey.xml).GetNetworkCredential().Password |
| 164 | + Publish-Module -Name $Folders.Release -NuGetApiKey $apiKey -Confirm |
| 165 | +} |
| 166 | + |
| 167 | +task ResGen -Jobs AssertPSResGen, ResGenImpl |
| 168 | + |
| 169 | +task Build -Jobs Clean, AssertDependencies, ResGen, BuildManaged, BuildRefactorModule, CopyToRelease, BuildDocs |
| 170 | + |
| 171 | +task PreRelease -Jobs Build, Analyze, Test |
| 172 | + |
| 173 | +task Install -Jobs PreRelease, DoInstall |
| 174 | + |
| 175 | +task Publish -Jobs PreRelease, DoPublish |
| 176 | + |
| 177 | +task . Build |
| 178 | + |
0 commit comments