|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Copyright Microsoft Corporation |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ---------------------------------------------------------------------------------- |
| 14 | +param([switch]$Isolated, [switch]$Run, [switch]$Test, [switch]$Docs, [switch]$Pack, [switch]$Code, [switch]$Release, [switch]$Debugger, [switch]$NoDocs) |
| 15 | +$ErrorActionPreference = 'Stop' |
| 16 | + |
| 17 | +if($PSEdition -ne 'Core') { |
| 18 | + Write-Error 'This script requires PowerShell Core to execute. [Note] Generated cmdlets will work in both PowerShell Core or Windows PowerShell.' |
| 19 | +} |
| 20 | + |
| 21 | +if(-not $Isolated -and -not $Debugger) { |
| 22 | + Write-Host -ForegroundColor Green 'Creating isolated process...' |
| 23 | + $pwsh = [System.Diagnostics.Process]::GetCurrentProcess().Path |
| 24 | + & "$pwsh" -NonInteractive -NoLogo -NoProfile -File $MyInvocation.MyCommand.Path @PSBoundParameters -Isolated |
| 25 | + |
| 26 | + if($LastExitCode -ne 0) { |
| 27 | + # Build failed. Don't attempt to run the module. |
| 28 | + return |
| 29 | + } |
| 30 | + |
| 31 | + if($Test) { |
| 32 | + . (Join-Path $PSScriptRoot 'test-module.ps1') |
| 33 | + if($LastExitCode -ne 0) { |
| 34 | + # Tests failed. Don't attempt to run the module. |
| 35 | + return |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + if($Docs) { |
| 40 | + . (Join-Path $PSScriptRoot 'generate-help.ps1') |
| 41 | + if($LastExitCode -ne 0) { |
| 42 | + # Docs generation failed. Don't attempt to run the module. |
| 43 | + return |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + if($Pack) { |
| 48 | + . (Join-Path $PSScriptRoot 'pack-module.ps1') |
| 49 | + if($LastExitCode -ne 0) { |
| 50 | + # Packing failed. Don't attempt to run the module. |
| 51 | + return |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + $runModulePath = Join-Path $PSScriptRoot 'run-module.ps1' |
| 56 | + if($Code) { |
| 57 | + . $runModulePath -Code |
| 58 | + } elseif($Run) { |
| 59 | + . $runModulePath |
| 60 | + } else { |
| 61 | + Write-Host -ForegroundColor Cyan "To run this module in an isolated PowerShell session, run the 'run-module.ps1' script or provide the '-Run' parameter to this script." |
| 62 | + } |
| 63 | + return |
| 64 | +} |
| 65 | + |
| 66 | +$binFolder = Join-Path $PSScriptRoot 'bin' |
| 67 | +$objFolder = Join-Path $PSScriptRoot 'obj' |
| 68 | + |
| 69 | +if(-not $Debugger) { |
| 70 | + Write-Host -ForegroundColor Green 'Cleaning build folders...' |
| 71 | + $null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path $binFolder, $objFolder |
| 72 | + |
| 73 | + if((Test-Path $binFolder) -or (Test-Path $objFolder)) { |
| 74 | + Write-Host -ForegroundColor Cyan 'Did you forget to exit your isolated module session before rebuilding?' |
| 75 | + Write-Error 'Unable to clean ''bin'' or ''obj'' folder. A process may have an open handle.' |
| 76 | + } |
| 77 | + |
| 78 | + Write-Host -ForegroundColor Green 'Compiling module...' |
| 79 | + $buildConfig = 'Debug' |
| 80 | + if($Release) { |
| 81 | + $buildConfig = 'Release' |
| 82 | + } |
| 83 | + dotnet publish $PSScriptRoot --verbosity quiet --configuration $buildConfig /nologo |
| 84 | + if($LastExitCode -ne 0) { |
| 85 | + Write-Error 'Compilation failed.' |
| 86 | + } |
| 87 | + |
| 88 | + $null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path (Join-Path $binFolder 'Debug'), (Join-Path $binFolder 'Release') |
| 89 | +} |
| 90 | + |
| 91 | +$dll = Join-Path $PSScriptRoot 'bin\Az.HanaOnAzure.private.dll' |
| 92 | +if(-not (Test-Path $dll)) { |
| 93 | + Write-Error "Unable to find output assembly in '$binFolder'." |
| 94 | +} |
| 95 | + |
| 96 | +# Load DLL to use build-time cmdlets |
| 97 | +$null = Import-Module -Name $dll |
| 98 | + |
| 99 | +$modulePaths = $dll |
| 100 | +$customPsm1 = Join-Path $PSScriptRoot 'custom\Az.HanaOnAzure.custom.psm1' |
| 101 | +if(Test-Path $customPsm1) { |
| 102 | + $modulePaths = @($dll, $customPsm1) |
| 103 | +} |
| 104 | + |
| 105 | +$exportsFolder = Join-Path $PSScriptRoot 'exports' |
| 106 | +if(Test-Path $exportsFolder) { |
| 107 | + $null = Get-ChildItem -Path $exportsFolder -Recurse -Exclude 'readme.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue |
| 108 | +} |
| 109 | +$null = New-Item -ItemType Directory -Force -Path $exportsFolder |
| 110 | + |
| 111 | +$internalFolder = Join-Path $PSScriptRoot 'internal' |
| 112 | +if(Test-Path $internalFolder) { |
| 113 | + $null = Get-ChildItem -Path $internalFolder -Recurse -Exclude '*.psm1', 'readme.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue |
| 114 | +} |
| 115 | +$null = New-Item -ItemType Directory -Force -Path $internalFolder |
| 116 | + |
| 117 | +$psd1 = Join-Path $PSScriptRoot './Az.HanaOnAzure.psd1' |
| 118 | +$guid = Get-ModuleGuid -Psd1Path $psd1 |
| 119 | +$moduleName = 'Az.HanaOnAzure' |
| 120 | +$examplesFolder = Join-Path $PSScriptRoot 'examples' |
| 121 | +$null = New-Item -ItemType Directory -Force -Path $examplesFolder |
| 122 | + |
| 123 | +if($NoDocs) { |
| 124 | + Write-Host -ForegroundColor Green 'Creating exports...' |
| 125 | + Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs |
| 126 | +} else { |
| 127 | + Write-Host -ForegroundColor Green 'Creating exports and docs...' |
| 128 | + $moduleDescription = 'Microsoft Azure PowerShell: HanaOn cmdlets' |
| 129 | + $docsFolder = Join-Path $PSScriptRoot 'docs' |
| 130 | + if(Test-Path $docsFolder) { |
| 131 | + $null = Get-ChildItem -Path $docsFolder -Recurse -Exclude 'readme.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue |
| 132 | + } |
| 133 | + $null = New-Item -ItemType Directory -Force -Path $docsFolder |
| 134 | + Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ModuleDescription $moduleDescription -DocsFolder $docsFolder -ExamplesFolder $examplesFolder -ModuleGuid $guid |
| 135 | +} |
| 136 | + |
| 137 | +Write-Host -ForegroundColor Green 'Creating format.ps1xml...' |
| 138 | +$formatPs1xml = Join-Path $PSScriptRoot './Az.HanaOnAzure.format.ps1xml' |
| 139 | +Export-FormatPs1xml -FilePath $formatPs1xml |
| 140 | + |
| 141 | +Write-Host -ForegroundColor Green 'Creating psd1...' |
| 142 | +$customFolder = Join-Path $PSScriptRoot 'custom' |
| 143 | +Export-Psd1 -ExportsFolder $exportsFolder -CustomFolder $customFolder -Psd1Path $psd1 -ModuleGuid $guid |
| 144 | + |
| 145 | +Write-Host -ForegroundColor Green 'Creating test stubs...' |
| 146 | +$testFolder = Join-Path $PSScriptRoot 'test' |
| 147 | +$null = New-Item -ItemType Directory -Force -Path $testFolder |
| 148 | +Export-TestStub -ModuleName $moduleName -ExportsFolder $exportsFolder -OutputFolder $testFolder |
| 149 | + |
| 150 | +Write-Host -ForegroundColor Green 'Creating example stubs...' |
| 151 | +Export-ExampleStub -ExportsFolder $exportsFolder -OutputFolder $examplesFolder |
| 152 | + |
| 153 | +Write-Host -ForegroundColor Green '-------------Done-------------' |
0 commit comments