This repository was archived by the owner on Apr 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleBuildToolsTemp.buildenvironment.ps1
121 lines (107 loc) · 6.38 KB
/
ModuleBuildToolsTemp.buildenvironment.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
param (
[Parameter(HelpMessage = 'If you are initializing this file or want to force overwrite the persistent export data use this flag.')]
[switch]$ForcePersist
)
<#
Update $Script:BuildEnv to suit your PowerShell module build. If you make sufficient changes to your build environment json file (via the module commands or otherwise) you should update this as well so those that inherit your project in the future are able to rebuild it from scratch.
#>
# If the variable is already defined then essentially do nothing.
# Otherwise we create a baseline variable first in case this is a first time run, then
# check for an exported .xml file with persistent settings for any run thereafter
if ((Get-Variable 'BuildEnv' -ErrorAction:SilentlyContinue) -eq $null) {
$Script:BuildEnv = New-Object -TypeName PSObject -Property @{
FirstRun = $True
Force = $False
ForceInstallModule = $False
Encoding = 'utf8'
ModuleToBuild = 'ModuleBuildToolsTemp'
ModuleVersion = '0.0.9'
ModuleWebsite = 'https://www.github.com/justin-p/ModuleBuildToolsTemp'
ModuleCopyright = "(c) $((get-date).Year.ToString()) Justin Perdok. All rights reserved."
ModuleLicenseURI = 'https://www.github.com/justin-p/ModuleBuildToolsTemp/LICENSE.md'
ModuleTags = 'modulebuildtools' -split ','
ModuleAuthor = 'Justin Perdok'
ModuleDescription = 'ModuleBuildToolsTemp'
# Options - These affect how your build will be run.
OptionAnalyzeCode = $True
OptionCodeHealthReport = $True
OptionCombineFiles = $TRUE
OptionTranscriptEnabled = $false
OptionTranscriptLogFile = 'BuildTranscript.Log'
# PlatyPS has been the cause of most of my build failures. This can help you isolate which function's CBH is causing you grief.
OptionRunPlatyPSVerbose = $false
# If you want to prescan and fail a build upon finding any proprietary strings
# enable this option and define some strings.
OptionSanitizeSensitiveTerms = $False
OptionSensitiveTerms = @($env:username, $env:userdomain, $env:userdnsdomain) | Where {$null -ne $_}
OptionSensitiveTermsInitialized = $false
# If you want to update your current module build version automatically
# after a successful psgallery publish set this to $true
OptionUpdateVersionAfterPublishing = $True
# Additional paths in the source module which should be copied over to the final build release
AdditionalModulePaths = @('plugins')
# Generate a yml file in the root folder of this project for readthedocs.org integration
OptionGenerateReadTheDocs = $False
# Most of the following options you probably don't need to change
BaseSourceFolder = 'src' # Base source path
PublicFunctionSource = "src\public" # Public functions (to be exported by file name as the function name)
PrivateFunctionSource = "src\private" # Private function source.
OtherModuleSource = "src\other" # Other module source.
BaseReleaseFolder = 'release' # Releases directory.
BuildToolFolder = 'build' # Build tool path.
BuildReportsFolder = 'build\reports' # Location where PSCodeHealth stores its reports.
ScratchFolder = 'temp' # Scratch path - this is where all our scratch work occurs. It will be cleared out at every run.
FunctionTemplates = "src\templates" # Location of function template files (*.tem)
# If you will be publishing to the PowerShell Gallery you will need a Nuget API key (can get from the website)
# You should NOT enter this key here but rather manually enter it in the ModuleBuildToolsTemp.buildenvironment.json file with: Set-MBBuildEnvironment -NugetAPIKey '<key>'
NugetAPIKey = ''
}
########################################
# !! Please leave anything below this line alone !!
########################################
$PersistentBuildFile = join-path $PSScriptRoot "ModuleBuildToolsTemp.buildenvironment.json"
# Load any persistent data (overrides anything in BuildEnv if the hash element exists)
if ((Test-Path $PersistentBuildFile)) {
try {
$LoadedBuildEnv = Get-Content $PersistentBuildFile | ConvertFrom-Json
}
catch {
throw "Unable to load $PersistentBuildFile"
}
$BaseSettings = ($Script:BuildEnv | Get-Member -Type 'NoteProperty').Name
$BuildSettings = ($LoadedBuildEnv | Get-Member -Type 'NoteProperty').Name
ForEach ($Key in $BuildSettings) {
if ($BaseSettings -contains $Key) {
Write-Verbose "Updating profile setting '$key' from $PersistentBuildFile"
($Script:BuildEnv).$Key = $LoadedBuildEnv.$Key
}
else {
Write-Verbose "Adding profile setting '$key' from $PersistentBuildFile"
Add-Member -InputObject $Script:BuildEnv -MemberType 'NoteProperty' -Name $Key -Value $LoadedBuildEnv.$Key
}
}
# Look for any settings in the base settings that are not in the saved configuration and
# force a persist if found.
ForEach ($BaseSetting in $BaseSettings) {
if ($BuildSettings -notcontains $BaseSetting) {
Write-Verbose " Base setting to be added to json configuration file: $BaseSetting"
$BuildExport = $True
}
}
}
else {
# No persistent file was found so we are going to create one
$BuildExport = $True
}
# We create this helper function here as a quasi private function which can be used without loading the modulebuild module
function Script:Save-BuildData {
$Script:BuildEnv | ConvertTo-Json | Out-File -FilePath $PersistentBuildFile -Encoding $Script:BuildEnv.Encoding -Force
}
# If we don't have a persistent file, we are forcing a persist, or properties were not the same between
# the loaded json and our defined BuildEnv file then push a new persistent file export.
if ((-not (Test-path $PersistentBuildFile)) -or $BuildExport -or $ForcePersist -or ($Script:BuildEnv.FirstRun)) {
$Script:BuildEnv.FirstRun = $false
Write-Verbose "Exporting the BuildEnv data!"
$Script:BuildEnv | ConvertTo-Json | Out-File -FilePath $PersistentBuildFile -Encoding $Script:BuildEnv.Encoding -Force
}
}