99
1010# Requires -Modules @ {ModuleName = " InvokeBuild" ;ModuleVersion = " 3.0.0" }
1111
12- task GetExtensionVersion - Before Package {
12+ # Grab package.json data which is used throughout the build.
13+ $script :PackageJson = Get-Content - Raw $PSScriptRoot / package.json | ConvertFrom-Json
14+ Write-Host " `n ### Extension Version: $ ( $script :PackageJson.version ) Extension Name: $ ( $script :PackageJson.name ) `n " - ForegroundColor Green
1315
14- $updateVersion = $false
15- $script :ExtensionVersion = `
16- if ($env: VSTS_BUILD ) {
17- $updateVersion = $true
18- $env: VSTS_BUILD_VERSION
19- }
20- else {
21- exec { & npm version | ConvertFrom-Json | ForEach-Object { $_.PowerShell } }
22- }
23-
24- Write-Host " `n ### Extension Version: $script :ExtensionVersion `n " - ForegroundColor Green
25-
26- if ($updateVersion ) {
27- exec { & npm version $script :ExtensionVersion -- no- git- tag- version -- allow- same- version }
28- }
29- }
30-
31- task ResolveEditorServicesPath - Before CleanEditorServices, BuildEditorServices {
16+ # region Utility tasks
17+ task ResolveEditorServicesPath - Before CleanEditorServices, TestEditorServices, BuildEditorServices {
3218
3319 $script :psesRepoPath = `
3420 if ($EditorServicesRepoPath ) {
@@ -40,7 +26,7 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices
4026
4127 if (! (Test-Path $script :psesRepoPath )) {
4228 # Clear the path so that it won't be used
43- Write-Host " `n ### WARNING: The PowerShellEditorServices repo cannot be found at path $script :psesRepoPath `n " - ForegroundColor Yellow
29+ Write-Warning " `n The PowerShellEditorServices repo cannot be found at path $script :psesRepoPath `n "
4430 $script :psesRepoPath = $null
4531 }
4632 else {
@@ -49,7 +35,18 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices
4935 }
5036}
5137
52- task Restore RestoreNodeModules - Before Build - If { -not (Test-Path " $PSScriptRoot /node_modules" ) }
38+ task UploadArtifacts {
39+ if ($env: TF_BUILD ) {
40+ # SYSTEM_PHASENAME is the Job name.
41+ Copy-Item - Path PowerShell- insiders.vsix `
42+ - Destination " $env: BUILD_ARTIFACTSTAGINGDIRECTORY /$ ( $script :PackageJson.name ) -$ ( $script :PackageJson.version ) -$env: SYSTEM_PHASENAME .vsix"
43+ }
44+ }
45+
46+ # endregion
47+ # region Restore tasks
48+
49+ task Restore RestoreNodeModules - If { -not (Test-Path " $PSScriptRoot /node_modules" ) }
5350
5451task RestoreNodeModules {
5552
@@ -61,6 +58,9 @@ task RestoreNodeModules {
6158 exec { & npm install $logLevelParam }
6259}
6360
61+ # endregion
62+ # region Clean tasks
63+
6464task Clean {
6565 Write-Host " `n ### Cleaning vscode-powershell`n " - ForegroundColor Green
6666 Remove-Item .\modules\* - Exclude " README.md" - Recurse - Force - ErrorAction Ignore
@@ -77,7 +77,10 @@ task CleanEditorServices {
7777
7878task CleanAll CleanEditorServices, Clean
7979
80- task Build {
80+ # endregion
81+ # region Build tasks
82+
83+ task Build Restore, {
8184 Write-Host " `n ### Building vscode-powershell" - ForegroundColor Green
8285 exec { & npm run compile }
8386}
@@ -92,17 +95,68 @@ task BuildEditorServices {
9295
9396task BuildAll BuildEditorServices, Build
9497
98+ # endregion
99+ # region Test tasks
100+
95101task Test Build, {
96102 if (! $global :IsLinux -and ! $global :IsMacOS ) {
97103 Write-Host " `n ### Running extension tests" - ForegroundColor Green
98104 exec { & npm run test }
99105 }
100106 else {
101- Write-Host " `n ### Skipping extension tests on non-Windows platform" - ForegroundColor Yellow
107+ Write-Warning " Skipping extension tests on Linux and macOS platform for legacy branch. "
102108 }
103109}
104110
105- task Package {
111+ task TestEditorServices {
112+ if ($script :psesBuildScriptPath ) {
113+ Write-Host " `n ### Testing PowerShellEditorServices`n " - ForegroundColor Green
114+ Invoke-Build Test $script :psesBuildScriptPath
115+ }
116+ }
117+
118+ task TestAll TestEditorServices, Test
119+
120+ # endregion
121+ # region Package tasks
122+
123+ task UpdateReadme - If { $script :PackageJson.version -like " *preview*" } {
124+ # Add the preview text
125+ $newReadmeTop = ' # PowerShell Language Support for Visual Studio Code
126+ > ## 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.
127+ > ### 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")
128+ > ## 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)'
129+ $readmePath = (Join-Path $PSScriptRoot README.md)
130+ $readmeContent = Get-Content - Path $readmePath
131+ if (! ($readmeContent -match " This is the PREVIEW version of the PowerShell extension" )) {
132+ $readmeContent [0 ] = $newReadmeTop
133+ $readmeContent | Set-Content $readmePath - Encoding utf8
134+ }
135+ }
136+
137+ task UpdatePackageJson {
138+ if ($script :PackageJson.version -like " *preview*" ) {
139+ $script :PackageJson.name = " powershell-preview"
140+ $script :PackageJson.displayName = " PowerShell Preview"
141+ $script :PackageJson.description = " (Preview) Develop PowerShell scripts in Visual Studio Code!"
142+ $script :PackageJson.preview = $true
143+ } else {
144+ $script :PackageJson.name = " powershell"
145+ $script :PackageJson.displayName = " PowerShell"
146+ $script :PackageJson.description = " Develop PowerShell scripts in Visual Studio Code!"
147+ $script :PackageJson.preview = $false
148+ }
149+
150+ $revision = if ($env: BUILD_BUILDID ) { $env: BUILD_BUILDID } else { 9999 }
151+ $script :PackageJson.version = " $ ( Get-Date - Format ' yyyy.M' ) .$revision "
152+
153+ $Utf8NoBomEncoding = [System.Text.UTF8Encoding ]::new($false )
154+ [System.IO.File ]::WriteAllLines(
155+ (Resolve-Path " $PSScriptRoot /package.json" ).Path,
156+ ($script :PackageJson | ConvertTo-Json - Depth 100 ),
157+ $Utf8NoBomEncoding )
158+ }
159+ task Package UpdateReadme, UpdatePackageJson, {
106160
107161 if ($script :psesBuildScriptPath ) {
108162 Write-Host " `n ### Copying PowerShellEditorServices module files" - ForegroundColor Green
@@ -119,16 +173,12 @@ task Package {
119173 exec { & node ./ node_modules/ vsce/ out/ vsce package }
120174
121175 # Change the package to have a static name for automation purposes
122- Move-Item - Force .\powershell - $ ($script :ExtensionVersion ).vsix .\PowerShell- insiders.vsix
176+ Move-Item - Force .\$ ( $ script :PackageJson .name ) - $ ($script :PackageJson .version ).vsix .\PowerShell- insiders.vsix
123177}
124178
125- task UploadArtifacts {
126- if ($env: TF_BUILD ) {
127- # SYSTEM_PHASENAME is the Job name.
128- Copy-Item - Path PowerShell- insiders.vsix `
129- - Destination " $env: BUILD_ARTIFACTSTAGINGDIRECTORY /powershell-$script :ExtensionVersion -$env: SYSTEM_PHASENAME .vsix"
130- }
131- }
179+ # endregion
132180
181+ # The set of tasks for a release
182+ task Release Clean , Build, Test, Package
133183# The default task is to run the entire CI build
134- task . GetExtensionVersion , BuildAll, Test, Package, UploadArtifacts
184+ task . Clean , BuildAll, Test, Package, UploadArtifacts
0 commit comments