Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df85d15

Browse files
committedJul 5, 2024·
Made much faster by only installing missing dependencies unless -Force is specified.
1 parent 652a128 commit df85d15

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed
 

‎build/Install-Dependencies.ps1

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,40 @@ param(
1010

1111
[ValidateScript({ Test-Path $_ })]
1212
[string]
13-
$ModuleSettingsPath
13+
$ModuleSettingsPath,
14+
15+
# Force installation of required modules, even if they are already installed.
16+
[switch]
17+
$Force
1418
)
1519

1620
. "$psscriptroot/common-functions.ps1"
1721

1822
$settingPath = "$PSScriptRoot/../module/$ModuleName/config/ModuleSettings.json"
1923
if ($ModuleSettingsPath) { $settingPath = $ModuleSettingsPath }
2024
$content = Get-Content -Path $settingPath | ConvertFrom-Json
21-
Write-Verbose("Installing Module $($content.sourceModule)")
22-
Install-Module $content.sourceModule -scope currentuser -Force -AllowClobber
2325

24-
foreach ($moduleName in $content.destinationModuleName){
25-
Write-Verbose("Installing Module $($moduleName)")
26-
Install-Module $moduleName -scope currentuser -RequiredVersion $content.destinationModuleVersion -Force -AllowClobber
27-
}
26+
if ($Force) {
27+
Write-Verbose 'Skipping the check for installed prerequisites.'
28+
} else {
29+
Write-Verbose 'Checking installed modules for required dependencies.'
30+
$InstalledModules = Get-Module -ListAvailable -Verbose:$false | Group-Object -Property Name
31+
}
32+
33+
$SourceModule = $content.sourceModule
34+
if (($InstalledModules.Name -contains $SourceModule) -and -not $Force) {
35+
Write-Verbose "The $SourceModule module is already installed."
36+
} else {
37+
Write-Verbose("Installing Module: $sourceModule")
38+
Install-Module $sourceModule -Scope CurrentUser -Force -AllowClobber
39+
}
40+
41+
foreach ($moduleName in $content.destinationModuleName) {
42+
$InstalledModuleReference = $InstalledModules.Where({ $_.Name -eq $moduleName }).Group
43+
if (($InstalledModuleReference.Version -ge $content.destinationModuleVersion) -and -not $Force) {
44+
Write-Verbose "The $moduleName module is already installed."
45+
} else {
46+
Write-Verbose "Installing Module: $moduleName"
47+
Install-Module $moduleName -Scope CurrentUser -RequiredVersion $content.destinationModuleVersion -Force -AllowClobber
48+
}
49+
}

0 commit comments

Comments
 (0)
Please sign in to comment.