Skip to content

Commit

Permalink
feat: add powershell build script
Browse files Browse the repository at this point in the history
  • Loading branch information
ecator authored and YanxinTang committed Sep 14, 2021
1 parent f198367 commit 7808aaf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clipboard-online is an application to share cilpboard text between Windows and i
- `cd clipboard-online`
- `go get github.com/akavel/rsrc`
- `./build.sh`
- PowerShell:`.\build.ps1`
- You can find release bin at `release` directory

## Usage
Expand Down
1 change: 1 addition & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clipboard-online 是一款可以帮你在 💻Windows 和 📱iOS 之间分享
- `cd clipboard-online`
- `go get github.com/akavel/rsrc`
- `./build.sh`
- PowerShell:`.\build.ps1`
- 你可以在 `release` 目录下找到可执行文件

## 使用
Expand Down
61 changes: 61 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<#
.SYNOPSIS
build script
#>


param (
[string]$version = "",
[Switch]$debug
)


Set-Location -Path $(Split-Path -Parent $MyInvocation.MyCommand.Definition)


$ROOT = $PWD
$prog = $($(Select-String module go.mod) -replace '.*?/')
$RELEASE_DIR = "${ROOT}\release"
$ENV_GOAPTH = $(go env GOPATH)
$output="${RELEASE_DIR}/$prog.exe"
$mode = "release"

if ($version -eq "") {
git describe --exact-match 2>$null
if ($?) {
$version = $(git describe --tags --abbrev=0)
}
else {
$version = $(git log --pretty=format:'%h' -1)
}

}


if ($debug) {
$mode = "debug"
}

function build() {
& $ENV_GOAPTH/bin/rsrc.exe -manifest clipboard-online.manifest -ico app.ico -o rsrc.syso
if ( $mode -eq "debug") {
build_debug
}
else {
build_release
Write-Output "Build complete"
}
}

function build_debug() {
Write-Output "build: debug"
go build -ldflags="-X 'main.mode=$mode' -X 'main.version=$version'" -o $output
}

function build_release() {
Write-Output "build: release"
go build -ldflags="-s -w -H windowsgui -X 'main.mode=$mode' -X 'main.version=$version'" -o $output
}

# Start build
build

0 comments on commit 7808aaf

Please sign in to comment.