2
2
# Licensed under the MIT License.
3
3
4
4
param (
5
+ [ValidateSet (" Debug" , " Release" )]
6
+ [string ]$Configuration = " Debug" ,
5
7
[string ]$EditorServicesRepoPath = $null
6
8
)
7
9
10
12
# Grab package.json data which is used throughout the build.
11
13
$script :PackageJson = Get-Content - Raw $PSScriptRoot / package.json | ConvertFrom-Json
12
14
$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
14
16
15
17
function Get-EditorServicesPath {
16
18
$psesRepoPath = if ($EditorServicesRepoPath ) {
@@ -23,7 +25,9 @@ function Get-EditorServicesPath {
23
25
return Resolve-Path " $psesRepoPath /PowerShellEditorServices.build.ps1" - ErrorAction Continue
24
26
}
25
27
26
- task Restore - If { ! (Test-Path " $PSScriptRoot /node_modules" ) } {
28
+ # region Setup tasks
29
+
30
+ task RestoreNodeModules - If { ! (Test-Path ./ node_modules) } {
27
31
Write-Host " `n ### Restoring vscode-powershell dependencies`n " - ForegroundColor Green
28
32
# When in a CI build use the --loglevel=error parameter so that
29
33
# package install warnings don't cause PowerShell to throw up
@@ -34,14 +38,50 @@ task Restore -If { !(Test-Path "$PSScriptRoot/node_modules") } {
34
38
}
35
39
}
36
40
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
37
78
79
+ # endregion
38
80
# region Clean tasks
39
81
40
82
task Clean {
41
83
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
45
85
}
46
86
47
87
task CleanEditorServices - If (Get-EditorServicesPath ) {
@@ -52,24 +92,10 @@ task CleanEditorServices -If (Get-EditorServicesPath) {
52
92
# endregion
53
93
# region Build tasks
54
94
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"
65
98
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
73
99
# TODO: TSLint is deprecated and we need to switch to ESLint.
74
100
# https://github.com/PowerShell/vscode-powershell/pull/3331
75
101
exec { & npm run lint }
@@ -80,7 +106,10 @@ task Build CopyEditorServices, Restore, {
80
106
# Code test runner expects individual files (and globs them at runtime).
81
107
# Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
82
108
# 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
+ }
84
113
}
85
114
86
115
# endregion
@@ -97,7 +126,6 @@ task TestEditorServices -If (Get-EditorServicesPath) {
97
126
}
98
127
99
128
# endregion
100
-
101
129
# region Package tasks
102
130
103
131
task UpdateReadme - If { $script :IsPreviewExtension } {
@@ -117,10 +145,8 @@ task UpdateReadme -If { $script:IsPreviewExtension } {
117
145
}
118
146
119
147
task 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
-
123
148
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!"
124
150
exec { & npm run package }
125
151
}
126
152
0 commit comments