|
1 | 1 | #!/usr/bin/env pwsh
|
2 | 2 | # Copyright (c) Microsoft Corporation.
|
3 | 3 | # Licensed under the MIT License.
|
4 |
| - |
5 |
| -[CmdletBinding(DefaultParameterSetName = "Build")] |
| 4 | +<# |
| 5 | +.SYNOPSIS |
| 6 | +A bootstrap for Invoke-Build which will perform the rest of the process. This is mostly compatability for programs that still use it, normally you should use Invoke-Build directly unless you don't have invoke-build installed. For noninteractive use, be sure to specify -Confirm:$false to avoid prompts |
| 7 | +#> |
| 8 | +#requires -version 5 |
| 9 | +using namespace System.Management.Automation |
| 10 | +using namespace System.Collections.Generic |
| 11 | + |
| 12 | +[CmdletBinding(DefaultParameterSetName = 'Build')] |
6 | 13 | param(
|
7 |
| - [Parameter(ParameterSetName="Bootstrap")] |
| 14 | + [Parameter(ParameterSetName = 'Bootstrap')] |
8 | 15 | [switch]
|
9 | 16 | $Bootstrap,
|
10 | 17 |
|
11 |
| - [Parameter(ParameterSetName="Build")] |
| 18 | + [Parameter(ParameterSetName = 'Build')] |
12 | 19 | [switch]
|
13 | 20 | $Clean,
|
14 | 21 |
|
15 |
| - [Parameter(ParameterSetName="Build")] |
| 22 | + [Parameter(ParameterSetName = 'Build')] |
16 | 23 | [switch]
|
17 | 24 | $Test
|
18 | 25 | )
|
19 |
| - |
20 |
| -$NeededTools = @{ |
21 |
| - VSCode = "Visual Studio Code" |
22 |
| - NodeJS = "Node.js 6.0 or higher" |
23 |
| - PowerShellGet = "PowerShellGet latest" |
24 |
| - InvokeBuild = "InvokeBuild latest" |
25 |
| -} |
26 |
| - |
27 |
| -function needsVSCode () { |
28 |
| - try { |
29 |
| - $vscodeVersion = (code -v) |
30 |
| - if (-not $vscodeVersion) { |
31 |
| - Throw |
32 |
| - } |
33 |
| - } catch { |
34 |
| - try { |
35 |
| - $vscodeInsidersVersion = (code-insiders -v) |
36 |
| - if (-not $vscodeInsidersVersion) { |
37 |
| - Throw |
38 |
| - } |
39 |
| - } catch { |
40 |
| - return $true |
41 |
| - } |
42 |
| - } |
43 |
| - return $false |
44 |
| -} |
45 |
| - |
46 |
| -function needsNodeJS () { |
47 |
| - try { |
48 |
| - $nodeJSVersion = node -v |
49 |
| - } catch { |
50 |
| - return $true |
51 |
| - } |
52 |
| - |
53 |
| - if ($nodeJSVersion -notmatch 'v(\d+\.\d+\.\d+)') { |
54 |
| - return $true |
55 |
| - } |
56 |
| - |
57 |
| - $nodeVer = [System.Version]$matches[1] |
58 |
| - return ($nodeVer.Major -lt 6) |
| 26 | +$SCRIPT:ErrorActionPreference = 'Stop' |
| 27 | +# Pin the InvokeBuild version to avoid possible supply chain attacks or breaking changes. |
| 28 | +$InvokeBuildVersion = '5.10.3' |
| 29 | + |
| 30 | +# Get unique non-common parameters specified to pass to Invoke-Build |
| 31 | +[hashset[string]]$commonParameters = ([PSCmdlet]::CommonParameters, [PSCmdlet]::OptionalCommonParameters) | ForEach-Object { $_ } |
| 32 | +$ibParams = @{} |
| 33 | +$ibParams.Task = ($PSBoundParameters.Keys | Where-Object { $_ -notin $commonParameters }) -join ',' |
| 34 | +$commonParams = @{} |
| 35 | +$PSBoundParameters.GetEnumerator() | Where-Object Key -In $commonParameters | ForEach-Object { |
| 36 | + $commonParams[$PSItem.Key] = $PSItem.Value |
| 37 | + $ibParams[$PSItem.Key] = $PSItem.Value |
59 | 38 | }
|
60 | 39 |
|
61 |
| -function needsPowerShellGet () { |
62 |
| - if (Get-Module -ListAvailable -Name PowerShellGet) { |
63 |
| - return $false |
64 |
| - } |
65 |
| - return $true |
| 40 | +try { |
| 41 | + $invokeBuildCommand = Get-Command Invoke-Build -FullyQualifiedModule @{ModuleName = 'InvokeBuild'; RequiredVersion = $InvokeBuildVersion } |
| 42 | + Write-Verbose "Bootstrap: Invoke-Build $InvokeBuildVersion detected." |
| 43 | +} catch { |
| 44 | + Write-Warning "Invoke-Build $InvokeBuildVersion not detected. Installing..." |
| 45 | + Install-Module -Name InvokeBuild -RequiredVersion $InvokeBuildVersion -Scope CurrentUser @commonParams |
66 | 46 | }
|
67 | 47 |
|
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 += "`nAll instructions for installing these tools can be found on VSCode PowerShell's Github:`n" ` |
106 |
| - + "https://github.com/PowerShell/vscode-powershell/blob/main/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 |
| -} |
| 48 | +Write-Verbose "Starting Invoke-Build $($ibParams.Task -join ', ')" |
| 49 | +& $invokeBuildCommand @ibParams |
| 50 | + |
| 51 | +# $NeededTools = @{ |
| 52 | +# VSCode = "Visual Studio Code" |
| 53 | +# NodeJS = "Node.js 6.0 or higher" |
| 54 | +# PowerShellGet = "PowerShellGet latest" |
| 55 | +# InvokeBuild = "InvokeBuild latest" |
| 56 | +# } |
| 57 | + |
| 58 | +# function needsVSCode () { |
| 59 | +# try { |
| 60 | +# $vscodeVersion = (code -v) |
| 61 | +# if (-not $vscodeVersion) { |
| 62 | +# Throw |
| 63 | +# } |
| 64 | +# } catch { |
| 65 | +# try { |
| 66 | +# $vscodeInsidersVersion = (code-insiders -v) |
| 67 | +# if (-not $vscodeInsidersVersion) { |
| 68 | +# Throw |
| 69 | +# } |
| 70 | +# } catch { |
| 71 | +# return $true |
| 72 | +# } |
| 73 | +# } |
| 74 | +# return $false |
| 75 | +# } |
| 76 | + |
| 77 | +# function needsNodeJS () { |
| 78 | +# try { |
| 79 | +# $nodeJSVersion = node -v |
| 80 | +# } catch { |
| 81 | +# return $true |
| 82 | +# } |
| 83 | + |
| 84 | +# if ($nodeJSVersion -notmatch 'v(\d+\.\d+\.\d+)') { |
| 85 | +# return $true |
| 86 | +# } |
| 87 | + |
| 88 | +# $nodeVer = [System.Version]$matches[1] |
| 89 | +# return ($nodeVer.Major -lt 6) |
| 90 | +# } |
| 91 | + |
| 92 | +# function needsPowerShellGet () { |
| 93 | +# if (Get-Module -ListAvailable -Name PowerShellGet) { |
| 94 | +# return $false |
| 95 | +# } |
| 96 | +# return $true |
| 97 | +# } |
| 98 | + |
| 99 | +# function needsInvokeBuild () { |
| 100 | +# if (Get-Module -ListAvailable -Name InvokeBuild) { |
| 101 | +# return $false |
| 102 | +# } |
| 103 | +# return $true |
| 104 | +# } |
| 105 | + |
| 106 | +# function getMissingTools () { |
| 107 | +# $missingTools = @() |
| 108 | + |
| 109 | +# if (needsVSCode) { |
| 110 | +# $missingTools += $NeededTools.VSCode |
| 111 | +# } |
| 112 | +# if (needsNodeJS) { |
| 113 | +# $missingTools += $NeededTools.NodeJS |
| 114 | +# } |
| 115 | +# if (needsPowerShellGet) { |
| 116 | +# $missingTools += $NeededTools.PowerShellGet |
| 117 | +# } |
| 118 | +# if (needsInvokeBuild) { |
| 119 | +# $missingTools += $NeededTools.InvokeBuild |
| 120 | +# } |
| 121 | + |
| 122 | +# return $missingTools |
| 123 | +# } |
| 124 | + |
| 125 | +# function hasMissingTools () { |
| 126 | +# return ((getMissingTools).Count -gt 0) |
| 127 | +# } |
| 128 | + |
| 129 | +# if ($Bootstrap) { |
| 130 | +# $string = "Here is what your environment is missing:`n" |
| 131 | +# $missingTools = getMissingTools |
| 132 | +# if (($missingTools).Count -eq 0) { |
| 133 | +# $string += "* nothing!`n`n Run this script without a flag to build or a -Clean to clean." |
| 134 | +# } else { |
| 135 | +# $missingTools | ForEach-Object {$string += "* $_`n"} |
| 136 | +# $string += "`nAll instructions for installing these tools can be found on VSCode PowerShell's Github:`n" ` |
| 137 | +# + "https://github.com/PowerShell/vscode-powershell/blob/main/docs/development.md" |
| 138 | +# } |
| 139 | +# Write-Host "`n$string`n" |
| 140 | +# } elseif(hasMissingTools) { |
| 141 | +# Write-Host "You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are." |
| 142 | +# } else { |
| 143 | +# if($Clean) { |
| 144 | +# Invoke-Build Clean |
| 145 | +# } |
| 146 | + |
| 147 | +# Invoke-Build Build |
| 148 | + |
| 149 | +# if($Test) { |
| 150 | +# Invoke-Build Test |
| 151 | +# } |
| 152 | +# } |
0 commit comments