-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.ps1
174 lines (136 loc) · 4.63 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
<#
.SYNOPSIS
发布 FrpGUI 应用程序到不同平台。
.DESCRIPTION
此脚本用于发布 FrpGUI 应用程序到 Windows、Linux、macOS 和浏览器平台。
.PARAMETER w
发布到 Windows 平台。
.PARAMETER l
发布到 Linux 平台。
.PARAMETER m
发布到 macOS 平台。
.PARAMETER c
设置此标志以创建客户端的发布版本。
.PARAMETER s
设置此标志以创建服务器的发布版本。
.PARAMETER b
设置此标志以发布浏览器版本。
.EXAMPLE
.\YourScript.ps1 -w -c -s
发布到 Windows 平台,创建客户端和服务器的发布版本。
.EXAMPLE
.\YourScript.ps1 -l
发布到 Linux 平台。
.EXAMPLE
.\YourScript.ps1 -m -c
发布到 macOS 平台,仅创建客户端的发布版本。
.EXAMPLE
.\YourScript.ps1 -b
发布到浏览器平台。
#>
param(
[Parameter()]
[switch]$w, #Windows
[switch]$l, #Linux
[switch]$m, #MacOS
[switch]$c, #Clients
[switch]$s, #Servers
[switch]$b #Browser
)
# 如果 $w, $l, $m 都为 false,则全部设为 true
if (-not ($w -or $l -or $m)) {
$w = $true
$l = $true
$m = $true
}
# 如果 $c, $s, $b 都为 false,则全部设为 true
if (-not ($c -or $s -or $b)) {
$c = $true
$s = $true
$b = $true
}
if ($w) { Write-Host "发布Windows" }
if ($l) { Write-Host "发布Linux" }
if ($m) { Write-Host "发布MacOS" }
if ($c) { Write-Host "发布客户端" }
if ($s) { Write-Host "发布服务器端" }
if ($b) { Write-Host "发布浏览器端" }
pause
$ErrorActionPreference = 'Stop'
try {
# 检查是否安装了.NET SDK
try {
dotnet
}
catch {
throw "未安装.NET SDK"
}
function Publish-UI {
param (
[string]$runtime,
[string]$outputDirectory
)
Write-Output "正在发布客户端:$runtime"
dotnet publish FrpGUI.Avalonia.Desktop -r $runtime -c Release -o $outputDirectory --self-contained true #/p:PublishSingleFile=true
$platform = switch ($runtime) {
"win-x64" { "windows_amd64" }
"linux-x64" { "linux_amd64" }
"osx-x64" { "darwin_amd64" }
}
mkdir $outputDirectory/frp -ErrorAction SilentlyContinue
Copy-Item "bin/frp_*_$platform/*" $outputDirectory/frp -Recurse
if (Test-Path $outputDirectory/FrpGUI.Avalonia.Desktop.exe) {
Move-Item $outputDirectory/FrpGUI.Avalonia.Desktop.exe $outputDirectory/FrpGUI.exe
}
if (Test-Path $outputDirectory/FrpGUI.Avalonia.Desktop) {
Move-Item $outputDirectory/FrpGUI.Avalonia.Desktop $outputDirectory/FrpGUI
}
}
function Publish-Service {
param (
[string]$runtime,
[string]$outputDirectory
)
Write-Output "正在发布服务:$runtime"
dotnet publish FrpGUI.WebAPI -r $runtime -c Release -o $outputDirectory --self-contained true
$platform = switch ($runtime) {
"win-x64" { "windows_amd64" }
"linux-x64" { "linux_amd64" }
"osx-x64" { "darwin_amd64" }
}
mkdir $outputDirectory/frp -ErrorAction SilentlyContinue
Copy-Item "bin/frp_*_$platform/*" $outputDirectory/frp -Recurse
}
Clear-Host
# 如果Publish目录存在,则删除
if (Test-Path "Publish") {
Remove-Item "Publish" -Recurse -Force
}
if ($c) {
if ($w) { Publish-UI -runtime "win-x64" -outputDirectory "Publish/client-win-x64" }
if ($l) { Publish-UI -runtime "linux-x64" -outputDirectory "Publish/client-linux-x64" }
if ($m) { Publish-UI -runtime "osx-x64" -outputDirectory "Publish/client-macos-x64" }
}
if ($s) {
if ($w) { Publish-Service -runtime "win-x64" -outputDirectory "Publish/server-win-x64" }
if ($l) { Publish-Service -runtime "linux-x64" -outputDirectory "Publish/server-linux-x64" }
if ($m) { Publish-Service -runtime "osx-x64" -outputDirectory "Publish/server-macos-x64" }
}
if ($b) {
Write-Output "正在发布:Browser"
dotnet publish FrpGUI.Avalonia.Browser -r browser-wasm -c Release -o "Publish/browser" --self-contained true
Move-Item "Publish/browser/wwwroot/*" "Publish/browser"
Copy-Item "FrpGUI.Avalonia.Browser/web.config" "Publish/browser"
Copy-Item "FrpGUI.Avalonia.Browser/uiconfig.json" "Publish/browser"
Remove-Item "Publish/browser/obj" -r
Remove-Item "Publish/browser/wwwroot" -r
}
Write-Output "正在清理"
Remove-Item FrpGUI*/bin/Release -Recurse
Write-Output "操作完成"
Invoke-Item Publish
pause
}
catch {
Write-Error $_
}