1+ <#
2+ This script publishes the module to the gallery.
3+ It expects as input an ApiKey authorized to publish the module.
4+
5+ Insert any build steps you may need to take before publishing it here.
6+ #>
7+ param (
8+ $ApiKey ,
9+
10+ $WorkingDirectory = $env: SYSTEM_DEFAULTWORKINGDIRECTORY
11+ )
12+
13+ # Prepare publish folder
14+ Write-PSFMessage - Level Important - Message " Creating and populating publishing directory"
15+ $publishDir = New-Item - Path $WorkingDirectory - Name publish - ItemType Directory - Force
16+ Remove-Item - Path " $publishDir \*" - Recurse - Force - ErrorAction SilentlyContinue
17+ Copy-Item - Path " $ ( $WorkingDirectory ) \PSUtil" - Destination $publishDir.FullName - Recurse - Force
18+
19+ # region Gather text data to compile
20+ $text = @ ()
21+ $processed = @ ()
22+
23+ # Gather Stuff to run before
24+ foreach ($line in (Get-Content " $ ( $PSScriptRoot ) \filesBefore.txt" | Where-Object { $_ -notlike " #*" }))
25+ {
26+ if ([string ]::IsNullOrWhiteSpace($line )) { continue }
27+
28+ $basePath = Join-Path " $ ( $publishDir.FullName ) \PSUtil" $line
29+ foreach ($entry in (Resolve-PSFPath - Path $basePath ))
30+ {
31+ $item = Get-Item $entry
32+ if ($item.PSIsContainer ) { continue }
33+ if ($item.FullName -in $processed ) { continue }
34+ $text += [System.IO.File ]::ReadAllText($item.FullName )
35+ $processed += $item.FullName
36+ }
37+ }
38+
39+ # Gather commands
40+ Get-ChildItem - Path " $ ( $publishDir.FullName ) \PSUtil\internal\functions\" - Recurse - File - Filter " *.ps1" | ForEach-Object {
41+ $text += [System.IO.File ]::ReadAllText($_.FullName )
42+ }
43+ Get-ChildItem - Path " $ ( $publishDir.FullName ) \PSUtil\functions\" - Recurse - File - Filter " *.ps1" | ForEach-Object {
44+ $text += [System.IO.File ]::ReadAllText($_.FullName )
45+ }
46+
47+ # Gather stuff to run afterwards
48+ foreach ($line in (Get-Content " $ ( $PSScriptRoot ) \filesAfter.txt" | Where-Object { $_ -notlike " #*" }))
49+ {
50+ if ([string ]::IsNullOrWhiteSpace($line )) { continue }
51+
52+ $basePath = Join-Path " $ ( $publishDir.FullName ) \PSUtil" $line
53+ foreach ($entry in (Resolve-PSFPath - Path $basePath ))
54+ {
55+ $item = Get-Item $entry
56+ if ($item.PSIsContainer ) { continue }
57+ if ($item.FullName -in $processed ) { continue }
58+ $text += [System.IO.File ]::ReadAllText($item.FullName )
59+ $processed += $item.FullName
60+ }
61+ }
62+ # endregion Gather text data to compile
63+
64+ # region Update the psm1 file
65+ $fileData = Get-Content - Path " $ ( $publishDir.FullName ) \PSUtil\PSUtil.psm1" - Raw
66+ $fileData = $fileData.Replace (' "<was not compiled>"' , ' "<was compiled>"' )
67+ $fileData = $fileData.Replace (' "<compile code into here>"' , ($text -join " `n`n " ))
68+ [System.IO.File ]::WriteAllText(" $ ( $publishDir.FullName ) \PSUtil\PSUtil.psm1" , $fileData , [System.Text.Encoding ]::UTF8)
69+ # endregion Update the psm1 file
70+
71+ # Publish to Gallery
72+ Publish-PSFModule - Path " $ ( $publishDir.FullName ) \PSUtil" - ApiKey $ApiKey
0 commit comments