forked from AdamGrossTX/FU.WhyAmIBlocked
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild.ps1
147 lines (130 loc) · 5.53 KB
/
Build.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
[cmdletbinding()]
param (
[parameter(Mandatory = $true)]
[System.IO.FileInfo]$modulePath,
[parameter(Mandatory = $false)]
[switch]$buildLocal
)
try {
$ModuleName = "FU.WhyAmIBlocked"
$Author = "Adam Gross (@AdamGrossTX)"
$CompanyName = "A Square Dozen"
$Prefix = "fu"
$Path = "C:\FeatureUpdateBlocks"
$ProjectUri = "https://github.com/AdamGrossTX/FU.WhyAmIBlocked"
#region Generate a new version number
$moduleName = Split-Path -Path $modulePath -Leaf
[Version]$exVer = Find-Module -Name $moduleName -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Version
if ($buildLocal) {
$rev = ((Get-ChildItem -Path "$($PSScriptRoot)\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
$newVersion = New-Object -TypeName Version -ArgumentList 1, 0, 0, $rev
}
else {
$newVersion = if ($exVer) {
$rev = ($exVer.Revision + 1)
New-Object version -ArgumentList $exVer.Major, $exVer.Minor, $exVer.Build, $rev
}
else {
$rev = ((Get-ChildItem "$($PSScriptRoot)\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
New-Object Version -ArgumentList 1, 0, 0, $rev
}
}
$releaseNotes = (Get-Content ".\$($moduleName)\ReleaseNotes.txt" -Raw -ErrorAction SilentlyContinue).Replace("{{NewVersion}}",$newVersion)
$releaseNotes = $exVer ? $releaseNotes.Replace("{{LastVersion}}","$($exVer.ToString())") : $releaseNotes.Replace("{{LastVersion}}","")
#endregion
#region Build out the release
$relPath = "$($PSScriptRoot)\bin\release\$($rev)\$($moduleName)"
"Version is $($newVersion)"
"Module Path is $($modulePath)"
"Module Name is $($moduleName)"
"Release Path is $($relPath)"
if (!(Test-Path -Path $relPath)) {
New-Item -Path $relPath -ItemType Directory -Force | Out-Null
}
Copy-Item -Path "$($modulePath)\*" -Destination "$($relPath)" -Recurse -Exclude ".gitKeep","releaseNotes.txt","description.txt","*.psm1","*.psd1"
$Manifest = @{
Path = "$($relPath)\$($ModuleName).psd1"
RootModule = "$($ModuleName).psm1"
Author = $Author
CompanyName = $CompanyName
ModuleVersion = $newVersion
Description = (Get-Content ".\$($moduleName)\description.txt" -raw).ToString()
FunctionsToExport = (Get-ChildItem -Path ("$($ModulePath)\Public\*.ps1") -Recurse).BaseName
DefaultCommandPrefix = $Prefix.ToUpper()
CmdletsToExport = @()
VariablesToExport = '*'
AliasesToExport = @()
DscResourcesToExport = @()
ReleaseNotes = $releaseNotes
ProjectUri = $ProjectUri
}
#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-modulemanifest?view=powershell-7
New-ModuleManifest @Manifest
$ModuleFunctionScript = "
`$Public = @(Get-ChildItem -Path `"`$(`$PSScriptRoot)\Public\*.ps1`" -ErrorAction SilentlyContinue)
`$Private = @(Get-ChildItem -Path `"`$(`$PSScriptRoot)\Private\*.ps1`" -ErrorAction SilentlyContinue)
`$script:Prefix = `"$($Prefix)`"
`$script:Path = `"$($Path)`"
`$initCfg = @{
Path = `"`$(`$script:Path)`"
ConfigFile = `"`$(`$script:Path)\Config.json`"
SDBCab = `"Appraiser_AlternateData.cab`"
SDBUnPackerFile = Join-Path -Path `$PSScriptRoot -ChildPath `"SDBUnpacker.py`"
sdb2xmlPath = Join-Path -Path `$PSScriptRoot -ChildPath `"sdb2xml.exe`"
UserConfigFile = `"`$(`$env:USERPROFILE)\.`$(`$script:Prefix)cfgpath`"
PythonPath = `$env:Path.split(';') | Where-Object {`$_ -Like `"*Python*`" -and `$_ -notlike `"*scripts*`"}
}
`$cfg = Get-Content `$initCfg[`"UserConfigFile`"] -ErrorAction SilentlyContinue
`$script:tick = [char]0x221a
if (`$cfg) {
if (Get-Content -Path `$cfg -raw -ErrorAction SilentlyContinue) {
`$script:Config = Get-Content -Path `$cfg -raw -ErrorAction SilentlyContinue | ConvertFrom-Json
}
else {
`$script:Config = `$initCfg
}
}
else {
`$script:Config = `$initCfg
}
#endregion
#region Dot source the files
foreach (`$import in @(`$Public + `$Private)) {
try {
. `$import.FullName
}
catch {
Write-Error -Message `"Failed to import function `$(`$import.FullName): `$_`"
}
}
#endregion
If(`$Script:Config.PythonPath -and (Test-Path -Path `"`$(`$Script:Config.PythonPath)`")) {
`$PythonVersion = & `"`$(`$Script:Config.PythonPath)\python.exe`" --version
}
Else {
`$PythonVersion = & python --version
}
If(`$pythonVersion) {
[switch]`$script:PythonInstalled = `$true
}
Else {
Throw `"Python is not installed. Install Pyton before proceeding.`"
}
"
$ModuleFunctionScript | Out-File -FilePath "$($relPath)\$($ModuleName).psm1" -Encoding utf8 -Force
#endregion
#region Generate a list of public functions and update the module manifest
#$functions = @(Get-ChildItem -Path $relPath\Public\*.ps1 -ErrorAction SilentlyContinue).basename
#$params = @{
# Path = "$relPath\$ModuleName.psd1"
# ModuleVersion = $newVersion
# Description = (Get-Content .\$moduleName\description.txt -raw).ToString()
# FunctionsToExport = $functions
# ReleaseNotes = $releaseNotes.ToString()
#}
#Update-ModuleManifest @params
#endregion
}
catch {
$_
}