This repository has been archived by the owner on Apr 10, 2020. It is now read-only.
forked from raspberry-sharp/raspberry-sharp-io
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.common.ps1
90 lines (76 loc) · 2.52 KB
/
build.common.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
79
80
81
82
83
84
85
86
87
88
89
90
$Script:UseWriteHost = $true
if(!$Global:ColorScheme) {
$Global:ColorScheme = @{
"Banner"=[ConsoleColor]::Cyan
"RuntimeName"=[ConsoleColor]::Yellow
"Help_Header"=[ConsoleColor]::Yellow
"Help_Switch"=[ConsoleColor]::Green
"Help_Argument"=[ConsoleColor]::Cyan
"Help_Optional"=[ConsoleColor]::Gray
"Help_Command"=[ConsoleColor]::DarkYellow
"Help_Executable"=[ConsoleColor]::DarkYellow
"ParameterName"=[ConsoleColor]::Cyan
"Warning" = [ConsoleColor]::Yellow
}
}
function _WriteOut {
param(
[Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true)][string]$msg,
[Parameter(Mandatory=$false)][ConsoleColor]$ForegroundColor,
[Parameter(Mandatory=$false)][ConsoleColor]$BackgroundColor,
[Parameter(Mandatory=$false)][switch]$NoNewLine)
if($__TestWriteTo) {
$cur = Get-Variable -Name $__TestWriteTo -ValueOnly -Scope Global -ErrorAction SilentlyContinue
$val = $cur + "$msg"
if(!$NoNewLine) {
$val += [Environment]::NewLine
}
Set-Variable -Name $__TestWriteTo -Value $val -Scope Global -Force
return
}
if(!$Script:UseWriteHost) {
if(!$msg) {
$msg = ""
}
if($NoNewLine) {
[Console]::Write($msg)
} else {
[Console]::WriteLine($msg)
}
}
else {
try {
if(!$ForegroundColor) {
$ForegroundColor = $host.UI.RawUI.ForegroundColor
}
if(!$BackgroundColor) {
$BackgroundColor = $host.UI.RawUI.BackgroundColor
}
Write-Host $msg -ForegroundColor:$ForegroundColor -BackgroundColor:$BackgroundColor -NoNewLine:$NoNewLine
} catch {
$Script:UseWriteHost = $false
_WriteOut $msg
}
}
}
function _WriteConfig{
param(
[Parameter(Mandatory=$true,Position=0)]$name,
[Parameter(Mandatory=$true,Position=1)]$value)
_WriteOut -NoNewline -ForegroundColor $Global:ColorScheme.ParameterName "${name}: "
_WriteOut "$value"
}
function _DownloadNuget{
param(
[Parameter(Mandatory=$true,Position=0)]$rootPath)
$sourceNugetExe = "http://nuget.org/nuget.exe"
$targetNugetExe = "$rootPath\nuget.exe"
if(!(Test-Path $targetNugetExe )){
_WriteOut "Downloading nuget to $targetNugetExe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
}
else{
# _WriteOut "nuget.exe is already present"
}
Set-Alias nuget $targetNugetExe -Scope Global
}