forked from PowerShell/PowerShellEditorServices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
99 lines (84 loc) · 2.15 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
#!/usr/bin/env pwsh
param(
[Parameter()]
[switch]
$Bootstrap,
[Parameter()]
[switch]
$Clean,
[Parameter()]
[switch]
$Test
)
$NeededTools = @{
OpenSsl = "openssl for macOS"
PowerShellGet = "PowerShellGet latest"
InvokeBuild = "InvokeBuild latest"
}
if ((-not $PSVersionTable["OS"]) -or $PSVersionTable["OS"].Contains("Windows")) {
$OS = "Windows"
} elseif ($PSVersionTable["OS"].Contains("Darwin")) {
$OS = "macOS"
} else {
$OS = "Linux"
}
function needsOpenSsl () {
if ($OS -eq "macOS") {
try {
$opensslVersion = (openssl version)
} catch {
return $true
}
}
return $false
}
function needsPowerShellGet () {
if (Get-Module -ListAvailable -Name PowerShellGet) {
return $false
}
return $true
}
function needsInvokeBuild () {
if (Get-Module -ListAvailable -Name InvokeBuild) {
return $false
}
return $true
}
function getMissingTools () {
$missingTools = @()
if (needsOpenSsl) {
$missingTools += $NeededTools.OpenSsl
}
if (needsPowerShellGet) {
$missingTools += $NeededTools.PowerShellGet
}
if (needsInvokeBuild) {
$missingTools += $NeededTools.InvokeBuild
}
return $missingTools
}
function hasMissingTools () {
return ((getMissingTools).Count -gt 0)
}
if ($Bootstrap) {
$string = "Here is what your environment is missing:`n"
$missingTools = getMissingTools
if (($missingTools).Count -eq 0) {
$string += "* nothing!`n`n Run this script without a flag to build or a -Clean to clean."
} else {
$missingTools | ForEach-Object {$string += "* $_`n"}
$string += "`nAll instructions for installing these tools can be found on PowerShell Editor Services' Github:`n" `
+ "https://github.com/powershell/PowerShellEditorServices#development"
}
Write-Host "`n$string`n"
} elseif(hasMissingTools) {
Write-Host "You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are."
} else {
if($Clean) {
Invoke-Build Clean
}
Invoke-Build Build
if($Test) {
Invoke-Build Test
}
}