Skip to content
This repository
tree: 756d179e5a
Fetching contributors…

Cannot retrieve contributors at this time

file 137 lines (111 sloc) 3.323 kb
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
$default_source = ""
$version_packages = $false

function version_packages
{
$script:version_packages = $true
}

function source
{
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $source = $null
)

$script:default_source = $source
}

function FileExistsInPath
{
param (
[Parameter(Position=0,Mandatory=$true)]
[string] $fileName = $null
)

$path = Get-Childitem Env:Path
$found = $false
foreach ($folder in $path.Value.Split(";")) { if (Test-Path "$folder\$fileName") { $found = $true; break } }
Write-Output $found
}

function install_to
{
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $path = $null
)

if(!(test-path $path))
{
if([System.IO.Path]::IsPathRooted($path))
{
$drive_letter = [System.IO.Path]::GetPathRoot($path)
$directory_name = $path.Replace($drive_letter, "")
new-item -path $drive_letter -name $directory_name -itemtype directory
}
else
{
new-item -path . -name $path -itemtype directory
}
}

push-location $path -stackname 'chewie_nuget'
}

function chocolate
{
  [CmdletBinding()]
param (
[Parameter(Position=0,Mandatory=$true)]
[string] $name = $null,

[Parameter(Position=1,Mandatory=$false)]
[alias("v")]
[string] $version = "",

[Parameter(Position=2,Mandatory=$false)]
[alias("s")]
[string] $source = ""
)
  
  $choco_install = $env:ChocolateyInstall
  
  if($choco_install -eq $null -or (test-path $choco_install -ErrorAction SilentlyContinue) -eq $false){
    Write-Host "you need to have chocolatey installed before you can use the chocolate commands"
    return
  }
   
$command = "chocolatey install $name"

if($version -ne "") { $command += " -v $version" }
if($source -eq "" -and $script:default_source -ne "") { $source = $script:default_source }
if($source -ne "") { $command += " -s $source" }

invoke-expression $command

}

function chew
{
[CmdletBinding()]
param (
[Parameter(Position=0,Mandatory=$true)]
[string] $name = $null,

[Parameter(Position=1,Mandatory=$false)]
[alias("v")]
[string] $version = "",

[Parameter(Position=2,Mandatory=$false)]
[alias("s")]
[string] $source = ""
)

$nuGetIsInPath = (FileExistsInPath "NuGet.exe") -or (FileExistsInPath "NuGet.bat")
$command = ""
if($nuGetIsInPath)
{
$command += "NuGet install"
if($script:version_packages -ne $true){$command += " -x"}

} else { $command += "install-package" }
$command += " $name"

if($version -ne "") { $command += " -v $version" }
if($source -eq "" -and $script:default_source -ne "") { $source = $script:default_source }
if($source -ne "") { $command += " -s $source" }

invoke-expression $command
}

function Invoke-Chewie
{
gc $pwd\.NugetFile | Foreach-Object { $block = [scriptblock]::Create($_.ToString()); % $block; }
if((get-location -stackname 'chewie_nuget').count -gt 0) { pop-location -stackname 'chewie_nuget' }
}

function Initialize-Chewie
{
if(!(test-path $pwd\.NugetFile))
{
new-item -path $pwd -name .NugetFile -itemtype file
add-content $pwd\.NugetFile "install_to 'lib'"
add-content $pwd\.NugetFile "chew 'machine.specifications'"
add-content $pwd\.NugetFile "chocolate 'console2'"
}
}
Something went wrong with that request. Please try again.