71 lines
2 KiB
PowerShell
71 lines
2 KiB
PowerShell
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
|
|
|
|
$null = New-Module {
|
|
. "$PSScriptRoot/../../Software/powershell/Profile.ps1";
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Generates the components for creating a module installer.
|
|
|
|
.PARAMETER Name
|
|
The name of the module to install.
|
|
|
|
.PARAMETER NativeOnly
|
|
A value indicating whether the module is installed in Windows PowerShell only.
|
|
|
|
.PARAMETER NoProfile
|
|
A value indicating whether the module is not added to the profile script of users.
|
|
#>
|
|
function Get-ModuleInstallerComponents {
|
|
param(
|
|
[string] $Name,
|
|
[switch] $NativeOnly,
|
|
[switch] $NoProfile
|
|
)
|
|
|
|
@{
|
|
context = @{
|
|
name = $Name;
|
|
nativeOnly = $NativeOnly;
|
|
};
|
|
installer = {
|
|
param(
|
|
[hashtable] $Context
|
|
)
|
|
|
|
$env:PENDING_MODULE_NAME = $Context.Name;
|
|
|
|
$installAction = {
|
|
$module = $env:PENDING_MODULE_NAME;
|
|
|
|
if (-not (Get-Module -ListAvailable $module -ErrorAction SilentlyContinue)) {
|
|
Install-Module -Scope AllUsers -Force $module @args;
|
|
}
|
|
};
|
|
|
|
if (-not $Context.NativeOnly) {
|
|
& $installAction -AcceptLicense;
|
|
}
|
|
|
|
if (Test-Command powershell) {
|
|
powershell -c ($installAction.ToString());
|
|
}
|
|
|
|
Remove-Item Env:\PENDING_MODULE_NAME;
|
|
};
|
|
|
|
configurator = ($NoProfile.IsPresent) ? { } : {
|
|
param(
|
|
[hashtable] $Context
|
|
)
|
|
|
|
$name = $Context.Name;
|
|
|
|
Add-PowerShellProfileStatement `
|
|
-System `
|
|
-Category $name `
|
|
-Script "Import-Module `"$name`";";
|
|
};
|
|
}
|
|
}
|
|
};
|