9
9
10
10
# Requires -Modules @ {ModuleName = " InvokeBuild" ;ModuleVersion = " 3.0.0" }
11
11
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
13
15
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 {
32
18
33
19
$script :psesRepoPath = `
34
20
if ($EditorServicesRepoPath ) {
@@ -40,7 +26,7 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices
40
26
41
27
if (! (Test-Path $script :psesRepoPath )) {
42
28
# 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 "
44
30
$script :psesRepoPath = $null
45
31
}
46
32
else {
@@ -49,7 +35,18 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices
49
35
}
50
36
}
51
37
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" ) }
53
50
54
51
task RestoreNodeModules {
55
52
@@ -61,6 +58,9 @@ task RestoreNodeModules {
61
58
exec { & npm install $logLevelParam }
62
59
}
63
60
61
+ # endregion
62
+ # region Clean tasks
63
+
64
64
task Clean {
65
65
Write-Host " `n ### Cleaning vscode-powershell`n " - ForegroundColor Green
66
66
Remove-Item .\modules\* - Exclude " README.md" - Recurse - Force - ErrorAction Ignore
@@ -77,7 +77,10 @@ task CleanEditorServices {
77
77
78
78
task CleanAll CleanEditorServices, Clean
79
79
80
- task Build {
80
+ # endregion
81
+ # region Build tasks
82
+
83
+ task Build Restore, {
81
84
Write-Host " `n ### Building vscode-powershell" - ForegroundColor Green
82
85
exec { & npm run compile }
83
86
}
@@ -92,17 +95,68 @@ task BuildEditorServices {
92
95
93
96
task BuildAll BuildEditorServices, Build
94
97
98
+ # endregion
99
+ # region Test tasks
100
+
95
101
task Test Build, {
96
102
if (! $global :IsLinux -and ! $global :IsMacOS ) {
97
103
Write-Host " `n ### Running extension tests" - ForegroundColor Green
98
104
exec { & npm run test }
99
105
}
100
106
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. "
102
108
}
103
109
}
104
110
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, {
106
160
107
161
if ($script :psesBuildScriptPath ) {
108
162
Write-Host " `n ### Copying PowerShellEditorServices module files" - ForegroundColor Green
@@ -119,16 +173,12 @@ task Package {
119
173
exec { & node ./ node_modules/ vsce/ out/ vsce package }
120
174
121
175
# 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
123
177
}
124
178
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
132
180
181
+ # The set of tasks for a release
182
+ task Release Clean , Build, Test, Package
133
183
# 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