forked from Faithlife/FaithlifeUtility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
61 lines (53 loc) · 1.97 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
<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.PARAMETER Target
The build script target to run.
#>
[CmdletBinding()]
Param(
[string]$Target,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
# delete cake directory if script changed
$CakeDirPath = Join-Path $PSScriptRoot "cake"
$PackagesConfigPath = Join-Path $CakeDirPath "packages.config"
If ((Test-Path $PackagesConfigPath) -and ((Get-Item(Join-Path $PSScriptRoot "build.cake")).LastWriteTime -gt (Get-Item($PackagesConfigPath)).LastWriteTime)) {
Write-Host "Cake script changed; rebuilding cake directory."
Remove-Item $CakeDirPath -Force -Recurse
}
# create cake directory
New-Item -Path $CakeDirPath -Type Directory -ErrorAction SilentlyContinue | Out-Null
# create packages.config
If (!(Test-Path $PackagesConfigPath)) {
[System.IO.File]::WriteAllLines($PackagesConfigPath, @(
"<?xml version=`"1.0`" encoding=`"utf-8`"?>",
"<packages>",
"`t<package id=`"Cake`" version=`"0.23.0`" />",
"</packages>"))
}
# download nuget.exe if not in path and not already downloaded
$NuGetExe = Get-Command "nuget.exe" -ErrorAction SilentlyContinue
If ($NuGetExe -ne $null) {
$NuGetExePath = $NuGetExe.Path
}
Else {
$NuGetExePath = Join-Path $CakeDirPath "nuget.exe"
If (!(Test-Path $NuGetExePath)) {
Invoke-WebRequest -Uri http://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NuGetExePath
}
}
# use NuGet to download Cake
Push-Location $CakeDirPath
Invoke-Expression "&`"$NuGetExePath`" install -ExcludeVersion -OutputDirectory ."
If ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet tools."
}
Pop-Location
# run Cake with specified arguments
$CakeExePath = Join-Path $CakeDirPath "Cake/Cake.exe"
$ExtraArgs = ""
if ($Target) { $ExtraArgs += "--target=$Target" }
Invoke-Expression "& `"$CakeExePath`" --paths_tools=cake --experimental $ExtraArgs $ScriptArgs"
Exit $LASTEXITCODE