This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Chocolatier.psm1
74 lines (61 loc) · 2.33 KB
/
Chocolatier.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
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
#region Private Variables
# Current script path
[string]$ScriptPath = Split-Path (Get-Variable MyInvocation -Scope Script).Value.MyCommand.Definition -Parent
# Define provider related variables
$script:ProviderName = "Chocolatier"
$script:PackageSourceName = "Chocolatey"
$script:additionalArguments = "AdditionalArguments"
$script:AllVersions = "AllVersions"
$script:AcceptLicense = "AcceptLicense"
# Define choco related variables
$script:ChocoExeName = 'choco.exe'
# Only allow the native Chocolatey .NET library with FullCLR
if ($PSEdition -eq 'Desktop' -and -not $env:CHOCO_CLI) {
$script:NativeAPI = $true
# If Choco.exe isn't already installed, try to guess where the API files should get extracted
if (-not $env:ChocolateyInstall) {
$env:ChocolateyInstall = "$($env:ProgramData)\chocolatey"
}
}
# Utility variables
$script:FastReferenceRegex = "(?<name>[^#]*)#(?<version>[^\s]*)#(?<source>[^#]*)"
$script:ChocoSourcePropertyNames = @(
'Name',
'Location',
'Disabled',
'UserName',
'Certificate',
'Priority',
'Bypass Proxy',
'Allow Self Service',
'Visibile to Admins Only'
)
Import-LocalizedData LocalizedData -filename "$script:ProviderName.Resource.psd1"
#endregion Private Variables
#region Methods
# Load included libraries, since the manifest wont handle that for package providers
if ($script:NativeAPI) {
Get-ChildItem $ScriptPath/lib/ -Filter 'chocolatey.dll' -File | ForEach-Object {
Add-Type -Path $_.FullName
}
}
# Dot sourcing private script files
Get-ChildItem $ScriptPath/src/private -Recurse -Filter '*.ps1' -File | ForEach-Object {
. $_.FullName
}
# Load and export methods
# Dot sourcing public function files
Get-ChildItem $ScriptPath/src/public -Recurse -Filter '*.ps1' -File | ForEach-Object {
. $_.FullName
# Find all the functions defined no deeper than the first level deep and export it.
# This looks ugly but allows us to not keep any uneeded variables from polluting the module.
([System.Management.Automation.Language.Parser]::ParseInput((Get-Content -Path $_.FullName -Raw), [ref]$null, [ref]$null)).FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false) | ForEach-Object {
Export-ModuleMember $_.Name
}
}
#endregion Methods
#region Module Cleanup
$ExecutionContext.SessionState.Module.OnRemove = {
# cleanup when unloading module (if any)
}
#endregion Module Cleanup