1
+ # !/usr/bin/env pwsh
2
+ param (
3
+ [Parameter ()]
4
+ [switch ]
5
+ $Bootstrap ,
6
+
7
+ [Parameter ()]
8
+ [switch ]
9
+ $Clean ,
10
+
11
+ [Parameter ()]
12
+ [switch ]
13
+ $Test
14
+ )
15
+
16
+ $NeededTools = @ {
17
+ OpenSsl = " openssl for macOS"
18
+ PowerShellGet = " PowerShellGet latest"
19
+ InvokeBuild = " InvokeBuild latest"
20
+ }
21
+
22
+ if ((-not $PSVersionTable [" OS" ]) -or $PSVersionTable [" OS" ].Contains(" Windows" )) {
23
+ $OS = " Windows"
24
+ } elseif ($PSVersionTable [" OS" ].Contains(" Darwin" )) {
25
+ $OS = " macOS"
26
+ } else {
27
+ $OS = " Linux"
28
+ }
29
+
30
+
31
+ function needsOpenSsl () {
32
+ if ($OS -eq " macOS" ) {
33
+ try {
34
+ $opensslVersion = (openssl version)
35
+ } catch {
36
+ return $true
37
+ }
38
+ }
39
+ return $false
40
+ }
41
+
42
+ function needsPowerShellGet () {
43
+ if (Get-Module - ListAvailable - Name PowerShellGet) {
44
+ return $false
45
+ }
46
+ return $true
47
+ }
48
+
49
+ function needsInvokeBuild () {
50
+ if (Get-Module - ListAvailable - Name InvokeBuild) {
51
+ return $false
52
+ }
53
+ return $true
54
+ }
55
+
56
+ function getMissingTools () {
57
+ $missingTools = @ ()
58
+
59
+ if (needsOpenSsl) {
60
+ $missingTools += $NeededTools.OpenSsl
61
+ }
62
+ if (needsPowerShellGet) {
63
+ $missingTools += $NeededTools.PowerShellGet
64
+ }
65
+ if (needsInvokeBuild) {
66
+ $missingTools += $NeededTools.InvokeBuild
67
+ }
68
+
69
+ return $missingTools
70
+ }
71
+
72
+ function hasMissingTools () {
73
+ return ((getMissingTools).Count -gt 0 )
74
+ }
75
+
76
+ if ($Bootstrap ) {
77
+ $string = " Here is what your environment is missing:`n "
78
+ $missingTools = getMissingTools
79
+ if (($missingTools ).Count -eq 0 ) {
80
+ $string += " * nothing!`n`n Run this script without a flag to build or a -Clean to clean."
81
+ } else {
82
+ $missingTools | ForEach-Object {$string += " * $_ `n " }
83
+ $string += " `n All instructions for installing these tools can be found on PowerShell Editor Services' Github:`n " `
84
+ + " https://github.com/powershell/PowerShellEditorServices#development"
85
+ }
86
+ Write-Host " `n $string `n "
87
+ } elseif (hasMissingTools) {
88
+ Write-Host " You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are."
89
+ } else {
90
+ if ($Clean ) {
91
+ Invoke-Build Clean
92
+ }
93
+
94
+ Invoke-Build Build
95
+
96
+ if ($Test ) {
97
+ Invoke-Build Test
98
+ }
99
+ }
0 commit comments