Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docs/Get-GitModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Accept wildcard characters: False

### -Name
You can query already installed modules for their online version if ProjectUri is specified in the module info.
To do this, just specify module name(s) with parameter -Names.
To do this, just specify module name(s) with parameter -Name.

```yaml
Type: String[]
Expand Down
24 changes: 23 additions & 1 deletion Docs/Update-GitModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ This cmdlet updates previously installed PowerShell module specified by its git

## SYNTAX

### ByUri
```
Update-GitModule [-ProjectUri] <String[]> [-Branch <String>] [-DestinationPath <String>] [-Force]
[<CommonParameters>]
```

### ByName
```
Update-GitModule -Name <String[]> [-Branch <String>] [-DestinationPath <String>] [-Force] [<CommonParameters>]
```

## DESCRIPTION

This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.
Expand Down Expand Up @@ -92,6 +98,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Name
You can update already installed modules with their git online version if ProjectUri is specified in the module info.
To do this, just specify module name(s) with parameter -Name.

```yaml
Type: String[]
Parameter Sets: ByName
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ProjectUri
Mandatory parameter specifying URL or the repository.
Multiple values are supported.
Expand All @@ -102,7 +124,7 @@ You can pass this parameter also via pipeline, for example via \`Find-Module\` b

```yaml
Type: String[]
Parameter Sets: (All)
Parameter Sets: ByUri
Aliases:

Required: True
Expand Down
27 changes: 27 additions & 0 deletions Private/ConvertTo-Uri.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function ConvertTo-Uri {
# converts array of module names to uris based on projectUri field

param (
[Parameter(Mandatory)]
[string[]]$Name
)

Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names"
foreach ($N1 in $Name) {
$Module = Get-InstalledModule $N1 -ea 0
if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0}

if (!$Module) {
Write-Error "$FunctionName found no module $N1"
continue
}

if (!($Module | ? ProjectUri)) {
Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information"
continue
}

# return information to $ProjectUri variable
$Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri
}
}
22 changes: 1 addition & 21 deletions Public/Get-GitModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,7 @@ function Get-GitModule {
$tmpRoot = [System.IO.Path]::GetTempPath()
}

if ($Name) {
Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names"
$ProjectUri = foreach ($N1 in $Name) {
$Module = Get-InstalledModule $N1 -ea 0
if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0}

if (!$Module) {
Write-Error "$FunctionName found no module $N1"
continue
}

if (!($Module | ? ProjectUri)) {
Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information"
continue
}

# return information to $ProjectUri variable
$Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri

}
}
if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name}

}

Expand Down
7 changes: 6 additions & 1 deletion Public/Update-GitModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ function Update-GitModule {
param (


[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)]
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0,ParameterSetName='ByUri')]
[string[]]$ProjectUri,
# https://github.com/dfinke/InstallModuleFromGitHub
# https://github.com/iricigor/FIFA2018

[Parameter(Mandatory,ParameterSetName='ByName')]
[string[]]$Name,

[string]$Branch = "master",
[string]$DestinationPath = (Get-InstallPath),
[switch]$Force
Expand All @@ -31,6 +34,8 @@ function Update-GitModule {
$tmpRoot = [System.IO.Path]::GetTempPath()
}

if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name}

}

PROCESS {
Expand Down
30 changes: 30 additions & 0 deletions Tests/functions/Update-GitModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ Describe "$CommandName basic testing" -Tag 'Functionality' {

}

Describe "$CommandName byName testing" -Tag 'Functionality' {


$moduleName = 'FIFA2018'
$moduleURL = 'https://github.com/iricigor/' + $moduleName

$ExistingModule = Get-InstalledModule $moduleName -ea 0
It 'Should uninstall again module if installed' -Skip:($ExistingModule -eq $null) {
{Uninstall-Module $moduleName} | Should -Not -Throw
}

# its not so easy to remove PowerShell module
$ExistingModule = Get-Module $moduleName -ListAvailable
It 'Should delete again module if still found' -Skip:($ExistingModule -eq $null) {
{Split-Path ($ExistingModule.Path) -Parent | Remove-Item -Force -Recurse} | Should -Not -Throw
}

It 'Should install again module from PSGallery' {
$OldProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
{Install-Module $moduleName -Repository PSGallery -Scope CurrentUser -Force} | Should -Not -Throw
$ProgressPreference = $OldProgressPreference
}

It 'Should update module byName to newer version' {
Update-GitModule -Name $moduleName -Force | Should -Not -Be $null
}

}


Describe "$CommandName error handling" -Tag 'Functionality' {

Expand Down