-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.ps1
263 lines (214 loc) · 8.6 KB
/
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
param (
$PreRelease
)
function Clear-Folder {
param (
[string] $Path
)
if (Test-Path -Path $Path) {
Remove-Item $Path -Recurse -Force | Out-Null
}
New-Item $Path -ItemType Directory | Out-Null
}
function Get-ALCompiler {
param (
[string] $Type,
[string] $Nav,
[string] $CU,
[string] $CompilerCachePath = "C:\ALCompiler",
$PreRelease
)
if ($Type -eq "Marketplace") {
return Get-MarketplaceALCompiler -CompilerCachePath $CompilerCachePath -PreRelease $PreRelease
}
if ($Type -eq "Nav") {
return Get-NavALCompiler -Nav $Nav -CU $CU -CompilerCachePath $CompilerCachePath
}
return $null
}
function Get-NavALCompiler {
param (
[string] $Nav,
[string] $CU,
[string] $CompilerCachePath = "C:\ALCompiler"
)
$navFolder = "Nav" + $Nav
$destPath = Join-Path -Path $CompilerCachePath -ChildPath $navFolder
$extensionFolder = Join-Path -Path $destPath -ChildPath "ext"
$compilerPath = Join-Path -Path $extensionFolder -ChildPath "extension\bin"
$compilerFilePath = Join-Path -Path $compilerPath -ChildPath "alc.exe"
if (!(Test-Path -Path $compilerFilePath)) {
$vsixPath = Get-NavCompilerVSIX -Nav $Nav -CU $CU
if ($null -eq $vsixPath) {
return $null
}
Expand-ALCompilerVSIX -Path $vsixPath -Destination $extensionFolder
}
$data = @{
Path = $compilerPath
Version = [System.Version]::new(0, 0, 0)
}
return $data
}
function Get-NavCompilerVSIX {
param (
[string] $Nav,
[string] $CU
)
$url = Get-NavArtifactUrl -nav $Nav -country 'w1' -cu $CU
$artifactPaths = Download-Artifacts -artifactUrl $url -includePlatform
foreach ($path in $artifactPaths) {
$vsixPath = Join-Path -Path $path -ChildPath "ModernDev\program files\Microsoft Dynamics NAV\110\Modern Development Environment\ALLanguage.vsix"
if (Test-Path -Path $vsixPath) {
return $vsixPath
}
}
return $null
}
function Get-MarketplaceALCompilerVersion {
param (
[string] $Url
)
$urlParts = $Url.Split("/")
$version = [System.Version]::new($urlParts.Get(6))
return $version
}
function Get-MarketplaceALCompiler {
param (
[string] $CompilerCachePath,
$PreRelease
)
$destPath = Join-Path -Path $CompilerCachePath -ChildPath "Marketplace"
$extensionFolder = Join-Path -Path $destPath -ChildPath "ext"
try {
if ($PreRelease) {
$url = Get-LatestAlLanguageExtensionUrl -allowPrerelease
} else {
$url = Get-LatestAlLanguageExtensionUrl
}
$lastUrl = Get-LastCompilerUrl -Path $destPath
if ($url -ne $lastUrl) {
if (!(Test-Path -Path $destPath)) {
New-Item $destPath -ItemType Directory | Out-Null
}
$vsixPath = Join-Path -Path $destPath -ChildPath "extension.zip"
if (Test-Path -Path $vsixPath) {
Remove-Item $vsixPath -Force | Out-Null
}
Invoke-WebRequest -Uri $url -OutFile $vsixPath
Expand-ALCompilerVSIX -Path $vsixPath -Destination $extensionFolder
Set-LastCompilerUrl -Path $destPath -Url $url
}
}
catch {
}
$data = @{
Path = Join-Path -Path $extensionFolder -ChildPath "extension\bin\win32"
Version = Get-MarketplaceALCompilerVersion -Url $url
}
return $data
}
function Get-LastCompilerUrl {
param (
[string] $Path
)
$filePath = Join-Path -Path $Path -ChildPath "lasturl.txt"
if (Test-Path -Path $filePath) {
return Get-Content -Path $filePath
}
return ""
}
function Set-LastCompilerUrl {
param (
[string] $Path,
[string] $Url
)
$filePath = Join-Path -Path $Path -ChildPath "lasturl.txt"
Set-Content -Path $filePath -Value $Url -Force
}
function Expand-ALCompilerVSIX {
param (
[string] $Path,
[string] $Destination
)
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($Path, $Destination)
}
function Set-ExtensionPackageVersion {
param (
[System.Version] $ALCompilerVersion
)
$packageManifest = Get-Content -Raw "package.json" -Encoding UTF8 | ConvertFrom-Json
$packageVersion = [System.Version]::new($packageManifest.version)
$newPackageVersion = [System.Version]::new($ALCompilerVersion.Major, $packageVersion.Minor, $ALCompilerVersion.Build)
$newVersionText = $newPackageVersion.ToString()
npm version $newVersionText --alow-same-version --no-git-tag-version
}
# Setup BC Container Helper
$module = Get-Module -ListAvailable -Name BCContainerHelper
if ($null -eq $module) {
Write-Host "Installing BC Container Helper"
Install-Module BCContainerhelper -Force
} else {
Write-Host "Updating BC Container Helper"
Update-Module BCContainerhelper -Force
}
Import-Module BCContainerhelper
# Download compiler libraries and update dll references
Write-Host "Downloading Latest AL Compiler from VS Code Marketplace"
$marketplaceALCompiler = Get-ALCompiler -Type "Marketplace" -PreRelease $PreRelease
$marketplaceALCompilerPath = $marketplaceALCompiler.Path
Write-Host "Downloading Nav 2018 AL Compiler from Nav Artifacts"
$nav2018ALCompiler = Get-ALCompiler -Type "Nav" -Nav "2018" -CU "cu14"
$nav2018ALCompilerPath = $nav2018ALCompiler.Path
Write-Host "Updating libraries references"
$oldLibrariesPath = "C:\Projects\MicrosoftALVersions\LatestBC\bin\win32"
$newLibrariesPath = $marketplaceALCompilerPath
$oldNav2018LibrariesPath = "C:\Projects\MicrosoftALVersions\Nav2018\microsoft.al-0.13.82793\bin"
$newNav2018LibrariesPath = $nav2018ALCompilerPath
$projectFilesList = Get-ChildItem -Path "language-server" -Filter "*.csproj" -Recurse
foreach ($projectFile in $projectFilesList) {
$projectContent = Get-Content -Path $projectFile.FullName
$projectContent = $projectContent.Replace($oldLibrariesPath, $newLibrariesPath)
$projectContent = $projectContent.Replace($oldNav2018LibrariesPath, $newNav2018LibrariesPath)
Set-Content -Path $projectFile.FullName -Value $projectContent -Force
}
# Prepare target language server folders in the vscode extension bin folder
$darwinBinPath = ".\vscode-extension\bin\netcore\darwin"
$winBinPath = ".\vscode-extension\bin\netcore\win32"
$linuxBinPath = ".\vscode-extension\bin\netcore\linux"
$netframeworkBinPath = ".\vscode-extension\bin\netframeworknav2018"
Clear-Folder -Path $darwinBinPath
Clear-Folder -Path $winBinPath
Clear-Folder -Path $linuxBinPath
Clear-Folder -Path $netframeworkBinPath
# Build language server
cd ".\language-server\"
# Windows - .net core
Write-Host "Building Windows .net core language server"
dotnet publish ".\AZALDevToolsServer.NetCore\AZALDevToolsServer.NetCore.csproj" -r win-x64 -f net8.0 -o "..\vscode-extension\bin\netcore\win32" --self-contained true --configuration Release
# MacOS - .net core
Write-Host "Building MacOS .net core language server"
dotnet publish ".\AZALDevToolsServer.NetCore\AZALDevToolsServer.NetCore.csproj" -r osx-x64 -f net8.0 -o "..\vscode-extension\bin\netcore\darwin" --self-contained true --configuration Release
# Linux - .net core
Write-Host "Building Linux .net core language server"
dotnet publish ".\AZALDevToolsServer.NetCore\AZALDevToolsServer.NetCore.csproj" -r linux-x64 -f net8.0 -o "..\vscode-extension\bin\netcore\linux" --self-contained false --configuration Release
# Windows - .net framework for Nav2018 extension development
Write-Host "Building Windows .net framework language server for Nav 2018"
$msBuildPath = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
& $msBuildPath ".\AZALDevToolsServer.NetFrameworkNav2018\AZALDevToolsServer.NetFrameworkNav2018.csproj" -p:Configuration=Release -p:OutputPath="..\..\vscode-extension\bin\netframeworknav2018"
# Update readme and changelog
Write-Host "Copying readme and changelog to vscode extension folder"
cd ".."
Copy-Item -Path ".\CHANGELOG.md" -Destination ".\vscode-extension\CHANGELOG.md" -Force
Copy-Item -Path ".\README.md" -Destination ".\vscode-extension\README.md" -Force
Copy-Item -Path ".\LICENSE" -Destination ".\vscode-extension\LICENSE" -Force
# Build vscode extension
cd "vscode-extension"
if ($PreRelease) {
Write-Host "Setting extension version to pre-release"
Set-ExtensionPackageVersion -ALCompilerVersion $marketplaceALCompiler.Version
}
write-Host "Packaging extension..."
vsce package
cd ".."