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
+ VSCode = " Visual Studio Code"
18
+ NodeJS = " Node.js 6.0 or higher"
19
+ PowerShellGet = " PowerShellGet latest"
20
+ InvokeBuild = " InvokeBuild latest"
21
+ }
22
+
23
+ if ((-not $PSVersionTable [" OS" ]) -or $PSVersionTable [" OS" ].Contains(" Windows" )) {
24
+ $OS = " Windows"
25
+ } elseif ($PSVersionTable [" OS" ].Contains(" Darwin" )) {
26
+ $OS = " macOS"
27
+ } else {
28
+ $OS = " Linux"
29
+ }
30
+
31
+
32
+ function needsVSCode () {
33
+ try {
34
+ $vscodeVersion = (code - v)
35
+ if (-not $vscodeVersion ) {
36
+ Throw
37
+ }
38
+ } catch {
39
+ try {
40
+ $vscodeInsidersVersion = (code- insiders - v)
41
+ if (-not $vscodeInsidersVersion ) {
42
+ Throw
43
+ }
44
+ } catch {
45
+ return $true
46
+ }
47
+ }
48
+ return $false
49
+ }
50
+
51
+ function needsNodeJS () {
52
+ try {
53
+ $nodeJSVersion = (node - v)
54
+
55
+ } catch {
56
+ return $true
57
+ }
58
+ return ($nodeJSVersion.Substring (1 , 1 ) -lt 6 )
59
+ }
60
+
61
+ function needsPowerShellGet () {
62
+ if (Get-Module - ListAvailable - Name PowerShellGet) {
63
+ return $false
64
+ }
65
+ return $true
66
+ }
67
+
68
+ function needsInvokeBuild () {
69
+ if (Get-Module - ListAvailable - Name InvokeBuild) {
70
+ return $false
71
+ }
72
+ return $true
73
+ }
74
+
75
+ function getMissingTools () {
76
+ $missingTools = @ ()
77
+
78
+ if (needsVSCode) {
79
+ $missingTools += $NeededTools.VSCode
80
+ }
81
+ if (needsNodeJS) {
82
+ $missingTools += $NeededTools.NodeJS
83
+ }
84
+ if (needsPowerShellGet) {
85
+ $missingTools += $NeededTools.PowerShellGet
86
+ }
87
+ if (needsInvokeBuild) {
88
+ $missingTools += $NeededTools.InvokeBuild
89
+ }
90
+
91
+ return $missingTools
92
+ }
93
+
94
+ function hasMissingTools () {
95
+ return ((getMissingTools).Count -gt 0 )
96
+ }
97
+
98
+ if ($Bootstrap ) {
99
+ $string = " Here is what your environment is missing:`n "
100
+ $missingTools = getMissingTools
101
+ if (($missingTools ).Count -eq 0 ) {
102
+ $string += " * nothing!`n`n Run this script without a flag to build or a -Clean to clean."
103
+ } else {
104
+ $missingTools | ForEach-Object {$string += " * $_ `n " }
105
+ $string += " `n All instructions for installing these tools can be found on VSCode PowerShell's Github:`n " `
106
+ + " https://github.com/PowerShell/vscode-powershell/blob/master/docs/development.md"
107
+ }
108
+ Write-Host " `n $string `n "
109
+ } elseif (hasMissingTools) {
110
+ Write-Host " You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are."
111
+ } else {
112
+ if ($Clean ) {
113
+ Invoke-Build Clean
114
+ }
115
+
116
+ Invoke-Build Build
117
+
118
+ if ($Test ) {
119
+ Invoke-Build Test
120
+ }
121
+ }
0 commit comments