-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nuget bootstrap, PSGalleryOptions
- Loading branch information
1 parent
5667e5e
commit fa5bdb6
Showing
7 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nuget.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# You can use the following: | ||
# Absolute paths | ||
# Relative paths | ||
# UNC paths | ||
# $ModuleRoot as "the path to the PSDepend module folder" | ||
$ModuleRoot\nuget.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Check for nuget exe. If it doesn't exist, create full path to parent, and download it | ||
function BootStrap-Nuget { | ||
[cmdletbinding()] | ||
param( | ||
$NugetPath = "$env:APPDATA\nuget.exe" | ||
) | ||
|
||
if($c = Get-Command 'nuget.exe' -ErrorAction SilentlyContinue) | ||
{ | ||
write-verbose "Found Nuget at [$($c.path)]" | ||
return | ||
} | ||
|
||
#Don't have it, download it | ||
$Parent = Split-Path $NugetPath -Parent | ||
if(-not (Test-Path $NugetPath)) | ||
{ | ||
if(-not (Test-Path $Parent)) | ||
{ | ||
Write-Verbose "Creating parent paths to [$NugetPath]'s parent: [$Parent]" | ||
mkdir $Parent -Force | ||
} | ||
Write-Verbose "Downloading nuget to [$NugetPath]" | ||
Invoke-WebRequest -uri 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $NugetPath | ||
} | ||
|
||
# Add to path | ||
if( ($ENV:Path -split ';') -notcontains $Parent ) | ||
{ | ||
$ENV:Path = $ENV:Path, $Parent -join ';' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# All credit and major props to Joel Bennett for this simplified solution that doesn't depend on PowerShellGet | ||
# https://gist.github.com/Jaykul/1caf0d6d26380509b04cf4ecef807355 | ||
function Find-NugetPackage { | ||
[CmdletBinding()] | ||
param( | ||
# The name of a package to find | ||
[Parameter(Mandatory)] | ||
$Name, | ||
# The repository api URL -- like https://www.powershellgallery.com/api/v2/ or https://www.nuget.org/api/v2/ | ||
$PackageSourceUrl = 'https://www.powershellgallery.com/api/v2/', | ||
|
||
#If specified takes precedence over version | ||
[switch]$IsLatest, | ||
|
||
[string]$Version | ||
) | ||
|
||
#Ugly way to do this. Prefer islatest, otherwise look for version, otherwise grab all matching modules | ||
if($IsLatest) | ||
{ | ||
Write-Verbose "Searching for latest [$name] module" | ||
$URI = "${PackageSourceUrl}Packages?`$filter=Id eq '$name' and IsLatestVersion" | ||
} | ||
elseif($PSBoundParameters.ContainsKey($Version)) | ||
{ | ||
Write-Verbose "Searching for version [$version] of [$name]" | ||
$URI = "${PackageSourceUrl}Packages?`$filter=Id eq '$name' and Version eq '$Version'" | ||
} | ||
else | ||
{ | ||
Write-Verbose "Searching for all versions of [$name] module" | ||
$URI = "${PackageSourceUrl}Packages?`$filter=Id eq '$name'" | ||
} | ||
|
||
Invoke-RestMethod $URI | | ||
Select-Object @{n='Name';ex={$_.title.('#text')}}, | ||
@{n='Author';ex={$_.author.name}}, | ||
@{n='Version';ex={$_.properties.NormalizedVersion}}, | ||
@{n='Uri';ex={$_.Content.src}}, | ||
@{n='Description';ex={$_.properties.Description}}, | ||
@{n='Properties';ex={$_.properties}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# All credit and major props to Joel Bennett for this simplified solution that doesn't depend on PowerShellGet | ||
# https://gist.github.com/Jaykul/1caf0d6d26380509b04cf4ecef807355 | ||
function Save-NugetPackage { | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(ValueFromPipelineByPropertyName,Mandatory)]$Name, | ||
[Parameter(ValueFromPipelineByPropertyName,Mandatory)]$Uri, | ||
[Parameter(ValueFromPipelineByPropertyName)]$Version="", | ||
[string]$Path = $pwd | ||
) | ||
$Path = (Join-Path $Path "$Name.$Version.nupkg") | ||
Invoke-WebRequest $Uri -OutFile $Path | ||
Get-Item $Path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters