-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPsCraft.psm1
More file actions
60 lines (50 loc) · 2.04 KB
/
Copy pathPsCraft.psm1
File metadata and controls
60 lines (50 loc) · 2.04 KB
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
#!/usr/bin/env pwsh
using namespace System.Management.Automation
#Requires -Psedition Core
#requires -Modules PsModuleBase, cliHelper.core, cliHelper.logger
using module .\Private\Enums.psm1
using module .\Private\BuildLog.psm1
using module .\Private\ModuleData.psm1
using module .\Private\Orchestrator.psm1
$global:OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
# Types that will be available to users when they import the module.
# Hint: To automatically update the typestoexport variable you can use:
# .\scripts\update_exporatable_types.ps1
$typestoExport = @(
[BuildLogEntry], [BuildTaskResult], [TestResult], [BuildLog], [BuildSummary], [SaveOptions], [PSEdition], [ModuleItemAttribute], [SchemaNode], [PsModuleSchema], [PsModuleDefaults], [PsModuleData], [AliasVisitor], [ParseResult], [BuildContext], [PsModule], [PsCraft], [BuildOrchestrator]
)
$TypeAcceleratorsClass = [PsObject].Assembly.GetType('System.Management.Automation.TypeAccelerators')
# Add type accelerators for every exportable type.
foreach ($Type in $typestoExport) {
try {
[void]$TypeAcceleratorsClass::Add($Type.FullName, $Type)
} catch {
# Ignore if already exists
$null
}
}
# Remove type accelerators when the module is removed.
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
foreach ($Type in $typestoExport) {
$TypeAcceleratorsClass::Remove($Type.FullName)
}
}.GetNewClosure();
$cmdlets = @(); $Public = Get-ChildItem "$PSScriptRoot/Public" -Filter "*.ps1" -Recurse -ErrorAction SilentlyContinue
$cmdlets += Get-ChildItem "$PSScriptRoot/Private/cmdlets" -Filter "*.ps1" -Recurse -ErrorAction SilentlyContinue
$cmdlets += $Public
foreach ($file in $cmdlets) {
try {
if ([string]::IsNullOrWhiteSpace($file.fullname)) { continue }
. "$($file.fullname)"
} catch {
Write-Warning "Failed to import function $($file.BaseName): $_"
$host.UI.WriteErrorLine($_)
}
}
$Param = @{
Function = $Public.BaseName
Cmdlet = '*'
Alias = '*'
Verbose = $false
}
Export-ModuleMember @Param