1
1
Remove-Variable - Name PSBPreference - Scope Script - Force - ErrorAction Ignore
2
2
Set-Variable - Name PSBPreference - Option ReadOnly - Scope Script - Value (. ([IO.Path ]::Combine($PSScriptRoot , ' build.properties.ps1' )))
3
+ $__DefaultBuildDependencies = $PSBPreference.Build.Dependencies
3
4
4
5
# Synopsis: Initialize build environment variables
5
6
task Init {
@@ -14,12 +15,14 @@ task Clean Init, {
14
15
# Synopsis: Builds module based on source directory
15
16
task StageFiles Clean , {
16
17
$buildParams = @ {
17
- Path = $PSBPreference.General.SrcRootDir
18
- ModuleName = $PSBPreference.General.ModuleName
19
- DestinationPath = $PSBPreference.Build.ModuleOutDir
20
- Exclude = $PSBPreference.Build.Exclude
21
- Compile = $PSBPreference.Build.CompileModule
22
- Culture = $PSBPreference.Help.DefaultLocale
18
+ Path = $PSBPreference.General.SrcRootDir
19
+ ModuleName = $PSBPreference.General.ModuleName
20
+ DestinationPath = $PSBPreference.Build.ModuleOutDir
21
+ Exclude = $PSBPreference.Build.Exclude
22
+ Compile = $PSBPreference.Build.CompileModule
23
+ CompileDirectories = $PSBPreference.Build.CompileDirectories
24
+ CopyDirectories = $PSBPreference.Build.CopyDirectories
25
+ Culture = $PSBPreference.Help.DefaultLocale
23
26
}
24
27
25
28
if ($PSBPreference.Help.ConvertReadMeToAboutHelp ) {
@@ -30,6 +33,7 @@ task StageFiles Clean, {
30
33
}
31
34
}
32
35
36
+ # only add these configuration values to the build parameters if they have been been set
33
37
' CompileHeader' , ' CompileFooter' , ' CompileScriptHeader' , ' CompileScriptFooter' | ForEach-Object {
34
38
if ($PSBPreference.Build.Keys -contains $_ ) {
35
39
$buildParams .$_ = $PSBPreference.Build .$_
@@ -39,8 +43,7 @@ task StageFiles Clean, {
39
43
Build-PSBuildModule @buildParams
40
44
}
41
45
42
- # Synopsis: Builds module and generate help documentation
43
- Task Build $ ($PSBPreference.Build.Dependencies -join " , " )
46
+
44
47
45
48
$analyzePreReqs = {
46
49
$result = $true
@@ -56,7 +59,7 @@ $analyzePreReqs = {
56
59
}
57
60
58
61
# Synopsis: Execute PSScriptAnalyzer tests
59
- task Analyze Build, {
62
+ task Analyze - If ( . $analyzePreReqs ) Build, {
60
63
$analyzeParams = @ {
61
64
Path = $PSBPreference.Build.ModuleOutDir
62
65
SeverityThreshold = $PSBPreference.Test.ScriptAnalysis.FailBuildOnSeverityLevel
@@ -83,25 +86,24 @@ $pesterPreReqs = {
83
86
}
84
87
85
88
# Synopsis: Execute Pester tests
86
- task Pester Build - If $pesterPreReqs , {
89
+ task Pester - If ( . $pesterPreReqs ) Build , {
87
90
$pesterParams = @ {
88
- Path = $PSBPreference.Test.RootDir
89
- ModuleName = $PSBPreference.General.ModuleName
90
- OutputPath = $PSBPreference.Test.OutputFile
91
- OutputFormat = $PSBPreference.Test.OutputFormat
92
- CodeCoverage = $PSBPreference.Test.CodeCoverage.Enabled
93
- CodeCoverageThreshold = $PSBPreference.Test.CodeCoverage.Threshold
94
- CodeCoverageFiles = $PSBPreference.Test.CodeCoverage.Files
91
+ Path = $PSBPreference.Test.RootDir
92
+ ModuleName = $PSBPreference.General.ModuleName
93
+ ModuleManifest = Join-Path $PSBPreference.Build.ModuleOutDir " $ ( $PSBPreference.General.ModuleName ) .psd1"
94
+ OutputPath = $PSBPreference.Test.OutputFile
95
+ OutputFormat = $PSBPreference.Test.OutputFormat
96
+ CodeCoverage = $PSBPreference.Test.CodeCoverage.Enabled
97
+ CodeCoverageThreshold = $PSBPreference.Test.CodeCoverage.Threshold
98
+ CodeCoverageFiles = $PSBPreference.Test.CodeCoverage.Files
99
+ CodeCoverageOutputFile = $PSBPreference.Test.CodeCoverage.OutputFile
100
+ CodeCoverageOutputFileFormat = $PSBPreference.Test.CodeCoverage.OutputFormat
101
+ ImportModule = $PSBPreference.Test.ImportModule
95
102
}
96
103
Test-PSBuildPester @pesterParams
97
104
}
98
105
99
- # Synopsis: Execute Pester and ScriptAnalyzer tests
100
- task Test Pester, Analyze, {
101
- }
102
106
103
- # Synopsis: Builds help documentation
104
- task BuildHelp GenerateMarkdown, GenerateMAML, {}
105
107
106
108
$genMarkdownPreReqs = {
107
109
$result = $true
@@ -113,7 +115,7 @@ $genMarkdownPreReqs = {
113
115
}
114
116
115
117
# Synopsis: Generates PlatyPS markdown files from module help
116
- task GenerateMarkdown StageFiles, {
118
+ task GenerateMarkdown - if ( $genMarkdownPreReqs ) StageFiles, {
117
119
$buildMDParams = @ {
118
120
ModulePath = $PSBPreference.Build.ModuleOutDir
119
121
ModuleName = $PSBPreference.General.ModuleName
@@ -133,7 +135,7 @@ $genHelpFilesPreReqs = {
133
135
}
134
136
135
137
# Synopsis: Generates MAML-based help from PlatyPS markdown files
136
- task GenerateMAML GenerateMarkdown, {
138
+ task GenerateMAML - if ( . $genHelpFilesPreReqs ) GenerateMarkdown, {
137
139
Build-PSBuildMAMLHelp - Path $PSBPreference.Docs.RootDir - DestinationPath $PSBPreference.Build.ModuleOutDir
138
140
}
139
141
@@ -147,7 +149,7 @@ $genUpdatableHelpPreReqs = {
147
149
}
148
150
149
151
# Synopsis: Create updatable help .cab file based on PlatyPS markdown help
150
- task GenerateUpdatableHelp BuildHelp, {
152
+ task GenerateUpdatableHelp - if ( . $genUpdatableHelpPreReqs ) BuildHelp, {
151
153
Build-PSBuildUpdatableHelp - DocsPath $PSBPreference.Docs.RootDir - OutputPath $PSBPreference.Help.UpdatableHelpOutDir
152
154
}
153
155
@@ -171,3 +173,22 @@ Task Publish Test, {
171
173
172
174
Publish-PSBuildModule @publishParams
173
175
}
176
+
177
+
178
+ # region Summary Tasks
179
+
180
+ # Synopsis: Builds help documentation
181
+ task BuildHelp GenerateMarkdown, GenerateMAML
182
+
183
+ Task Build {
184
+ if ([String ]$PSBPreference.Build.Dependencies -ne [String ]$__DefaultBuildDependencies ) {
185
+ throw [NotSupportedException ]' You cannot use $PSBPreference.Build.Dependencies with Invoke-Build. Please instead redefine the build task or your default task to include your dependencies. Example: Task . Dependency1,Dependency2,Build,Test or Task Build Dependency1,Dependency2,StageFiles'
186
+ }
187
+ }, StageFiles, BuildHelp
188
+
189
+ # Synopsis: Execute Pester and ScriptAnalyzer tests
190
+ task Test Analyze, Pester
191
+
192
+ task . Build, Test
193
+
194
+ # endregion Summary Tasks
0 commit comments