1
- # This function might be a partially out of date and only the -BuildDoc switch is guaranteed to work since it is used and needed for the build process.
2
- [CmdletBinding ()]
1
+ [CmdletBinding (DefaultParameterSetName = " BuildOne" )]
3
2
param (
3
+ [Parameter (ParameterSetName = " BuildAll" )]
4
+ [switch ]$All ,
4
5
5
- [Parameter (ParameterSetName = ' Build ' )]
6
- [ValidateSet (' PSV3 Debug ' , ' PSV3 Release ' , ' Debug ' , ' Release ' )]
7
- [string ] $Configuration = ' Debug ' ,
6
+ [Parameter (ParameterSetName = " BuildOne " )]
7
+ [ValidateSet (" full " , " core " )]
8
+ [string ]$Framework = " core " ,
8
9
9
- [Parameter (ParameterSetName = ' Build' )]
10
- [switch ] $BuildDocs = $false ,
10
+ [Parameter (ParameterSetName = " BuildOne" )]
11
+ [ValidateSet (" PSv3" , " PSv4" , " PSv5" )]
12
+ [string ]$AnalyzerVersion = " PSv5" ,
11
13
12
- [Parameter (ParameterSetName = ' Build' )]
13
- [switch ] $CleanOutput = $false ,
14
+ [Parameter (ParameterSetName = " BuildOne" )]
15
+ [ValidateSet (" Debug" , " Release" )]
16
+ [string ]$Configuration = " Debug" ,
14
17
15
- [Parameter (ParameterSetName = ' Build ' )]
16
- [switch ] $Install = $false ,
18
+ [Parameter (ParameterSetName = " BuildDoc " )]
19
+ [switch ]$Documentation ,
17
20
18
- [Parameter (ParameterSetName = ' Build' )]
19
- [switch ] $Uninstall = $false ,
21
+ [Parameter (ParameterSetName = ' BuildAll' )]
22
+ [Parameter (ParameterSetName = ' BuildOne' )]
23
+ [switch ]$Clobber ,
20
24
21
- [Parameter (ParameterSetName = ' Test ' )]
22
- [switch ] $Test = $false ,
25
+ [Parameter (Mandatory = $true , ParameterSetName = ' Clean ' )]
26
+ [switch ] $Clean ,
23
27
24
- [Parameter (ParameterSetName = ' Test' )]
25
- [switch ] $Engine = $false ,
28
+ [Parameter (Mandatory = $true , ParameterSetName = ' Test' )]
29
+ [switch ] $Test ,
26
30
27
31
[Parameter (ParameterSetName = ' Test' )]
28
- [switch ] $Rules = $false ,
29
-
30
- [Parameter (ParameterSetName = ' Test' )]
31
- [switch ] $RunInDifferentProcess = $false
32
+ [switch ] $InProcess
32
33
)
33
34
34
- # Some cmdlets like copy-item do not respond to the $verbosepreference variable
35
- # hence we set it explicitly
36
- $verbosity = $false
37
- if ($VerbosePreference.Equals ([System.Management.Automation.ActionPreference ]' Continue' ))
38
- {
39
- $verbosity = $true
40
- }
41
-
42
- Function CreateIfNotExists ([string ] $folderPath )
43
- {
44
- if (-not (Test-Path $folderPath ))
45
- {
46
- New-Item - Path $folderPath - ItemType Directory - Verbose:$verbosity
47
- }
48
- }
49
-
50
- $projectRoot = Resolve-path (Split-Path $MyInvocation.InvocationName )
51
- $solutionPath = Join-Path $projectRoot ' PSScriptAnalyzer.sln'
52
- $outPath = Join-Path $projectRoot ' out'
53
- $destinationPath = Join-Path $outPath PSScriptAnalyzer
54
-
55
- if (-not (Test-Path $solutionPath ))
56
- {
57
- $errMsg = " {0} not the right directory" -f $solutionPath
58
- throw $errMsg
59
- }
60
-
61
- if ($CleanOutput )
62
- {
63
- Remove-Item - Recurse $outPath \* - Force - Verbose:$verbosity
64
- }
65
-
66
- if ($BuildDocs )
67
- {
68
- $docsPath = Join-Path $projectRoot ' docs'
69
- $markdownDocsPath = Join-Path $docsPath ' markdown'
70
- $outputDocsPath = Join-Path $destinationPath en- US
71
-
72
- CreateIfNotExists($outputDocsPath )
73
-
74
- # Build documentation using platyPS
75
- $requiredVersionOfplatyPS = 0.9
76
- if ($null -eq (Get-Module platyPS - ListAvailable - Verbose:$verbosity | Where-Object { $_.Version -ge $requiredVersionOfplatyPS }))
77
- {
78
- " Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Please install it from https://www.powershellgallery.com/packages/platyPS/ using e.g. the following command: Install-Module platyPS"
79
- }
80
- if ($null -eq (Get-Module platyPS - Verbose:$verbosity ))
81
- {
82
- Import-Module platyPS - Verbose:$verbosity
83
- }
84
- if (-not (Test-Path $markdownDocsPath - Verbose:$verbosity ))
85
- {
86
- throw " Cannot find markdown documentation folder."
87
- }
88
- New-ExternalHelp - Path $markdownDocsPath - OutputPath $outputDocsPath - Force - Verbose:$verbosity
89
- }
90
-
91
- # Appveyor errors out due to $profile being null. Hence...
92
- $moduleRootPath = " $HOME /Documents/WindowsPowerShell/Modules"
93
- if ($null -ne $profile )
94
- {
95
- $moduleRootPath = Join-Path (Split-Path $profile ) ' Modules'
96
- }
97
- $modulePSSAPath = Join-Path $moduleRootPath ' PSScriptAnalyzer'
98
- if ($Install )
99
- {
100
- if (-not (Test-Path $moduleRootPath ))
101
- {
102
- New-Item - Path $moduleRootPath - ItemType Directory - Force - Verbose:$verbosity
103
- }
104
- if (-not (Test-Path - Path $destinationPath ))
105
- {
106
- throw " Please build the module first."
107
- }
108
- Copy-Item - Path $destinationPath - Destination $modulePSSAPath - Recurse - Verbose:$verbosity
109
- }
110
-
111
- if ($Test )
112
- {
113
- Import-Module - Name Pester - MinimumVersion 4.3 .1 - ErrorAction Stop
114
- Function GetTestRunnerScriptContent ($testPath )
115
- {
116
- $x = @"
117
- cd $testPath
118
- Invoke-Pester
119
- "@
120
- return $x
121
- }
122
-
123
- Function CreateTestRunnerScript ($testPath )
124
- {
125
- $tmptmpFilePath = [System.IO.Path ]::GetTempFileName()
126
- $tmpFilePath = $tmptmpFilePath + ' .ps1'
127
- Move-Item $tmptmpFilePath $tmpFilePath - Verbose:$verbosity
128
- $content = GetTestRunnerScriptContent $testPath
129
- Set-Content - Path $tmpFilePath - Value $content - Verbose:$verbosity
130
- return $tmpFilePath
131
- }
132
-
133
- Function GetTestPath ($TestType )
134
- {
135
- if ($TestType -eq " engine" )
136
- {
137
- $testPath = Join-Path $projectRoot " Tests/Engine"
35
+ END {
36
+ Import-Module - Force (Join-Path $PSScriptRoot build.psm1)
37
+ if ( $Clean -or $Clobber ) {
38
+ Remove-Build
39
+ if ( $PSCmdlet.ParameterSetName -eq " Clean" ) {
40
+ return
138
41
}
139
- else
140
- {
141
- $testPath = Join-Path $projectRoot " Tests/Rules"
142
- }
143
- return $testPath
144
42
}
145
43
146
- Function RunTest ($TestType , [Boolean ] $DifferentProcess )
147
- {
148
- $testPath = GetTestPath($TestType )
149
- if ($DifferentProcess )
150
- {
151
- $testScriptFilePath = CreateTestRunnerScript $testPath
152
- Start-Process powershell - ArgumentList " -NoExit" , " -File $testScriptFilePath " - Verb runas
153
- # clean up the test file
44
+ $setName = $PSCmdlet.ParameterSetName
45
+ switch ( $setName ) {
46
+ " BuildAll" {
47
+ Build-ScriptAnalyzer - All
154
48
}
155
- else
156
- {
157
- try
158
- {
159
- Push-Location .
160
- ([scriptblock ]::Create((GetTestRunnerScriptContent $testPath ))).Invoke()
161
- }
162
- finally
163
- {
164
- Pop-Location
165
-
49
+ " BuildDoc" {
50
+ Build-ScriptAnalyzer - Documentation
51
+ }
52
+ " BuildOne" {
53
+ $buildArgs = @ {
54
+ Framework = $Framework
55
+ AnalyzerVersion = $AnalyzerVersion
56
+ Configuration = $Configuration
166
57
}
58
+ Build-ScriptAnalyzer @buildArgs
59
+ }
60
+ " Test" {
61
+ Test-ScriptAnalyzer - InProcess:$InProcess
62
+ return
63
+ }
64
+ default {
65
+ throw " Unexpected parameter set '$setName '"
167
66
}
168
67
}
169
-
170
- if ($Engine -or (-not ($Engine -or $Rules )))
171
- {
172
- RunTest ' engine' $RunInDifferentProcess
173
- }
174
- if ($Rules -or (-not ($Engine -or $Rules )))
175
- {
176
- RunTest ' rules' $RunInDifferentProcess
177
- }
178
- }
179
-
180
- if ($Uninstall )
181
- {
182
- Remove-Item - Path $modulePSSAPath - Force - Verbose:$verbosity - Recurse
183
- }
68
+ }
0 commit comments