-
Notifications
You must be signed in to change notification settings - Fork 240
Closed
Labels
Area-Build & ReleaseIssue-EnhancementA feature request (enhancement).A feature request (enhancement).
Description
This awesome tool RequiredModules is a complete implementation of our partial modules.json PowerShell module dependency specification, and our Invoke-Build task for parsing and installing them:
PowerShellEditorServices/PowerShellEditorServices.build.ps1
Lines 367 to 431 in 7c035bc
| task RestorePsesModules -After Build { | |
| $submodulePath = (Resolve-Path $PsesSubmodulePath).Path + [IO.Path]::DirectorySeparatorChar | |
| Write-Host "`nRestoring EditorServices modules..." | |
| # Read in the modules.json file as a hashtable so it can be splatted | |
| $moduleInfos = @{} | |
| (Get-Content -Raw $ModulesJsonPath | ConvertFrom-Json).PSObject.Properties | ForEach-Object { | |
| $name = $_.Name | |
| $body = @{ | |
| Name = $name | |
| MinimumVersion = $_.Value.MinimumVersion | |
| MaximumVersion = $_.Value.MaximumVersion | |
| AllowPrerelease = $script:IsPreview | |
| Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository } | |
| Path = $submodulePath | |
| } | |
| if (-not $name) | |
| { | |
| throw "EditorServices module listed without name in '$ModulesJsonPath'" | |
| } | |
| $moduleInfos.Add($name, $body) | |
| } | |
| if ($moduleInfos.Keys.Count -gt 0) { | |
| # `#Requires` doesn't display the version needed in the error message and `using module` doesn't work with InvokeBuild in Windows PowerShell | |
| # so we'll just use Import-Module to check that PowerShellGet 1.6.0 or higher is installed. | |
| # This is needed in order to use the `-AllowPrerelease` parameter | |
| Import-Module -Name PowerShellGet -MinimumVersion 1.6.0 -ErrorAction Stop | |
| } | |
| # Save each module in the modules.json file | |
| foreach ($moduleName in $moduleInfos.Keys) | |
| { | |
| if (Test-Path -Path (Join-Path -Path $submodulePath -ChildPath $moduleName)) | |
| { | |
| Write-Host "`tModule '${moduleName}' already detected. Skipping" | |
| continue | |
| } | |
| $moduleInstallDetails = $moduleInfos[$moduleName] | |
| $splatParameters = @{ | |
| Name = $moduleName | |
| AllowPrerelease = $moduleInstallDetails.AllowPrerelease | |
| Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository } | |
| Path = $submodulePath | |
| } | |
| # Only add Min and Max version if we're doing a stable release. | |
| # This is due to a PSGet issue with AllowPrerelease not installing the latest preview. | |
| if (!$moduleInstallDetails.AllowPrerelease) { | |
| $splatParameters.MinimumVersion = $moduleInstallDetails.MinimumVersion | |
| $splatParameters.MaximumVersion = $moduleInstallDetails.MaximumVersion | |
| } | |
| Write-Host "`tInstalling module: ${moduleName} with arguments $(ConvertTo-Json $splatParameters)" | |
| Save-Module @splatParameters | |
| } | |
| Write-Host "`n" | |
| } |
Thanks for the tip @JustinGrote
rjmholt
Metadata
Metadata
Assignees
Labels
Area-Build & ReleaseIssue-EnhancementA feature request (enhancement).A feature request (enhancement).