forked from couleur-tweak-tips/TweakList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildMaster.ps1
60 lines (49 loc) · 1.49 KB
/
buildMaster.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
[CmdletBinding()]
param(
[Switch]$Write, # Returns it instead of importing it
[String]$Directory = $PSScriptRoot
)
if (!$Directory) {
Write-Warning "No directory was passed, defaulting to $($PWD.Path)"
pause
}
else {
Push-Location $Directory
}
$FunctionCount = 0
$Master = [System.Text.StringBuilder]::new(@"
# This file is automatically built at every push to combine every function into a single file
using namespace System.Management.Automation # Required by Invoke-NGENpsosh
Remove-Module TweakList -ErrorAction Ignore
New-Module TweakList ([ScriptBlock]::Create({
"@)
Get-ChildItem ./helpers, ./modules -Recurse -File | ForEach-Object {
switch ($_) {
{ $_.Extension -eq '.ps1' } {
Write-Verbose "Dot-sourcing $_"
. $_.FullName
# Wait-Debugger
try {
Get-Command $_.BaseName -CommandType Function -ErrorAction Stop | Out-Null
}
catch {
Write-Host "$_ has mismatched basename/function declared" -ForegroundColor Red
break
}
$Master.Append([System.Environment]::NewLine + (Get-Content $_ -Raw)) | Out-Null
$FunctionCount++
}
} }
$Master.Append(@"
Export-ModuleMember * -Alias *
})) | Import-Module -DisableNameChecking -Global
"@) | Out-Null
$Master = $Master.ToString()
if (!$Write) {
Write-Host "Imported $FunctionCount functions"
Invoke-Expression $Master
}
else {
return $Master
}
Pop-Location