-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathvscode-powershell.build.ps1
147 lines (122 loc) · 5.65 KB
/
vscode-powershell.build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",
[string]$EditorServicesRepoPath = $null
)
#Requires -Modules @{ ModuleName = "InvokeBuild"; ModuleVersion = "3.0.0" }
function Get-EditorServicesPath {
$psesRepoPath = if ($EditorServicesRepoPath) {
$EditorServicesRepoPath
} else {
"$PSScriptRoot/../PowerShellEditorServices/"
}
# NOTE: The ErrorActionPreference for both Invoke-Build and Azure DevOps
# scripts is Stop, but we want to continue and return false here.
return Resolve-Path "$psesRepoPath/PowerShellEditorServices.build.ps1" -ErrorAction Continue
}
#region Setup tasks
task RestoreNodeModules -If { !(Test-Path ./node_modules) } {
Write-Host "`n### Restoring vscode-powershell dependencies`n" -ForegroundColor Green
# When in a CI build use the --loglevel=error parameter so that
# package install warnings don't cause PowerShell to throw up
if ($env:TF_BUILD) {
Invoke-BuildExec { & npm ci --loglevel=error }
} else {
Invoke-BuildExec { & npm install }
}
}
task RestoreEditorServices -If (Get-EditorServicesPath) {
switch ($Configuration) {
"Debug" {
# When debugging, we always rebuild PSES and ensure its symlinked so
# that developers always have the latest local bits.
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -ne "SymbolicLink") {
Write-Host "`n### Creating symbolic link to PSES" -ForegroundColor Green
Remove-BuildItem ./modules
New-Item -ItemType SymbolicLink -Path ./modules -Target "$(Split-Path (Get-EditorServicesPath))/module"
}
Write-Host "`n### Building PSES`n" -ForegroundColor Green
Invoke-Build Build (Get-EditorServicesPath) -Configuration $Configuration
}
"Release" {
# When releasing, we ensure the bits are not symlinked but copied,
# and only if they don't already exist.
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -eq "SymbolicLink") {
Write-Host "`n### Deleting PSES symbolic link" -ForegroundColor Green
Remove-BuildItem ./modules
}
if (!(Test-Path ./modules)) {
# We only build if it hasn't been built at all.
if (!(Test-Path "$(Split-Path (Get-EditorServicesPath))/module/PowerShellEditorServices/bin")) {
Write-Host "`n### Building PSES`n" -ForegroundColor Green
Invoke-Build Build (Get-EditorServicesPath) -Configuration $Configuration
}
Write-Host "`n### Copying PSES`n" -ForegroundColor Green
Copy-Item -Recurse -Force "$(Split-Path (Get-EditorServicesPath))/module" ./modules
}
}
}
}
task Restore RestoreEditorServices, RestoreNodeModules
#endregion
#region Clean tasks
task Clean {
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
Remove-BuildItem ./modules, ./out, ./node_modules, *.vsix
}
task CleanEditorServices -If (Get-EditorServicesPath) {
Write-Host "`n### Cleaning PowerShellEditorServices`n" -ForegroundColor Green
Invoke-Build Clean (Get-EditorServicesPath)
}
#endregion
#region Build tasks
task Build Restore, {
Write-Host "`n### Building vscode-powershell`n" -ForegroundColor Green
Assert-Build (Test-Path ./modules/PowerShellEditorServices/bin) "Extension requires PSES"
Write-Host "`n### Linting TypeScript`n" -ForegroundColor Green
Invoke-BuildExec { & npm run lint }
# TODO: When supported we should use `esbuild` for the tests too. Although
# we now use `esbuild` to transpile, bundle, and minify the extension, we
# still use `tsc` to transpile everything in `src` and `test` because the VS
# Code test runner expects individual files (and globs them at runtime).
# Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
# https://github.com/evanw/esbuild/issues/944
switch ($Configuration) {
"Debug" { Invoke-BuildExec { & npm run build -- --sourcemap } }
"Release" { Invoke-BuildExec { & npm run build -- --minify } }
}
}
#endregion
#region Test tasks
task Test Build, {
Write-Host "`n### Running extension tests" -ForegroundColor Green
Invoke-BuildExec { & npm run test }
# Reset the state of files modified by tests
Invoke-BuildExec { git checkout package.json test/TestEnvironment.code-workspace }
}
task TestEditorServices -If (Get-EditorServicesPath) {
Write-Host "`n### Testing PowerShellEditorServices`n" -ForegroundColor Green
Invoke-Build Test (Get-EditorServicesPath)
}
#endregion
#region Package tasks
task Package Build, {
# Sanity check our changelog version versus package.json (which lacks pre-release label)
Import-Module $PSScriptRoot/tools/VersionTools.psm1
$version = Get-Version -RepositoryName vscode-powershell
$packageVersion = Get-MajorMinorPatch -Version $version
$packageJson = Get-Content -Raw $PSScriptRoot/package.json | ConvertFrom-Json
Assert-Build ($packageJson.version -eq $packageVersion)
Write-Host "`n### Packaging powershell-$packageVersion.vsix`n" -ForegroundColor Green
Assert-Build ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
if (Test-IsPreRelease) {
Write-Host "`n### This is a pre-release!`n" -ForegroundColor Green
Invoke-BuildExec { & npm run package -- --pre-release }
} else {
Invoke-BuildExec { & npm run package }
}
}
#endregion
task . Build, Test, Package