-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathbuild.ps1
More file actions
212 lines (193 loc) · 8.41 KB
/
Copy pathbuild.ps1
File metadata and controls
212 lines (193 loc) · 8.41 KB
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
param(
[string] $port="8080",
[Switch] $cleanMetadata=$false,
[Switch] $cleanOnly=$false
)
function PostCleanup() {
Remove-Item -Path 'docfx.zip' -Force 2>&1 > $null
Remove-Item -Path 'docfx-plugins-typescriptreference.zip' -Force 2>&1 > $null
Remove-Item -Path 'docfx-tmpls-discordfx.zip' -Force 2>&1 > $null
if($cleanMetadata) {
Remove-Item -Path './_site/' -Recurse -Force 2>&1 > $null
Remove-Item -Path './obj' -Recurse -Force 2>&1 > $null
Remove-Item -Path './api/**.yml' -Force 2>&1 > $null
Remove-Item -Path './altv-types/docs/_site/' -Recurse -Force 2>&1 > $null
Remove-Item -Path './altv-types/docs/obj' -Recurse -Force 2>&1 > $null
Remove-Item -Path './altv-types/docs/api/**.yml' -Force 2>&1 > $null
Remove-Item -Path './altv-types/docs/api/.manifest' -Force 2>&1 > $null
Remove-Item -Path './coreclr-module/docs/_site/' -Recurse -Force 2>&1 > $null
Remove-Item -Path './coreclr-module/docs/obj' -Recurse -Force 2>&1 > $null
Remove-Item -Path './coreclr-module/docs/api/**.yml' -Force 2>&1 > $null
Remove-Item -Path './coreclr-module/docs/api/.manifest' -Force 2>&1 > $null
}
}
function GetAssemblyVersion([string] $file) {
if(-not (Test-Path -Path $file)) { throw "Cannot find path $file because it does not exist." }
$ver=(Get-Item -Path $file | Select-Object -ExpandProperty VersionInfo).FileVersion.Split('.')
if($ver.Length -lt 4) {
$ver -Join '.'
} else {
($ver | Select -SkipLast 1) -Join '.'
}
}
function GetVisualStudioVersion() {
$instances=& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products * -latest -format json | ConvertFrom-Json
if($instances.Length -gt 0) {
$instances[0].installationVersion
} else {
""
}
}
function VerifyVisualStudioInstance() {
$instances=& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products * -requires Microsoft.NetCore.Component.SDK -latest -format json | ConvertFrom-Json
$instances.Length -gt 0
}
function FetchAndDownloadRelease([string] $repo, [string] $file, [string] $tag=$null) {
$global:ProgressPreference='SilentlyContinue'
if(-not $tag) {
$tag=(Invoke-WebRequest -UseBasicParsing "https://api.github.com/repos/$repo/releases" | ConvertFrom-Json)[0].tag_name
}
Invoke-WebRequest -UseBasicParsing "https://github.com/$repo/releases/download/$tag/$file" -OutFile $file
$global:ProgressPreference='Continue'
return ([int]$? - 1)
}
function ExtractArchive([string] $path, [string] $dest) {
if(-not (Test-Path -Path $path)) { throw "Cannot find path $path because it does not exist." }
$file=Get-Item -Path $path
if(!$dest) {
$dest=$file.FullName.Substring(0, $file.FullName.LastIndexOf('.'))
}
$global:ProgressPreference='SilentlyContinue'
Expand-Archive -Path $file -DestinationPath $dest -Force
$global:ProgressPreference='Continue'
return ([int]$? - 1)
}
function LogWrap([string] $msg, [ScriptBlock] $action, [boolean] $disResult=$false) {
Write-Host -NoNewline "$msg . . . "
try {
$errcode, $msg=Invoke-Command -ScriptBlock $action
} catch {
$err=$true
$errcode=1
$msg=$_
}
if(-not $err) {
if(-not ($errcode -is [int])) {
$errcode=$LastExitCode
}
if(-not $msg) {
$msg=$Error[0].Exception.Message
}
}
if(-not $disResult -and $errcode -eq 0x0) {
Write-Host -NoNewline -ForegroundColor 'green' "done`n"
} elseif($errcode -eq -0x1) {
Write-Host -NoNewline -ForegroundColor 'yellow' "skipped`n"
} elseif($errcode -gt 0x0) {
Write-Host -NoNewline -ForegroundColor 'red' "failed"
Write-Host -ForegroundColor 'red' " with code $($errcode):`n$($msg)"
exit
}
}
try
{
$cwd=(Get-Location).Path
if($cleanOnly) { exit }
LogWrap "Checkout JS repository" {
if(Test-Path "./altv-types/") { return -0x1 }
New-Item -ItemType "directory" -Path "./altv-types" -Force
Set-Location -Path "./altv-types"
git init 2>$null
git remote add "origin" "https://github.com/altmp/altv-types/" 2>$null
git fetch --depth 1 "origin" "master" 2>$null
git reset --hard "FETCH_HEAD" 2>$null
git branch --set-upstream-to "origin/master" "master" 2>$null
Set-Location $cwd
}
LogWrap "Checkout C# repository" {
if(Test-Path "./coreclr-module/") { return -0x1 }
New-Item -ItemType "directory" -Path "./coreclr-module" -Force
Set-Location -Path "./coreclr-module"
git init 2>$null
git remote add "origin" "https://github.com/FabianTerhorst/coreclr-module/" 2>$null
git fetch --depth 1 "origin" "master" 2>$null
git reset --hard "FETCH_HEAD" 2>$null
git branch --set-upstream-to "origin/master" "master" 2>$null
Set-Location $cwd
}
LogWrap "Downloading DocFx package" {
if(Test-Path "./docfx/docfx.exe") { return -0x1 }
FetchAndDownloadRelease "dotnet/docfx" "docfx.zip" 2>$null
}
LogWrap "Extracting DocFx package" {
if(Test-Path "./docfx/docfx.exe") { return -0x1 }
ExtractArchive "docfx.zip" "./docfx/" 2>$null
}
LogWrap "Downloading DocFx TypeScriptReference package" {
if(Test-Path "./templates/docfx-plugins-typescriptreference/") { return -0x1 }
FetchAndDownloadRelease "Lhoerion/DocFx.Plugins.TypeScriptReference" "docfx-plugins-typescriptreference.zip" 2>&1 6>$null
}
LogWrap "Extracting DocFx TypeScriptReference package" {
if(Test-Path "./templates/docfx-plugins-typescriptreference/") { return -0x1 }
ExtractArchive "docfx-plugins-typescriptreference.zip" "./templates/" 2>&1 6>$null
}
LogWrap "Downloading DocFx DiscordFX package" {
if(Test-Path "./templates/discordfx/") { return -0x1 }
FetchAndDownloadRelease "Lhoerion/DiscordFX" "docfx-tmpls-discordfx.zip" 2>&1 6>$null
}
LogWrap "Extracting DocFx DiscordFX package" {
if(Test-Path "./templates/discordfx/") { return -0x1 }
ExtractArchive "docfx-tmpls-discordfx.zip" "./templates/" 2>&1 6>$null
}
LogWrap "Installing node dependencies" {
Set-Location -Path './altv-types/docs/'
yarn --version 2>$null
if($?) {
yarn install 2>$null
} else {
npm install 2>$null
}
Set-Location $cwd
}
LogWrap "Tools version" {
$vsVer=GetVisualStudioVersion
$docfxVer=GetAssemblyVersion "./docfx/docfx.exe"
$pluginVer=GetAssemblyVersion "./templates/docfx-plugins-typescriptreference/plugins/*.dll"
$themeVer=cat "./templates/discordfx/version.txt"
$typedocVer=npm view typedoc version
$type2docfxVer=npm view typedoc version
# & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -format json
Write-Host -NoNewline -ForegroundColor "green" "done`n"
if($vsVer -ne "") {
Write-Host "Visual Studio v$vsVer"
} else {
Write-Host -ForegroundColor "yellow" "Visual Studio installation not found!"
}
Write-Host "DocFx v$docfxVer"
Write-Host "DocFx TypescriptReference v$pluginVer"
Write-Host "DocFx DiscordFX v$themeVer"
Write-Host "TypeDoc v$typedocVer"
Write-Host "type2docfx v$type2docfxVer"
} $true
LogWrap "Generating JS project metadata" {
Set-Location -Path './altv-types/docs/'
$stderr=npx typedoc --options './typedoc.json' 2>$null
if($LastExitCode -gt 0x0) { return $LastExitCode, $stderr }
$stderr=npx type2docfx './api/.manifest' './api/' --basePath '.' --sourceUrl 'https://github.com/altmp/altv-types' --sourceBranch 'master' --disableAlphabetOrder 2>&1 6>$null
Set-Location $cwd
return $LastExitCode, $buff
}
LogWrap "Generating C# project metadata" {
if(VerifyVisualStudioInstance) {
./docfx/docfx metadata "./coreclr-module/docs/docfx.json"
} else {
return -0x1
}
}
./docfx/docfx build "docfx.json" --serve -p $port
}
finally
{
Set-Location $cwd
PostCleanup
}