forked from code-cracker/code-cracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
68 lines (61 loc) · 1.72 KB
/
build.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
$ErrorActionPreference = "Stop"
# functions:
function IsNugetVersion3($theNugetExe) {
try {
$nugetText = . $theNugetExe | Out-String
} catch {
return false
}
[regex]$regex = '^NuGet Version: (.*)\n'
$match = $regex.Match($nugetText)
$version = $match.Groups[1].Value
return $version.StartsWith(3)
}
function Get-Nuget {
if (gcm nuget -ErrorAction SilentlyContinue) {
if (IsNugetVersion3 'nuget') {
return 'nuget'
} else {
Download-Nuget
return $localNuget
}
} else {
Download-Nuget
return $localNuget
}
}
function Download-Nuget {
$tempNuget = "$env:TEMP\codecracker\nuget.exe"
if (!(Test-Path "$env:TEMP\codecracker\")) {
md "$env:TEMP\codecracker\"
}
if (Test-Path $localNuget) {
if (IsNugetVersion3($localNuget)) { return }
}
if (Test-Path $tempNuget) {
if (IsNugetVersion3($tempNuget)) {
cp $tempNuget $localNuget
return
}
}
wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $tempNuget
cp $tempNuget $localNuget
}
function Import-Psake {
$psakeModule = "$PSScriptRoot\packages\psake.4.5.0\tools\psake.psm1"
if ((Test-Path $psakeModule) -ne $true) {
. $nugetExe restore $PSScriptRoot\.nuget\packages.config -SolutionDirectory $PSScriptRoot
}
Import-Module $psakeModule -force
}
# statements:
$localNuget = "$PSScriptRoot\.nuget\nuget.exe"
$nugetExe = Get-Nuget
Import-Psake
if ($MyInvocation.UnboundArguments.Count -ne 0) {
. $PSScriptRoot\psake.ps1 -taskList ($MyInvocation.UnboundArguments -join " ")
}
else {
. $PSScriptRoot\build.ps1 Build
}
exit !($psake.build_success)