@@ -18,42 +18,96 @@ $testModuleManifestSplat = @{
1818}
1919
2020$manifest = Test-ModuleManifest @testModuleManifestSplat
21-
22- $script :Settings = @ {
23- Name = $moduleName
24- Manifest = $manifest
25- Version = $manifest.Version
26- ShouldTest = $true
27- }
28-
29- $script :Folders = @ {
30- PowerShell = " $PSScriptRoot \module"
31- CSharp = " $PSScriptRoot \src"
32- Build = ' {0}\src\{1}\bin\{2}' -f $PSScriptRoot , $moduleName , $Configuration
33- Release = ' {0}\Release\{1}\{2}' -f $PSScriptRoot , $moduleName , $manifest.Version
34- Docs = " $PSScriptRoot \docs"
35- Test = " $PSScriptRoot \test"
36- Results = " $PSScriptRoot \testresults"
37- }
38-
39- $script :Discovery = @ {
40- HasDocs = Test-Path (' {0}\{1}\*.md' -f $Folders.Docs , $PSCulture )
41- HasTests = Test-Path (' {0}\*.Tests.ps1' -f $Folders.Test )
42- IsUnix = $PSVersionTable.PSEdition -eq " Core" -and -not $IsWindows
43- }
21+ $moduleVersion = $manifest.Version
4422
4523$tools = " $PSScriptRoot \tools"
4624$script :GetDotNet = Get-Command $tools \GetDotNet.ps1
4725$script :AssertModule = Get-Command $tools \AssertRequiredModule.ps1
4826$script :GetOpenCover = Get-Command $tools \GetOpenCover.ps1
4927$script :GenerateSignatureMarkdown = Get-Command $tools \GenerateSignatureMarkdown.ps1
5028
29+ function RemakeFolder {
30+ [CmdletBinding ()]
31+ param (
32+ [ValidateNotNullOrEmpty ()]
33+ [string ] $LiteralPath
34+ )
35+ end {
36+ $ErrorActionPreference = ' Stop'
37+ if (Test-Path - LiteralPath $LiteralPath ) {
38+ Remove-Item - LiteralPath $LiteralPath - Recurse
39+ }
40+
41+ $null = New-Item - ItemType Directory - Path $LiteralPath
42+ }
43+ }
44+
45+ function GetArtifactPath {
46+ [CmdletBinding ()]
47+ param (
48+ [ValidateNotNullOrEmpty ()]
49+ [string ] $FileName ,
50+
51+ [switch ] $Legacy
52+ )
53+ end {
54+ $moduleName = $script :ModuleName
55+ $config = $script :Configuration
56+ $legacyTarget = $script :LegacyTarget
57+ $modernTarget = $script :ModernTarget
58+
59+ $target = $modernTarget
60+ if ($Legacy ) {
61+ $target = $legacyTarget
62+ }
63+
64+ if (-not $FileName ) {
65+ return " ./artifacts/publish/$moduleName /${config} _${target} "
66+ }
67+
68+ return " ./artifacts/publish/$moduleName /${config} _${target} /$FileName "
69+ }
70+ }
71+
72+ task GetProjectInfo {
73+ $script :ModernTarget = $null
74+ $script :LegacyTarget = $null
75+ if (Test-Path - LiteralPath ./ Directory.Build.props) {
76+ $content = Get-Content - Raw - LiteralPath ./ Directory.Build.props
77+ if ($content -match ' <ModernTarget>(?<target>[^<]+)</ModernTarget>' ) {
78+ $script :ModernTarget = $matches [' target' ]
79+ }
80+
81+ if ($content -match ' <LegacyTarget>(?<target>[^<]+)</LegacyTarget>' ) {
82+ $script :LegacyTarget = $matches [' target' ]
83+ }
84+ }
85+
86+
87+ $script :ModuleName = $ModuleName = ' ClassExplorer'
88+ $testModuleManifestSplat = @ {
89+ ErrorAction = ' Ignore'
90+ WarningAction = ' Ignore'
91+ Path = " ./module/$ModuleName .psd1"
92+ }
93+
94+ $manifest = Test-ModuleManifest @testModuleManifestSplat
95+ $script :ModuleVersion = $manifest.Version
96+ $script :_IsWindows = $true
97+ $runtimeInfoType = ' System.Runtime.InteropServices.RuntimeInformation' -as [type ]
98+ try {
99+ if ($null -ne $runtimeInfoType ) {
100+ $script :_IsWindows = $runtimeInfoType ::IsOSPlatform([System.Runtime.InteropServices.OSPlatform ]::Windows)
101+ }
102+ } catch { }
103+ }
104+
51105task AssertDotNet {
52- $script :dotnet = & $GetDotNet - Unix:$Discovery .IsUnix
106+ $script :dotnet = & $GetDotNet - Unix:( -not $ script :_IsWindows )
53107}
54108
55109task AssertOpenCover - If { $GenerateCodeCoverage.IsPresent } {
56- if ($Discovery .IsUnix ) {
110+ if (-not $ script :_IsWindows ) {
57111 Write-Warning ' Generating code coverage from .NET core is currently unsupported, disabling code coverage generation.'
58112 $script :GenerateCodeCoverage = $false
59113 return
@@ -63,66 +117,77 @@ task AssertOpenCover -If { $GenerateCodeCoverage.IsPresent } {
63117}
64118
65119task AssertRequiredModules {
66- & $AssertModule Pester 5.3 . 0 - Force:$Force.IsPresent
67- & $AssertModule InvokeBuild 5.8 . 4 - Force:$Force.IsPresent
120+ & $AssertModule Pester 5.7 . 1 - Force:$Force.IsPresent
121+ & $AssertModule InvokeBuild 5.14 . 22 - Force:$Force.IsPresent
68122 & $AssertModule platyPS 0.14 .2 - Force:$Force.IsPresent
69- & $AssertModule Yayaml 0.1 . 1 - Force:$Force.IsPresent
123+ & $AssertModule Yayaml 0.7 . 0 - Force:$Force.IsPresent
70124}
71125
72126task AssertDevDependencies - Jobs AssertDotNet, AssertOpenCover, AssertRequiredModules
73127
74128task Clean {
75- if ($PSScriptRoot -and (Test-Path $PSScriptRoot \Release)) {
76- Remove-Item $PSScriptRoot \Release - Recurse
77- }
78-
79- $null = New-Item $Folders.Release - ItemType Directory
80- if (Test-Path $Folders.Results ) {
81- Remove-Item $Folders.Results - Recurse
82- }
83-
84- $null = New-Item $Folders.Results - ItemType Directory
129+ RemakeFolder ./ Release
130+ RemakeFolder ./ testresults
85131 & $dotnet clean -- verbosity quiet - nologo
86132}
87133
88- task BuildDocs - If { $Discovery.HasDocs } {
89- $sourceDocs = " $PSScriptRoot \docs\$PSCulture "
90- $releaseDocs = ' {0}\{1}' -f $Folders.Release , $PSCulture
134+ task BuildDocs - If { Test-Path ./ docs/ $PSCulture /* .md } {
135+ $releaseDocs = " ./Release/ClassExplorer/$moduleVersion "
136+ $null = New-Item $releaseDocs / $PSCulture - ItemType Directory - Force - ErrorAction Ignore
137+ $null = New-ExternalHelp - Path ./ docs/ $PSCulture - OutputPath $releaseDocs / $PSCulture
91138
92- $null = New-Item $releaseDocs - ItemType Directory - Force - ErrorAction SilentlyContinue
93- $null = New-ExternalHelp - Path $sourceDocs - OutputPath $releaseDocs
94-
95- & $GenerateSignatureMarkdown.Source - AboutHelp $releaseDocs \about_Type_Signatures.help.txt
96- & $GenerateSignatureMarkdown.Source $PSScriptRoot \docs\en- US\about_Type_Signatures.help.md
139+ & $GenerateSignatureMarkdown.Source - AboutHelp $releaseDocs / about_Type_Signatures.help.txt
140+ & $GenerateSignatureMarkdown.Source ./ docs/ en- US/ about_Type_Signatures.help.md
97141}
98142
99143task BuildDll {
100- if (-not $Discovery .IsUnix ) {
101- & $dotnet publish -- configuration $Configuration -- framework net471 -- verbosity quiet - nologo
144+ if ($ script :_IsWindows ) {
145+ & $dotnet publish -- configuration $Configuration -- framework $ script :LegacyTarget -- verbosity quiet - nologo
102146 }
103- & $dotnet publish -- configuration $Configuration -- framework netcoreapp3.1 -- verbosity quiet - nologo
147+
148+ & $dotnet publish -- configuration $Configuration -- framework $script :ModernTarget -- verbosity quiet - nologo
104149}
105150
106151task CopyToRelease {
107- $powershellSource = ' {0}\*' -f $Folders.PowerShell
108- $release = $Folders.Release
109- $releaseDesktopBin = " $release \bin\Desktop"
110- $releaseCoreBin = " $release \bin\Core"
111- $sourceDesktopBin = ' {0}\net471\publish\*' -f $Folders.Build
112- $sourceCoreBin = ' {0}\netcoreapp3.1\publish\*' -f $Folders.Build
113- Copy-Item - Path $powershellSource - Destination $release - Recurse - Force
152+ $version = $script :ModuleVersion
153+ $modern = $script :ModernTarget
154+ $legacy = $script :LegacyTarget
114155
115- if ( -not $Discovery .IsUnix ) {
116- $null = New-Item $releaseDesktopBin - Force - ItemType Directory
117- Copy-Item - Path $sourceDesktopBin - Destination $releaseDesktopBin - Force
156+ $releasePath = " ./Release/ClassExplorer/ $version "
157+ if ( -not ( Test-Path - LiteralPath $releasePath )) {
158+ $null = New-Item $releasePath - ItemType Directory
118159 }
119160
120- $null = New-Item $releaseCoreBin - Force - ItemType Directory
121- Copy-Item - Path $sourceCoreBin - Destination $releaseCoreBin - Force
161+ Copy-Item - Path ./ module/* - Destination $releasePath - Recurse - Force
162+
163+ if ($script :_IsWindows ) {
164+ $null = New-Item $releasePath / bin/ Legacy - Force - ItemType Directory
165+ $legacyFiles = (
166+ ' ClassExplorer.dll' ,
167+ ' ClassExplorer.pdb' ,
168+ ' System.Buffers.dll' ,
169+ ' System.Collections.Immutable.dll' ,
170+ ' System.Memory.dll' ,
171+ ' System.Numerics.Vectors.dll' ,
172+ ' System.Runtime.CompilerServices.Unsafe.dll' )
173+
174+ foreach ($file in $legacyFiles ) {
175+ Copy-Item - Force - LiteralPath ./ artifacts/ publish/ ClassExplorer/ ${Configuration} _ $legacy / $file - Destination $releasePath / bin/ Legacy
176+ }
177+ }
178+
179+ $null = New-Item $releasePath / bin/ Modern - Force - ItemType Directory
180+ $modernFiles = (
181+ ' ClassExplorer.dll' ,
182+ ' ClassExplorer.pdb' ,
183+ ' ClassExplorer.deps.json' )
184+ foreach ($file in $modernFiles ) {
185+ Copy-Item - Force - LiteralPath ./ artifacts/ publish/ ClassExplorer/ ${Configuration} _ $modern / $file - Destination $releasePath / bin/ Modern
186+ }
122187}
123188
124- task DoTest - If { $Discovery .HasTests -and $Settings .ShouldTest } {
125- if ($Discovery .IsUnix ) {
189+ task DoTest - If { Test-Path . / test /* .ps1 } {
190+ if (-not $ script :_IsWindows ) {
126191 $scriptString = '
127192 $projectPath = "{0}"
128193 Invoke-Pester "$projectPath" -OutputFormat NUnitXml -OutputFile "$projectPath\testresults\pester.xml"
@@ -141,16 +206,16 @@ task DoTest -If { $Discovery.HasTests -and $Settings.ShouldTest } {
141206 $scriptString ))
142207
143208 $powershellCommand = ' powershell'
144- if ($Discovery .IsUnix ) {
209+ if ($PSVersionTable .PSVersion.Major -gt 5 ) {
145210 $powershellCommand = ' pwsh'
146211 }
147212
148- $powershell = (Get-Command $powershellCommand ).Source
213+ $powershell = (Get-Command - CommandType Application $powershellCommand ).Source
149214
150215 if ($GenerateCodeCoverage.IsPresent ) {
151216 # OpenCover needs full pdb's. I'm very open to suggestions for streamlining this...
152217 # & $dotnet clean
153- & $dotnet publish -- configuration $Configuration -- framework net471 -- verbosity quiet - nologo / p:DebugType= Full
218+ & $dotnet publish -- configuration $Configuration -- framework $ script :LegacyTarget -- verbosity quiet - - nologo / p:DebugType= Full
154219
155220 $moduleName = $Settings.Name
156221 $release = ' {0}\bin\Desktop\{1}' -f $Folders.Release , $moduleName
@@ -212,7 +277,7 @@ task DoPublish {
212277 Publish-Module - Name $Folders.Release - NuGetApiKey $apiKey - Force:$Force.IsPresent
213278}
214279
215- task Build - Jobs AssertDevDependencies, Clean , BuildDll, CopyToRelease, BuildDocs
280+ task Build - Jobs GetProjectInfo , AssertDevDependencies, Clean , BuildDll, CopyToRelease, BuildDocs
216281
217282task Test - Jobs Build, DoTest
218283
0 commit comments