forked from dfinke/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSDevOps.psm1
41 lines (36 loc) · 1.73 KB
/
PSDevOps.psm1
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
#region Import Functions
foreach ($file in Get-ChildItem -Path $psScriptRoot -Filter *-*.ps1) {
. $file.FullName
}
#endregion Import Functions
#region Import Parts
# Parts are simple .ps1 files beneath a /Parts directory that can be used throughout the module.
$partsDirectory = $( # Because we want to be case-insensitive, and because it's fast
foreach ($dir in [IO.Directory]::GetDirectories($psScriptRoot)) { # [IO.Directory]::GetDirectories()
if ($dir -imatch "\$([IO.Path]::DirectorySeparatorChar)Parts$") { # and some Regex
[IO.DirectoryInfo]$dir;break # to find our parts directory.
}
})
if ($partsDirectory) { # If we have parts directory
foreach ($partFile in $partsDirectory.EnumerateFileSystemInfos()) { # enumerate all of the files.
if ($partFile.Extension -ne '.ps1') { continue } # Skip anything that's not a PowerShell script.
$partName = # Get the name of the script.
$partFile.Name.Substring(0, $partFile.Name.Length - $partFile.Extension.Length)
$ExecutionContext.SessionState.PSVariable.Set( # Set a variable
$partName, # named the script that points to the script (e.g. $foo = gcm .\Parts\foo.ps1)
$ExecutionContext.SessionState.InvokeCommand.GetCommand($partFile.Fullname, 'ExternalScript')
)
}
}
#endregion Import Parts
#region Load Extension Modules
$extensionModules =
@(
$myInvocation.MyCommand.ScriptBlock.Module
. $GetExtensionModule $MyInvocation.MyCommand.ScriptBlock.Module.Name
)
#endregion Load Extension Modules
#region Import Components
$extensionModules |
. $importComponents -ComponentRoot 'ado', 'githubactions'
#endregion Import Components