22# Licensed under the MIT License.
33
44param (
5+ [ValidateSet (" Debug" , " Release" )]
6+ [string ]$Configuration = " Debug" ,
57 [string ]$EditorServicesRepoPath = $null
68)
79
1012# Grab package.json data which is used throughout the build.
1113$script :PackageJson = Get-Content - Raw $PSScriptRoot / package.json | ConvertFrom-Json
1214$script :IsPreviewExtension = $script :PackageJson.name -like " *preview*" -or $script :PackageJson.displayName -like " *preview*"
13- Write-Host " `n ### Extension Version : $ ( $script :PackageJson.version ) Extension Name: $ ( $script :PackageJson.name ) `n " - ForegroundColor Green
15+ Write-Host " `n ### Extension: $ ( $script :PackageJson.name ) - $ ( $script :PackageJson.version ) `n " - ForegroundColor Green
1416
1517function Get-EditorServicesPath {
1618 $psesRepoPath = if ($EditorServicesRepoPath ) {
@@ -23,7 +25,9 @@ function Get-EditorServicesPath {
2325 return Resolve-Path " $psesRepoPath /PowerShellEditorServices.build.ps1" - ErrorAction Continue
2426}
2527
26- task Restore - If { ! (Test-Path " $PSScriptRoot /node_modules" ) } {
28+ # region Setup tasks
29+
30+ task RestoreNodeModules - If { ! (Test-Path ./ node_modules) } {
2731 Write-Host " `n ### Restoring vscode-powershell dependencies`n " - ForegroundColor Green
2832 # When in a CI build use the --loglevel=error parameter so that
2933 # package install warnings don't cause PowerShell to throw up
@@ -34,14 +38,50 @@ task Restore -If { !(Test-Path "$PSScriptRoot/node_modules") } {
3438 }
3539}
3640
41+ task RestoreEditorServices - If (Get-EditorServicesPath ) {
42+ switch ($Configuration ) {
43+ " Debug" {
44+ # When debugging, we always rebuild PSES and ensure its symlinked so
45+ # that developers always have the latest local bits.
46+ if ((Get-Item ./ modules - ErrorAction SilentlyContinue).LinkType -ne " SymbolicLink" ) {
47+ Write-Host " `n ### Creating symbolic link to PSES" - ForegroundColor Green
48+ remove ./ modules
49+ New-Item - ItemType SymbolicLink - Path ./ modules - Target " $ ( Split-Path (Get-EditorServicesPath )) /module"
50+ }
51+
52+ Write-Host " `n ### Building PSES`n " - ForegroundColor Green
53+ Invoke-Build Build (Get-EditorServicesPath )
54+ }
55+ " Release" {
56+ # When releasing, we ensure the bits are not symlinked but copied,
57+ # and only if they don't already exist.
58+ if ((Get-Item ./ modules - ErrorAction SilentlyContinue).LinkType -eq " SymbolicLink" ) {
59+ Write-Host " `n ### Deleting PSES symbolic link" - ForegroundColor Green
60+ remove ./ modules
61+ }
62+
63+ if (! (Test-Path ./ modules)) {
64+ # We only build if it hasn't been built at all.
65+ if (! (Test-Path " $ ( Split-Path (Get-EditorServicesPath )) /module/PowerShellEditorServices/bin" )) {
66+ Write-Host " `n ### Building PSES`n " - ForegroundColor Green
67+ Invoke-Build Build (Get-EditorServicesPath )
68+ }
69+
70+ Write-Host " `n ### Copying PSES`n " - ForegroundColor Green
71+ Copy-Item - Recurse - Force " $ ( Split-Path (Get-EditorServicesPath )) /module" ./ modules
72+ }
73+ }
74+ }
75+ }
76+
77+ task Restore RestoreEditorServices, RestoreNodeModules
3778
79+ # endregion
3880# region Clean tasks
3981
4082task Clean {
4183 Write-Host " `n ### Cleaning vscode-powershell`n " - ForegroundColor Green
42- Remove-Item ./ modules - Recurse - Force - ErrorAction Ignore
43- Remove-Item ./ out - Recurse - Force - ErrorAction Ignore
44- Remove-Item ./ node_modules - Recurse - Force - ErrorAction Ignore
84+ remove ./ modules, ./ out, ./ node_modules, * .vsix
4585}
4686
4787task CleanEditorServices - If (Get-EditorServicesPath ) {
@@ -52,24 +92,10 @@ task CleanEditorServices -If (Get-EditorServicesPath) {
5292# endregion
5393# region Build tasks
5494
55- task BuildEditorServices - If (Get-EditorServicesPath ) {
56- Write-Host " `n ### Building PowerShellEditorServices`n " - ForegroundColor Green
57- Invoke-Build Build (Get-EditorServicesPath )
58- }
59-
60- task LinkEditorServices - If (Get-EditorServicesPath ) BuildEditorServices, {
61- Write-Host " `n ### For developer use only! Creating symbolic link to PSES" - ForegroundColor Green
62- Remove-Item ./ modules - Recurse - Force - ErrorAction Ignore
63- New-Item - ItemType SymbolicLink - Path ./ modules - Target " $ ( Split-Path (Get-EditorServicesPath )) /module"
64- }
95+ task Build Restore, {
96+ Write-Host " `n ### Building vscode-powershell`n " - ForegroundColor Green
97+ assert (Test-Path ./ modules/ PowerShellEditorServices/ bin) " Extension requires PSES"
6598
66- task CopyEditorServices - If { ! (Test-Path ./ modules) -and (Get-EditorServicesPath ) } BuildEditorServices, {
67- Write-Host " `n ### Copying PSES" - ForegroundColor Green
68- Copy-Item - Recurse - Force " $ ( Split-Path (Get-EditorServicesPath )) /module" ./ modules
69- }
70-
71- task Build CopyEditorServices, Restore, {
72- Write-Host " `n ### Building vscode-powershell" - ForegroundColor Green
7399 # TODO: TSLint is deprecated and we need to switch to ESLint.
74100 # https://github.com/PowerShell/vscode-powershell/pull/3331
75101 exec { & npm run lint }
@@ -80,7 +106,10 @@ task Build CopyEditorServices, Restore, {
80106 # Code test runner expects individual files (and globs them at runtime).
81107 # Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
82108 # https://github.com/evanw/esbuild/issues/944
83- exec { & npm run build }
109+ switch ($Configuration ) {
110+ " Debug" { exec { & npm run build -- -- sourcemap } }
111+ " Release" { exec { & npm run build -- -- minify } }
112+ }
84113}
85114
86115# endregion
@@ -97,7 +126,6 @@ task TestEditorServices -If (Get-EditorServicesPath) {
97126}
98127
99128# endregion
100-
101129# region Package tasks
102130
103131task UpdateReadme - If { $script :IsPreviewExtension } {
@@ -117,10 +145,8 @@ task UpdateReadme -If { $script:IsPreviewExtension } {
117145}
118146
119147task Package UpdateReadme, Build, {
120- assert (Test-Path ./ modules/ PowerShellEditorServices)
121- assert ((Get-Item ./ modules).LinkType -ne " SymbolicLink" ) " Packaging requires a copy of PSES, not a symlink!"
122-
123148 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!"
124150 exec { & npm run package }
125151}
126152
0 commit comments