1+ <#
2+ . DESCRIPTION
3+ Builds the PSSwagger.LiveTestFramework module.
4+ #>
5+ [CmdletBinding ()]
6+ param (
7+ [Parameter (Mandatory = $true )]
8+ [string ]
9+ $OutputDirectory
10+ )
11+
12+ <#
13+ . DESCRIPTION
14+ Remove the output directory if it exists then create it.
15+ #>
16+ function Prepare-OutputDirectory {
17+ [CmdletBinding ()]
18+ param (
19+ [Parameter (Mandatory = $true )]
20+ [string ]
21+ $OutputDirectory
22+ )
23+
24+ if (Test-Path - Path $OutputDirectory ) {
25+ Write-Verbose - Message " Cleaning module directory"
26+ Remove-Item - Path $OutputDirectory - ErrorAction SilentlyContinue - Recurse - Force
27+ }
28+
29+ Write-Verbose - Message " Creating module directory"
30+ $null = New-Item - Path $OutputDirectory - ItemType Container - Force
31+ }
32+
33+ <#
34+ . DESCRIPTION
35+ Converts all source C# files (.cs) to code files (.Code.ps1).
36+ #>
37+ function Convert-CSharpFiles {
38+ [CmdletBinding ()]
39+ param (
40+ [Parameter (Mandatory = $true )]
41+ [string ]
42+ $SrcPath
43+ )
44+
45+ Write-Verbose - Message " Converting all C# files to code files"
46+
47+ & $SrcPath \ConvertFrom-CSharpFiles.ps1
48+ }
49+
50+ <#
51+ . DESCRIPTION
52+ Copies PowerShell module files to the output directory (.psd1 and .psm1)
53+ #>
54+ function Copy-PowerShellModuleFiles {
55+ [CmdletBinding ()]
56+ param (
57+ [Parameter (Mandatory = $true )]
58+ [string ]
59+ $OutputDirectory ,
60+
61+ [Parameter (Mandatory = $true )]
62+ [string ]
63+ $RepoPath
64+ )
65+
66+ Copy-Item - Path (Join-Path - Path $repoPath - ChildPath ' PSSwagger.LiveTestFramework.psd1' ) - Destination (Join-Path - Path $OutputDirectory - ChildPath ' PSSwagger.LiveTestFramework.psd1' ) - Verbose
67+ Copy-Item - Path (Join-Path - Path $repoPath - ChildPath ' PSSwagger.LiveTestFramework.psm1' ) - Destination (Join-Path - Path $OutputDirectory - ChildPath ' PSSwagger.LiveTestFramework.psm1' ) - Verbose
68+ }
69+
70+ <#
71+ . DESCRIPTION
72+ Copies all code files in the correct directory structure to the output directory.
73+ #>
74+ function Copy-CodeProject {
75+ [CmdletBinding ()]
76+ param (
77+ [Parameter (Mandatory = $true )]
78+ [string ]
79+ $OutputDirectory ,
80+
81+ [Parameter (Mandatory = $true )]
82+ [string ]
83+ $SrcPath ,
84+
85+ [Parameter (Mandatory = $true )]
86+ [string ]
87+ $Project
88+ )
89+
90+ Get-ChildItem - Path (Join-Path - Path $srcPath - ChildPath $Project | Join-Path - ChildPath ' *.Code.ps1' ) - File | ForEach-Object {
91+ $dir = $_.Directory
92+ $subPath = " \"
93+ while ($dir -and $dir.FullName -ne $srcPath ) {
94+ $subPath = Join-Path $dir.Name - ChildPath $dirName
95+ $dir = $dir.Parent
96+ }
97+ $outputDir = Join-Path - Path $OutputDirectory - ChildPath ' src' | Join-Path - ChildPath $subPath
98+ if (-not (Test-Path - Path $outputDir - PathType Container)) {
99+ $null = New-Item - Path $outputDir - ItemType Container - Force
100+ }
101+ $outputFilePath = Join-Path - Path $outputDir - ChildPath $_.Name
102+
103+ Copy-Item - Path $_.FullName - Destination $outputFilePath - Verbose
104+ }
105+ }
106+
107+ <#
108+ . DESCRIPTION
109+ Retrieves the release info file.
110+ #>
111+ function Get-ReleaseInfo {
112+ [CmdletBinding ()]
113+ param (
114+ [Parameter (Mandatory = $true )]
115+ [string ]
116+ $RepoPath
117+ )
118+
119+ Get-Content - Path (Join-Path - Path $RepoPath - ChildPath ' release.json' ) | ConvertFrom-Json
120+ }
121+
122+ <#
123+ . DESCRIPTION
124+ Replaces dynamic info in the module manifest, like ModuleVersion.
125+ #>
126+ function Set-ModuleManifestInfo {
127+ [CmdletBinding ()]
128+ param (
129+ [Parameter (Mandatory = $true )]
130+ [object ]
131+ $Release ,
132+
133+ [Parameter (Mandatory = $true )]
134+ [string ]
135+ $OutputDirectory
136+ )
137+
138+ $psd1Path = Join-Path - Path $OutputDirectory - ChildPath ' PSSwagger.LiveTestFramework.psd1'
139+ $manifestContent = Get-Content - Path $psd1Path
140+ $manifestContent = $manifestContent.Replace (" ModuleVersion = '9.9.9'" , " ModuleVersion = '$ ( $Release.version ) '" )
141+ $manifestContent | Out-File - FilePath $psd1Path
142+ }
143+
144+ $srcPath = Join-Path - Path $PSScriptRoot - ChildPath ' src'
145+ $release = Get-ReleaseInfo - RepoPath $PSScriptRoot
146+ $moduleOutputDirectory = Join-Path - Path $OutputDirectory - ChildPath ' PSSwagger.LiveTestFramework' | Join-Path - ChildPath $release.version
147+ Prepare- OutputDirectory - OutputDirectory $moduleOutputDirectory
148+ Convert-CSharpFiles - SrcPath $srcPath
149+
150+ # Copy PowerShell files
151+ Copy-PowerShellModuleFiles - OutputDirectory $moduleOutputDirectory - RepoPath $PSScriptRoot
152+
153+ # Copy code files
154+ # This should ignore csproj, intermediate cs files
155+ # Currently this is a non-recursive search for *.Code.ps1 files
156+ Copy-CodeProject - OutputDirectory $moduleOutputDirectory - SrcPath $srcPath - Project ' PSSwagger.LTF.Lib'
157+ Copy-CodeProject - OutputDirectory $moduleOutputDirectory - SrcPath $srcPath - Project ' PSSwagger.LTF.ConsoleServer'
158+
159+ Set-ModuleManifestInfo - Release $release - OutputDirectory $moduleOutputDirectory
160+
161+ # This currently only works in some cases.
162+ if (-not $? ) {
163+ Write-Host " Module packaging completed with errors." - BackgroundColor DarkRed
164+ } else {
165+ Write-Host " Module packaged successfully." - BackgroundColor DarkGreen
166+ }
0 commit comments