-
Notifications
You must be signed in to change notification settings - Fork 490
/
build.ps1
121 lines (104 loc) · 2.72 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
#!/usr/bin/env pwsh
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[CmdletBinding(DefaultParameterSetName = "Build")]
param(
[Parameter(ParameterSetName="Bootstrap")]
[switch]
$Bootstrap,
[Parameter(ParameterSetName="Build")]
[switch]
$Clean,
[Parameter(ParameterSetName="Build")]
[switch]
$Test
)
$NeededTools = @{
VSCode = "Visual Studio Code"
NodeJS = "Node.js 6.0 or higher"
PowerShellGet = "PowerShellGet latest"
InvokeBuild = "InvokeBuild latest"
}
function needsVSCode () {
try {
$vscodeVersion = (code -v)
if (-not $vscodeVersion) {
Throw
}
} catch {
try {
$vscodeInsidersVersion = (code-insiders -v)
if (-not $vscodeInsidersVersion) {
Throw
}
} catch {
return $true
}
}
return $false
}
function needsNodeJS () {
try {
$nodeJSVersion = node -v
} catch {
return $true
}
if ($nodeJSVersion -notmatch 'v(\d+\.\d+\.\d+)') {
return $true
}
$nodeVer = [System.Version]$matches[1]
return ($nodeVer.Major -lt 6)
}
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 (needsVSCode) {
$missingTools += $NeededTools.VSCode
}
if (needsNodeJS) {
$missingTools += $NeededTools.NodeJS
}
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 VSCode PowerShell's Github:`n" `
+ "https://github.com/PowerShell/vscode-powershell/blob/main/docs/development.md"
}
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
}
}