forked from anzwdev/al-code-outline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
207 lines (166 loc) · 6.73 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
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-ALCompilerPath {
param (
[string] $Type,
[string] $Nav,
[string] $CU,
[string] $CompilerCachePath = "C:\ALCompiler"
)
if ($Type -eq "Marketplace") {
return Get-MarketplaceALCompilerPath -CompilerCachePath $CompilerCachePath
}
if ($Type -eq "Nav") {
return Get-NavALCompilerPath -Nav $Nav -CU $CU -CompilerCachePath $CompilerCachePath
}
return $null
}
function Get-NavALCompilerPath {
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
}
return $compilerPath
}
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-MarketplaceALCompilerPath {
param (
[string] $CompilerCachePath
)
$destPath = Join-Path -Path $CompilerCachePath -ChildPath "Marketplace"
$extensionFolder = Join-Path -Path $destPath -ChildPath "ext"
try {
$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 {
}
return Join-Path -Path $extensionFolder -ChildPath "extension\bin\win32"
}
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)
}
# 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"
$marketplaceALCompilerPath = Get-ALCompilerPath -Type "Marketplace"
Write-Host "Downloading Nav 2018 AL Compiler from Nav Artifacts"
$nav2018ALCompilerPath = Get-ALCompilerPath -Type "Nav" -Nav "2018" -CU "cu14"
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 net6.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 net6.0 -o "..\vscode-extension\bin\netcore\darwin" --self-contained true --configuration Release
# Windows - .net framework for Nav2018 extension development
$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
cd ".."
Copy-Item -Path ".\CHANGELOG.md" -Destination ".\vscode-extension\CHANGELOG.md" -Force
Copy-Item -Path ".\README.md" -Destination ".\vscode-extension\README.md" -Force
# Build vscode extension
cd "vscode-extension"
vsce package
cd ".."