-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.ps1
153 lines (133 loc) · 4.23 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
[cmdletbinding()]
param()
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$scriptDir = ((Get-ScriptDirectory) + "\")
$global:buildsettings = New-Object -TypeName psobject -Property @{
SourceRoot = ($scriptDir)
}
function InternalOverrideSettingsFromEnv{
[cmdletbinding()]
param(
[Parameter(Position=0)]
[object[]]$settings = ($global:PSBuildSettings),
[Parameter(Position=1)]
[string]$prefix = 'PSBuild'
)
process{
foreach($settingsObj in $settings){
if($settingsObj -eq $null){
continue
}
$settingNames = $null
if($settingsObj -is [hashtable]){
$settingNames = $settingsObj.Keys
}
else{
$settingNames = ($settingsObj | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name)
}
foreach($name in ($settingNames.Clone())){
$fullname = ('{0}{1}' -f $prefix,$name)
if(Test-Path "env:$fullname"){
'Updating setting [{0}] to [{1}]' -f ($settingsObj.$name),((get-childitem "env:$fullname").Value) | Write-Verbose
$settingsObj.$name = ((get-childitem "env:$fullname").Value)
}
}
}
}
}
InternalOverrideSettingsFromEnv -settings $global:buildsettings
<#
.SYNOPSIS
You can add this to you build script to ensure that psbuild is available before calling
Invoke-MSBuild. If psbuild is not available locally it will be downloaded automatically.
#>
function EnsurePsbuildInstlled{
[cmdletbinding()]
param(
[string]$psbuildInstallUri = 'https://raw.githubusercontent.com/ligershark/psbuild/master/src/GetPSBuild.ps1'
)
process{
if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){
'Installing psbuild from [{0}]' -f $psbuildInstallUri | Write-Verbose
(new-object Net.WebClient).DownloadString($psbuildInstallUri) | iex
}
else{
'psbuild already loaded, skipping download' | Write-Verbose
}
# make sure it's loaded and throw if not
if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){
throw ('Unable to install/load psbuild from [{0}]' -f $psbuildInstallUri)
}
}
}
function EnsureDirectoryExists{
[cmdletbinding()]
param(
[string]$path
)
process{
if(-not (Test-Path $path)){
New-Item -Path $path -ItemType Directory
}
}
}
function CopyFiles{
[cmdletbinding()]
param(
$files
)
process{
foreach($file in $files){
$src = $file.Source
$dest = $file.Dest
EnsureDirectoryExists (Split-Path $dest -Parent)
@'
Copy
src: {0}
dest: {1}
'@ -f $src, $dest | Write-Verbose
Copy-Item -LiteralPath $src -Destination $dest
}
}
}
function CopyStaticFilesToOtherProjects{
[cmdletbinding()]
param(
[string]$srcRoot = ($global:buildsettings.SourceRoot)
)
process{
$filesToCopy =
<# The file is customized on purpose, don't overwrite it
@{
'Source'=(Join-Path $srcRoot 'templatepack.proj')
'Dest' = (join-path $srcRoot 'SideWaffle.Creator\template\templatepack.proj')
},#>
@{
'Source'=(Join-Path $srcRoot 'templatepack.SideWaffle.Template.proj')
'Dest' = (join-path $srcRoot 'templates\SideWaffle.Template\template\templatepack.SideWaffle.Template.proj')
},
@{
'Source'=(Join-Path $srcRoot 'wafflebuilder.targets')
'Dest' = (join-path $srcRoot 'SideWaffle.Creator\Properties\wafflebuilder.targets')
},
@{
'Source'=(Join-Path $srcRoot 'wafflebuilder.targets')
'Dest' = (join-path $srcRoot 'templates\SideWaffle.Template\Properties\wafflebuilder.targets')
}
CopyFiles -files $filesToCopy
}
}
function BuildAll{
[cmdletbinding()]
param()
process{
'Build started' | Write-Output
CopyStaticFilesToOtherProjects
}
}
# start script
BuildAll