Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0d558fe

Browse files
committed
Move all bootstrap logic to build script
1 parent 637d127 commit 0d558fe

File tree

2 files changed

+26
-112
lines changed

2 files changed

+26
-112
lines changed

build.ps1

Lines changed: 5 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License.
44
<#
55
.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
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.
77
#>
88
#requires -version 5
99
using namespace System.Management.Automation
@@ -31,6 +31,9 @@ $InvokeBuildVersion = '5.10.3'
3131
[hashset[string]]$commonParameters = ([PSCmdlet]::CommonParameters, [PSCmdlet]::OptionalCommonParameters) | ForEach-Object { $_ }
3232
$ibParams = @{}
3333
$ibParams.Task = ($PSBoundParameters.Keys | Where-Object { $_ -notin $commonParameters }) -join ','
34+
if (-not $ibParams.Task) {
35+
$ibParams.Task = '.'
36+
}
3437
$commonParams = @{}
3538
$PSBoundParameters.GetEnumerator() | Where-Object Key -In $commonParameters | ForEach-Object {
3639
$commonParams[$PSItem.Key] = $PSItem.Value
@@ -42,111 +45,8 @@ try {
4245
Write-Verbose "Bootstrap: Invoke-Build $InvokeBuildVersion detected."
4346
} catch {
4447
Write-Warning "Invoke-Build $InvokeBuildVersion not detected. Installing..."
45-
Install-Module -Name InvokeBuild -RequiredVersion $InvokeBuildVersion -Scope CurrentUser @commonParams
48+
Install-Module -Name InvokeBuild -RequiredVersion $InvokeBuildVersion -Scope CurrentUser @commonParams -Force
4649
}
4750

4851
Write-Verbose "Starting Invoke-Build $($ibParams.Task -join ', ')"
4952
& $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-
# }

vscode-powershell.build.ps1

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ param(
99
[string]$EditorServicesRepoPath = $null,
1010
# Keep this up to date with the version that vscode stable uses (see vscode help -> about)
1111
[Version]$RequiredNodeVersion = '16.14.2',
12-
[PowerShell.Commands.ModuleSpecification]$RequiredModules = @(
12+
# List of modules that are required for the build
13+
[Microsoft.PowerShell.Commands.ModuleSpecification[]]$RequiredModules = @(
1314
@{ ModuleName = 'InvokeBuild'; ModuleVersion = '5.0.0' }
1415
@{ ModuleName = 'Pester'; ModuleVersion = '5.3.0' } #For PSES Build. TODO: Remove once we hook into PSES build script
1516
@{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.21.0' } #For PSES Build
1617
@{ ModuleName = 'platyPS'; ModuleVersion = '0.14.0' } #For PSES Build
1718
)
1819
)
19-
$ErrorActionPreference = 'Stop'
20+
$SCRIPT:ErrorActionPreference = 'Stop'
2021

2122
#Requires -Modules @{ ModuleName = "InvokeBuild"; ModuleVersion = "5.0.0" }
2223

2324
#region Prerequisites
2425

2526
task Prerequisites {
26-
Assert-NodeVersion $RequiredNodeVersion -ErrorAction Continue
27-
Assert-Module $RequiredModules -ErrorAction Continue
27+
# We want all prereqs to run so we can tell the user everything they are missing, rather than them having to fix/check/fix/check/etc.
28+
[ErrorRecord[]]$preRequisiteIssues = & {
29+
Assert-NodeVersion $RequiredNodeVersion -ErrorAction Continue
30+
Assert-Module $RequiredModules -ErrorAction Continue
31+
} 2>&1
32+
33+
if ($preRequisiteIssues) {
34+
$ErrorActionPreference = 'Continue'
35+
Write-Warning 'The following prerequisites are not met. Please install them before continuing. Setup guidance can be found here: https://github.com/PowerShell/vscode-powershell/blob/main/docs/development.md'
36+
$preRequisiteIssues | ForEach-Object { Write-Error $_ }
37+
}
38+
# We dont need to test for vscode anymore because we download it dynamically during the build.
39+
2840
}
2941

3042
function Assert-NodeVersion ($RequiredNodeVersion) {
@@ -118,7 +130,7 @@ task Restore RestoreEditorServices, RestoreNodeModules
118130
#endregion
119131
#region Clean tasks
120132

121-
task Clean {
133+
task CleanExtension {
122134
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
123135
Remove-BuildItem ./modules, ./out, ./node_modules, *.vsix
124136
}
@@ -153,7 +165,7 @@ task Build Restore, {
153165
#endregion
154166
#region Test tasks
155167

156-
task Test Build, {
168+
task TestExtension {
157169
Write-Host "`n### Running extension tests" -ForegroundColor Green
158170
Invoke-BuildExec { & npm run test }
159171
# Reset the state of files modified by tests
@@ -191,4 +203,6 @@ task Package Build, {
191203

192204
# High Level Tasks
193205
task Bootstrap Prerequisites
194-
task . Build, Test, Package
206+
task Clean CleanExtension, CleanEditorServices
207+
task Test Build, TestExtension, TestEditorServices
208+
task . Prerequisites, Build, Test, Package

0 commit comments

Comments
 (0)