Fix build scripts

This commit is contained in:
Markson committed 2022-09-19 21:07:16 +08:00
1 parent ca6a052732
commit 81ef00684b
2 files changed
+72 -75

No files matched your search

+62 -66
View File
@@ -1,4 +1,6 @@
Function Gzip-File([ValidateScript({Test-Path $_})][string]$File){
Write-Host $PSScriptRoot
Function Compress-File([ValidateScript({Test-Path $_})][string]$File){
$srcFile = Get-Item -Path $File
$newFileName = "$($srcFile.FullName).gz"
@@ -22,75 +24,69 @@ Function Gzip-File([ValidateScript({Test-Path $_})][string]$File){
}
}
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)) {
Function Get-build-tools(){
if ([String]::IsNullOrEmpty($(Get-Command git -ErrorAction ignore))) {
Write-Output "You don't install git, please install it and add it to your path."
}
if ([String]::IsNullOrEmpty($(Get-Command yarn -ErrorAction ignore))) {
Write-Output "You don't install yarn, please install it and add it to your path."
Write-Output "You should also install Node.js to make yarn work fine."
}
if ([String]::IsNullOrEmpty($(Get-Command go -ErrorAction ignore))) {
Write-Output "You don't install go, please install it and add it to your path."
}
if ([String]::IsNullOrEmpty($(Get-Command git -ErrorAction ignore))) {
exit 1
}
if ([String]::IsNullOrEmpty($(Get-Command yarn -ErrorAction ignore))) {
exit 1
}
if ([String]::IsNullOrEmpty($(Get-Command go -ErrorAction ignore))) {
exit 1
}
}
Function Build-v2rayA(){
#Get OS
if ([String]::IsNullOrEmpty($(Test-Path ${$env:windir} -ErrorAction Ignore))) {
$v2rayaBin = "v2raya"
}
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"
$v2rayaBin = "v2raya.exe"
}
#Get Paths
$TerminalPath = Get-Item -LiteralPath ./ | ForEach-Object -Process { $_.FullName }
$CurrentPath = $PSScriptRoot
#Get Informations
$DateLong = git log -1 --format="%cd" --date=short
$Date = $DateLong -replace "-"; ""
$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 Web Panel
Set-Location -Path "$currentPath/gui"
yarn; yarn build
#Compress Web Panel's files
Get-ChildItem "$CurrentPath/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"){
Compress-File($_.FullName)
Remove-Item -Path $_.FullName
}
}
#Build v2rayA
Set-Location -Path "$CurrentPath/service"
go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$CurrentPath/$v2rayaBin"
Set-Location -Path "$TerminalPath"
}
Set-Location -Path "$SHELL_FOLDER"
Set-PSDebug -Trace 1
Get-build-tools
Build-v2rayA
Set-PSDebug -Trace 0
+10 -9
View File
@@ -1,20 +1,21 @@
#!/bin/bash
set -ex
CWD="$(pwd)"
SHELL_FOLDER="$(dirname $(realpath $0))"
if [ -d "$SHELL_FOLDER/.git" ]; then
date=$(git -C "$SHELL_FOLDER" log -1 --format="%cd" --date=short | sed s/-//g)
count=$(git -C "$SHELL_FOLDER" rev-list --count HEAD)
commit=$(git -C "$SHELL_FOLDER" rev-parse --short HEAD)
CurrentDir="$(pwd)"
if [ -d "$CurrentDir/.git" ]; then
date=$(git -C "$CurrentDir" log -1 --format="%cd" --date=short | sed s/-//g)
count=$(git -C "$CurrentDir" rev-list --count HEAD)
commit=$(git -C "$CurrentDir" rev-parse --short HEAD)
version="unstable-$date.r${count}.$commit"
else
version="unstable"
fi
cd "$SHELL_FOLDER"/gui && yarn && OUTPUT_DIR="$SHELL_FOLDER"/service/server/router/web yarn build
for file in $(find "$SHELL_FOLDER"/service/server/router/web |grep -v png |grep -v index.html|grep -v .gz)
cd "$CurrentDir"/gui && yarn && OUTPUT_DIR="$CurrentDir"/service/server/router/web yarn build
for file in $(find "$CurrentDir"/service/server/router/web |grep -v png |grep -v index.html|grep -v .gz)
do
if [ ! -d $file ];then
gzip -9 $file
fi
done
cd "$SHELL_FOLDER"/service && CGO_ENABLED=0 go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$CWD"/v2raya
cd "$CurrentDir"/service && CGO_ENABLED=0 go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$CurrentDir"/v2raya