forked from v2rayA/v2rayA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-in-pwsh.ps1
96 lines (81 loc) · 3.16 KB
/
build-in-pwsh.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
Function Gzip-File([ValidateScript({Test-Path $_})][string]$File){
$srcFile = Get-Item -Path $File
$newFileName = "$($srcFile.FullName).gz"
try
{
$srcFileStream = New-Object System.IO.FileStream($srcFile.FullName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read))
$dstFileStream = New-Object System.IO.FileStream($newFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None))
$gzip = New-Object System.IO.Compression.GZipStream($dstFileStream,[System.IO.Compression.CompressionMode]::Compress)
$srcFileStream.CopyTo($gzip)
}
catch
{
Write-Host "$_.Exception.Message" -ForegroundColor Red
}
finally
{
$gzip.Dispose()
$srcFileStream.Dispose()
$dstFileStream.Dispose()
}
}
Set-PSDebug -Trace 1
## Check OS
$TestWinDir = Test-Path $env:windir -ErrorAction Ignore
if ([String]::IsNullOrEmpty($TestWinDir)) {
$v2rayaBin = "v2raya"
}
else {
$v2rayaBin = "v2raya.exe"
}
## Test Git / yarn /Go
$TestGit = Get-Command git -ErrorAction ignore
$TestYarn = Get-Command yarn -ErrorAction ignore
$TestGo = Get-Command go -ErrorAction ignore
if ([String]::IsNullOrEmpty($TestGit)) {
Write-Output "You don't install git, please install it and add it to your path."
}
else {
if ([String]::IsNullOrEmpty($TestYarn)) {
Write-Output "You don't install yarn, please install it and add it to your path."
}
else {
if ([String]::IsNullOrEmpty($TestGo)) {
Write-Output "You don't install golang, please install it and add it to your path."
}
else {
## Get current folder
## $SHELL_FOLDER = Get-Item -LiteralPath ./ | ForEach-Object -Process { $_.FullName }
$CWD = Get-Location
$shell_path = Resolve-Path -Path $PSCommandPath
$SHELL_FOLDER = Split-Path $shell_path
## Get date
$DateLong = git log -1 --format="%cd" --date=short
$Date = $DateLong -replace "-"; ""
## Other info
$count = git rev-list --count HEAD
$commit = git rev-parse --short HEAD
## Version
$version = "unstable-$date.r$count.$commit"
## Disable CGO
${env:CGO_ENABLED} = "0"
## Set yarn's output path
${env:OUTPUT_DIR} = "$SHELL_FOLDER/service/server/router/web"
## Build v2rayA
$guiPath = $SHELL_FOLDER + "/gui"
Set-Location -path "$guiPath"
yarn
yarn build
Get-ChildItem "$SHELL_FOLDER/service/server/router/web" -recurse |Where-Object{$_.PSIsContainer -eq $False}|ForEach-Object -Process{
if($_.Extension -ne ".png" -and $_.Extension -ne ".gz" -and $_.Name -ne "index.html"){
Gzip-File($_.FullName)
Remove-Item -Path $_.FullName
}
}
$corePath = $SHELL_FOLDER + "/service"
Set-Location -path "$corePath"
go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$SHELL_FOLDER/$v2rayaBin"
}
}
}
Set-Location -Path "$SHELL_FOLDER"