-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.ps1
70 lines (55 loc) · 1.83 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
[CmdletBinding(DefaultParameterSetName = 'testing')]
param(
[Parameter(ParameterSetName = 'building')]
[string[]]$Names,
[switch]$Build,
[switch]$Install,
[Parameter(ParameterSetName = 'testing')]
[switch]$Test
)
$outputDirectory = "$PSScriptRoot\_output"
$packagesDirectory = "$outputDirectory\packages"
if (!(Test-Path $outputDirectory)) {
$null = New-Item $outputDirectory -ItemType Directory
}
if (!(Test-Path $packagesDirectory)) {
$null = New-Item $packagesDirectory -ItemType Directory
}
if ($null -ne $Names) {
$Names = $Names | ForEach-Object { if (!$_.EndsWith('.template')) { "$_.template" } else { $_ } }
}
function Build-AllTemplates {
$null = Remove-Item "$packagesDirectory\*.nupkg"
$nuspecs = Get-ChildItem "$PSScriptRoot\src" -Filter '*.nuspec' -Recurse | Where-Object {
$null -eq $Names -or $_.BaseName -in $Names
}
$nuspecs | ForEach-Object {
"Building template $($_.BaseName)"
Start-Process 'choco' -ArgumentList 'pack', $_.FullName, '--out', "$packagesDirectory" -Wait -NoNewWindow
}
}
function Install-PackageTemplates {
$names = (Get-ChildItem "$PSScriptRoot\src" -Filter '*.nuspec' -Recurse | Where-Object {
$null -eq $Names -or $_.BaseName -in $Names
} | ForEach-Object BaseName) -join " "
Start-Process 'choco' -ArgumentList 'install', $names, '-y', '--source', "$packagesDirectory" -Wait -NoNewWindow
}
function Invoke-PesterTests {
$null = Remove-Item "$outputDirectory\tests" -Recurse -ErrorAction Ignore
Invoke-Pester -Path "$PSScriptRoot\test" -Output Detailed
}
if (!$Build -and !$Install -and !$Test) {
$Build = $Install = $true
if ($null -eq $Names) {
$Test = $true
}
}
if ($Build) {
Build-AllTemplates
}
if ($Install) {
Install-PackageTemplates
}
if ($Test) {
Invoke-PesterTests
}