Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions InstallModuleFromGitHub.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ function Install-ModuleFromGitHub {
Process {
if($PSBoundParameters.ContainsKey("ProjectUri")) {
$GitHubRepo = $null
if($ProjectUri.OriginalString.StartsWith("https://github.com")) {
if($ProjectUri.OriginalString.StartsWith("https://github.com") -or $ProjectUri.OriginalString.StartsWith("https://bitbucket.org")) {
$GitHubRepo = $ProjectUri.AbsolutePath
} else {
$name=$ProjectUri.LocalPath.split('/')[-1]
Write-Host -ForegroundColor Red ("Module [{0}]: not installed, it is not hosted on GitHub " -f $name)
Write-Host -ForegroundColor Red ("Module [{0}]: not installed, it is not hosted on GitHub or BitBucket " -f $name)
}
}

if($GitHubRepo) {
Write-Verbose ("[$(Get-Date)] Retrieving {0} {1}" -f $GitHubRepo, $Branch)

$url = "https://github.com/{0}/archive/{1}.zip" -f $GitHubRepo, $Branch
if ($ProjectUri.OriginalString.StartsWith("https://github.com")){
$url = "https://github.com/{0}/archive/{1}.zip" -f $GitHubRepo, $Branch
}
elseif($ProjectUri.OriginalString.StartsWith("https://bitbucket.org")){
$url = "https://bitbucket.org/{0}/get/{1}.zip" -f $GitHubRepo, $Branch
}

$targetModuleName=$GitHubRepo.split('/')[-1]
Write-Debug "targetModuleName: $targetModuleName"

Expand All @@ -42,16 +48,15 @@ function Install-ModuleFromGitHub {
}

Expand-Archive -Path $OutFile -DestinationPath $tmpDir -Force

$unzippedArchive = "$($targetModuleName)-$($Branch)"
$unzippedArchive = (Get-ChildItem $tmpDir| Where-Object {$_.LastWriteTime -gt $(get-date).AddMinutes(-2) -and $_.Name -like "*$targetModuleName*"}).Name
Write-Debug "targetModule: $targetModule"

if ($IsLinux -or $IsOSX) {
$dest = Join-Path -Path $HOME -ChildPath ".local/share/powershell/Modules"
}

else {
$dest = "C:\Program Files\WindowsPowerShell\Modules"
$dest = [Environment]::GetFolderPath("MyDocuments")+"\WindowsPowerShell\"
}

if($DestinationPath) {
Expand All @@ -67,7 +72,7 @@ function Install-ModuleFromGitHub {
$dest = Join-Path -Path $dest -ChildPath $ModuleVersion
}

$null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)/*" $dest -Force
$null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)/*" $dest -Force -Recurse
}
}
}
Expand Down