1111
1212# Grab package.json data which is used throughout the build.
1313$script :PackageJson = Get-Content - Raw $PSScriptRoot / package.json | ConvertFrom-Json
14- $script :IsPreviewExtension = $script :PackageJson.name -like " *preview*" -or $script :PackageJson.displayName -like " *preview*"
1514Write-Host " `n ### Extension: $ ( $script :PackageJson.name ) -$ ( $script :PackageJson.version ) `n " - ForegroundColor Green
1615
1716function Get-EditorServicesPath {
@@ -32,9 +31,9 @@ task RestoreNodeModules -If { !(Test-Path ./node_modules) } {
3231 # When in a CI build use the --loglevel=error parameter so that
3332 # package install warnings don't cause PowerShell to throw up
3433 if ($env: TF_BUILD ) {
35- exec { & npm ci -- loglevel= error }
34+ Invoke-BuildExec { & npm ci -- loglevel= error }
3635 } else {
37- exec { & npm install }
36+ Invoke-BuildExec { & npm install }
3837 }
3938}
4039
@@ -45,7 +44,7 @@ task RestoreEditorServices -If (Get-EditorServicesPath) {
4544 # that developers always have the latest local bits.
4645 if ((Get-Item ./ modules - ErrorAction SilentlyContinue).LinkType -ne " SymbolicLink" ) {
4746 Write-Host " `n ### Creating symbolic link to PSES" - ForegroundColor Green
48- remove ./ modules
47+ Remove-BuildItem ./ modules
4948 New-Item - ItemType SymbolicLink - Path ./ modules - Target " $ ( Split-Path (Get-EditorServicesPath )) /module"
5049 }
5150
@@ -57,7 +56,7 @@ task RestoreEditorServices -If (Get-EditorServicesPath) {
5756 # and only if they don't already exist.
5857 if ((Get-Item ./ modules - ErrorAction SilentlyContinue).LinkType -eq " SymbolicLink" ) {
5958 Write-Host " `n ### Deleting PSES symbolic link" - ForegroundColor Green
60- remove ./ modules
59+ Remove-BuildItem ./ modules
6160 }
6261
6362 if (! (Test-Path ./ modules)) {
@@ -81,7 +80,7 @@ task Restore RestoreEditorServices, RestoreNodeModules
8180
8281task Clean {
8382 Write-Host " `n ### Cleaning vscode-powershell`n " - ForegroundColor Green
84- remove ./ modules, ./ out, ./ node_modules, * .vsix
83+ Remove-BuildItem ./ modules, ./ out, ./ node_modules, * .vsix
8584}
8685
8786task CleanEditorServices - If (Get-EditorServicesPath ) {
@@ -94,9 +93,9 @@ task CleanEditorServices -If (Get-EditorServicesPath) {
9493
9594task Build Restore, {
9695 Write-Host " `n ### Building vscode-powershell`n " - ForegroundColor Green
97- assert (Test-Path ./ modules/ PowerShellEditorServices/ bin) " Extension requires PSES"
96+ Assert-Build (Test-Path ./ modules/ PowerShellEditorServices/ bin) " Extension requires PSES"
9897
99- exec { & npm run lint }
98+ Invoke-BuildExec { & npm run lint }
10099
101100 # TODO: When supported we should use `esbuild` for the tests too. Although
102101 # we now use `esbuild` to transpile, bundle, and minify the extension, we
@@ -105,8 +104,8 @@ task Build Restore, {
105104 # Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
106105 # https://github.com/evanw/esbuild/issues/944
107106 switch ($Configuration ) {
108- " Debug" { exec { & npm run build -- -- sourcemap } }
109- " Release" { exec { & npm run build -- -- minify } }
107+ " Debug" { Invoke-BuildExec { & npm run build -- -- sourcemap } }
108+ " Release" { Invoke-BuildExec { & npm run build -- -- minify } }
110109 }
111110}
112111
@@ -115,9 +114,9 @@ task Build Restore, {
115114
116115task Test - If (! ($env: TF_BUILD -and $global :IsLinux )) Build, {
117116 Write-Host " `n ### Running extension tests" - ForegroundColor Green
118- exec { & npm run test }
117+ Invoke-BuildExec { & npm run test }
119118 # Reset the state of files modified by tests
120- exec { git checkout package.json test/ .vscode/ settings.json}
119+ Invoke-BuildExec { git checkout package.json test/ .vscode/ settings.json}
121120}
122121
123122task TestEditorServices - If (Get-EditorServicesPath ) {
@@ -128,26 +127,14 @@ task TestEditorServices -If (Get-EditorServicesPath) {
128127# endregion
129128# region Package tasks
130129
131- task UpdateReadme - If { $script :IsPreviewExtension } {
132- # Add the preview text
133- $newReadmeTop = ' # PowerShell Language Support for Visual Studio Code
134-
135- > ## ATTENTION: This is the PREVIEW version of the PowerShell extension for VSCode which contains features that are being evaluated for stable. It works with PowerShell 5.1 and up.
136- > ### If you are looking for the stable version, please [go here](https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell) or install the extension called "PowerShell" (not "PowerShell Preview")
137- > ## NOTE: If you have both stable (aka "PowerShell") and preview (aka "PowerShell Preview") installed, you MUST [DISABLE](https://code.visualstudio.com/docs/editor/extension-gallery#_disable-an-extension) one of them for the best performance. Docs on how to disable an extension can be found [here](https://code.visualstudio.com/docs/editor/extension-gallery#_disable-an-extension)'
138- $readmePath = (Join-Path $PSScriptRoot README.md)
139-
140- $readmeContent = Get-Content - Path $readmePath
141- if (! ($readmeContent -match " This is the PREVIEW version of the PowerShell extension" )) {
142- $readmeContent [0 ] = $newReadmeTop
143- $readmeContent | Set-Content $readmePath - Encoding utf8
144- }
145- }
146-
147- task Package UpdateReadme, Build, {
130+ task Package Build, {
148131 Write-Host " `n ### Packaging $ ( $script :PackageJson.name ) -$ ( $script :PackageJson.version ) .vsix`n " - ForegroundColor Green
149- assert ((Get-Item ./ modules).LinkType -ne " SymbolicLink" ) " Packaging requires a copy of PSES, not a symlink!"
150- exec { & npm run package }
132+ Assert-Build ((Get-Item ./ modules).LinkType -ne " SymbolicLink" ) " Packaging requires a copy of PSES, not a symlink!"
133+ if ($script :PackageJson.preview ) {
134+ Invoke-BuildExec { & npm run package -- -- pre- release }
135+ } else {
136+ Invoke-BuildExec { & npm run package }
137+ }
151138}
152139
153140# endregion
0 commit comments