@@ -18,42 +18,118 @@ $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
22+
23+
24+ # $script:Settings = @{
25+ # Name = $moduleName
26+ # Manifest = $manifest
27+ # Version = $manifest.Version
28+ # ShouldTest = $true
29+ # }
30+
31+ # $script:Folders = @{
32+ # PowerShell = " $PSScriptRoot\module"
33+ # CSharp = " $PSScriptRoot\src"
34+ # Build = '{0}\src\{1}\bin\{2}' -f $PSScriptRoot, $moduleName, $Configuration
35+ # Release = '{0}\Release\{1}\{2}' -f $PSScriptRoot, $moduleName, $manifest.Version
36+ # Docs = "$PSScriptRoot\docs "
37+ # Test = "$PSScriptRoot\test"
38+ # Results = "$PSScriptRoot\testresults"
39+ # }
40+
41+ # HasDocs = Test-Path ('{0}\{1}\*.md ' -f $Folders.Docs, $PSCulture )
42+ # HasTests = Test-Path ('{0}\*.Tests.ps1' -f $Folders.Test)
43+ # $_IsUnix = $PSVersionTable.PSEdition -eq "Core" -and -not $IsWindows
4444
4545$tools = " $PSScriptRoot \tools"
4646$script :GetDotNet = Get-Command $tools \GetDotNet.ps1
4747$script :AssertModule = Get-Command $tools \AssertRequiredModule.ps1
4848$script :GetOpenCover = Get-Command $tools \GetOpenCover.ps1
4949$script :GenerateSignatureMarkdown = Get-Command $tools \GenerateSignatureMarkdown.ps1
5050
51+ function RemakeFolder {
52+ [CmdletBinding ()]
53+ param (
54+ [ValidateNotNullOrEmpty ()]
55+ [string ] $LiteralPath
56+ )
57+ end {
58+ $ErrorActionPreference = ' Stop'
59+ if (Test-Path - LiteralPath $LiteralPath ) {
60+ Remove-Item - LiteralPath $LiteralPath - Recurse
61+ }
62+
63+ $null = New-Item - ItemType Directory - Path $LiteralPath
64+ }
65+ }
66+
67+ function GetArtifactPath {
68+ [CmdletBinding ()]
69+ param (
70+ [ValidateNotNullOrEmpty ()]
71+ [string ] $FileName ,
72+
73+ [switch ] $Legacy
74+ )
75+ end {
76+ $moduleName = $script :ModuleName
77+ $config = $script :Configuration
78+ $legacyTarget = $script :LegacyTarget
79+ $modernTarget = $script :ModernTarget
80+
81+ $target = $modernTarget
82+ if ($Legacy ) {
83+ $target = $legacyTarget
84+ }
85+
86+ if (-not $FileName ) {
87+ return " ./artifacts/publish/$moduleName /${config} _${target} "
88+ }
89+
90+ return " ./artifacts/publish/$moduleName /${config} _${target} /$FileName "
91+ }
92+ }
93+
94+ task GetProjectInfo {
95+ $script :ModernTarget = $null
96+ $script :LegacyTarget = $null
97+ if (Test-Path - LiteralPath ./ Directory.Build.props) {
98+ $content = Get-Content - Raw - LiteralPath ./ Directory.Build.props
99+ if ($content -match ' <ModernTarget>(?<target>[^<]+)</ModernTarget>' ) {
100+ $script :ModernTarget = $matches [' target' ]
101+ }
102+
103+ if ($content -match ' <LegacyTarget>(?<target>[^<]+)</LegacyTarget>' ) {
104+ $script :LegacyTarget = $matches [' target' ]
105+ }
106+ }
107+
108+
109+ $script :ModuleName = $ModuleName = ' ClassExplorer'
110+ $testModuleManifestSplat = @ {
111+ ErrorAction = ' Ignore'
112+ WarningAction = ' Ignore'
113+ Path = " ./module/$ModuleName .psd1"
114+ }
115+
116+ $manifest = Test-ModuleManifest @testModuleManifestSplat
117+ $script :ModuleVersion = $manifest.Version
118+ $script :_IsWindows = $true
119+ $runtimeInfoType = ' System.Runtime.InteropServices.RuntimeInformation' -as [type ]
120+ try {
121+ if ($null -ne $runtimeInfoType ) {
122+ $script :_IsWindows = $runtimeInfoType ::IsOSPlatform([System.Runtime.InteropServices.OSPlatform ]::Windows)
123+ }
124+ } catch { }
125+ }
126+
51127task AssertDotNet {
52- $script :dotnet = & $GetDotNet - Unix:$Discovery .IsUnix
128+ $script :dotnet = & $GetDotNet - Unix:$script :_IsWindows
53129}
54130
55131task AssertOpenCover - If { $GenerateCodeCoverage.IsPresent } {
56- if ($Discovery .IsUnix ) {
132+ if (-not $ script :_IsWindows ) {
57133 Write-Warning ' Generating code coverage from .NET core is currently unsupported, disabling code coverage generation.'
58134 $script :GenerateCodeCoverage = $false
59135 return
@@ -63,66 +139,77 @@ task AssertOpenCover -If { $GenerateCodeCoverage.IsPresent } {
63139}
64140
65141task AssertRequiredModules {
66- & $AssertModule Pester 5.3 . 0 - Force:$Force.IsPresent
67- & $AssertModule InvokeBuild 5.8 . 4 - Force:$Force.IsPresent
142+ & $AssertModule Pester 5.7 . 1 - Force:$Force.IsPresent
143+ & $AssertModule InvokeBuild 5.14 . 22 - Force:$Force.IsPresent
68144 & $AssertModule platyPS 0.14 .2 - Force:$Force.IsPresent
69- & $AssertModule Yayaml 0.1 . 1 - Force:$Force.IsPresent
145+ & $AssertModule Yayaml 0.7 . 0 - Force:$Force.IsPresent
70146}
71147
72148task AssertDevDependencies - Jobs AssertDotNet, AssertOpenCover, AssertRequiredModules
73149
74150task 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
151+ RemakeFolder ./ Release
152+ RemakeFolder ./ testresults
85153 & $dotnet clean -- verbosity quiet - nologo
86154}
87155
88- task BuildDocs - If { $Discovery.HasDocs } {
89- $sourceDocs = " $PSScriptRoot \docs\$PSCulture "
90- $releaseDocs = ' {0}\{1}' -f $Folders.Release , $PSCulture
156+ task BuildDocs - If { Test-Path ./ docs/ $PSCulture /* .md } {
157+ $releaseDocs = " ./Release/ClassExplorer/$moduleVersion "
158+ $null = New-Item $releaseDocs / $PSCulture - ItemType Directory - Force - ErrorAction Ignore
159+ $null = New-ExternalHelp - Path ./ docs/ $PSCulture - OutputPath $releaseDocs / $PSCulture
91160
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
161+ & $GenerateSignatureMarkdown.Source - AboutHelp $releaseDocs / about_Type_Signatures.help.txt
162+ & $GenerateSignatureMarkdown.Source ./ docs/ en- US/ about_Type_Signatures.help.md
97163}
98164
99165task BuildDll {
100- if (-not $Discovery .IsUnix ) {
101- & $dotnet publish -- configuration $Configuration -- framework net471 -- verbosity quiet - nologo
166+ if ($ script :_IsWindows ) {
167+ & $dotnet publish -- configuration $Configuration -- framework $ script :LegacyTarget -- verbosity quiet - nologo
102168 }
103- & $dotnet publish -- configuration $Configuration -- framework netcoreapp3.1 -- verbosity quiet - nologo
169+
170+ & $dotnet publish -- configuration $Configuration -- framework $script :ModernTarget -- verbosity quiet - nologo
104171}
105172
106173task 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
174+ $version = $script :ModuleVersion
175+ $modern = $script :ModernTarget
176+ $legacy = $script :LegacyTarget
114177
115- if ( -not $Discovery .IsUnix ) {
116- $null = New-Item $releaseDesktopBin - Force - ItemType Directory
117- Copy-Item - Path $sourceDesktopBin - Destination $releaseDesktopBin - Force
178+ $releasePath = " ./Release/ClassExplorer/ $version "
179+ if ( -not ( Test-Path - LiteralPath $releasePath )) {
180+ $null = New-Item $releasePath - ItemType Directory
118181 }
119182
120- $null = New-Item $releaseCoreBin - Force - ItemType Directory
121- Copy-Item - Path $sourceCoreBin - Destination $releaseCoreBin - Force
183+ Copy-Item - Path ./ module/* - Destination $releasePath - Recurse - Force
184+
185+ if ($script :_IsWindows ) {
186+ $null = New-Item $releasePath / bin/ Legacy - Force - ItemType Directory
187+ $legacyFiles = (
188+ ' ClassExplorer.dll' ,
189+ ' ClassExplorer.pdb' ,
190+ ' System.Buffers.dll' ,
191+ ' System.Collections.Immutable.dll' ,
192+ ' System.Memory.dll' ,
193+ ' System.Numerics.Vectors.dll' ,
194+ ' System.Runtime.CompilerServices.Unsafe.dll' )
195+
196+ foreach ($file in $legacyFiles ) {
197+ Copy-Item - Force - LiteralPath ./ artifacts/ publish/ ClassExplorer/ ${Configuration} _ $legacy / $file - Destination $releasePath / bin/ Legacy
198+ }
199+ }
200+
201+ $null = New-Item $releasePath / bin/ Modern - Force - ItemType Directory
202+ $modernFiles = (
203+ ' ClassExplorer.dll' ,
204+ ' ClassExplorer.pdb' ,
205+ ' ClassExplorer.deps.json' )
206+ foreach ($file in $modernFiles ) {
207+ Copy-Item - Force - LiteralPath ./ artifacts/ publish/ ClassExplorer/ ${Configuration} _ $modern / $file - Destination $releasePath / bin/ Modern
208+ }
122209}
123210
124- task DoTest - If { $Discovery .HasTests -and $Settings .ShouldTest } {
125- if ($Discovery .IsUnix ) {
211+ task DoTest - If { Test-Path . / test /* .ps1 } {
212+ if (-not $ script :_IsWindows ) {
126213 $scriptString = '
127214 $projectPath = "{0}"
128215 Invoke-Pester "$projectPath" -OutputFormat NUnitXml -OutputFile "$projectPath\testresults\pester.xml"
@@ -141,16 +228,16 @@ task DoTest -If { $Discovery.HasTests -and $Settings.ShouldTest } {
141228 $scriptString ))
142229
143230 $powershellCommand = ' powershell'
144- if ($Discovery .IsUnix ) {
231+ if ($PSVersionTable .PSVersion.Major -gt 5 ) {
145232 $powershellCommand = ' pwsh'
146233 }
147234
148- $powershell = (Get-Command $powershellCommand ).Source
235+ $powershell = (Get-Command - CommandType Application $powershellCommand ).Source
149236
150237 if ($GenerateCodeCoverage.IsPresent ) {
151238 # OpenCover needs full pdb's. I'm very open to suggestions for streamlining this...
152239 # & $dotnet clean
153- & $dotnet publish -- configuration $Configuration -- framework net471 -- verbosity quiet - nologo / p:DebugType= Full
240+ & $dotnet publish -- configuration $Configuration -- framework $ script :LegacyTarget -- verbosity quiet - - nologo / p:DebugType= Full
154241
155242 $moduleName = $Settings.Name
156243 $release = ' {0}\bin\Desktop\{1}' -f $Folders.Release , $moduleName
@@ -212,7 +299,7 @@ task DoPublish {
212299 Publish-Module - Name $Folders.Release - NuGetApiKey $apiKey - Force:$Force.IsPresent
213300}
214301
215- task Build - Jobs AssertDevDependencies, Clean , BuildDll, CopyToRelease, BuildDocs
302+ task Build - Jobs GetProjectInfo , AssertDevDependencies, Clean , BuildDll, CopyToRelease, BuildDocs
216303
217304task Test - Jobs Build, DoTest
218305
0 commit comments