-
Notifications
You must be signed in to change notification settings - Fork 51
/
ChocolateyPack.ps1
78 lines (65 loc) · 1.83 KB
/
ChocolateyPack.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]
$apiKey,
[Parameter(Mandatory = $false, Position=0)]
[string]
[ValidateSet('Push','Pack')]
$operation = 'Push',
[Parameter(Mandatory = $false, Position=1)]
[string]
$source = 'http://chocolatey.org'
)
function Get-CurrentDirectory
{
$thisName = $MyInvocation.MyCommand.Name
[IO.Path]::GetDirectoryName((Get-Content function:$thisName).File)
}
function Get-NugetPath
{
Write-Host 'Executing Get-NugetPath'
Get-ChildItem -Path (Get-CurrentDirectory) -Include 'nuget.exe' -Recurse |
Select -ExpandProperty FullName -First 1
}
function Restore-Nuget
{
Write-Host 'Executing Restore-Nuget'
$nuget = Get-NugetPath
if ($nuget -ne $null)
{
&"$nuget" update -Self | Write-Host
return $nuget
}
$nugetPath = Join-Path (Get-CurrentDirectory) 'nuget.exe'
(New-Object Net.WebClient).DownloadFile('http://nuget.org/NuGet.exe', $nugetPath)
return Get-NugetPath
}
function Invoke-Pack
{
$currentDirectory = Get-CurrentDirectory
Write-Host "Running against $currentDirectory"
Get-ChildItem -Path $currentDirectory -Filter *.nuspec -Recurse |
% {
$csproj = Join-Path $_.DirectoryName ($_.BaseName + '.csproj')
if (Test-Path $csproj)
{
&$script:nuget pack "$csproj" -Prop Configuration=Release -Exclude '**\*.CodeAnalysisLog.xml'
}
else
{ &$script:nuget pack $_.FullName }
}
}
function Invoke-Push
{
Get-ChildItem *.nupkg |
% {
Write-Host "Value of source -> $source"
if ($source -eq '') { &$script:nuget push $_ $apiKey }
else { &$script:nuget push $_ $apiKey -source $source }
}
}
$script:nuget = Restore-Nuget
del *.nupkg
Invoke-Pack
if ($operation -eq 'Push') { Invoke-Push }
del *.nupkg