-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.sh
67 lines (57 loc) · 1.88 KB
/
build.sh
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
###
# @Author: SpenserCai
# @Date: 2023-08-17 11:04:55
# @version:
# @LastEditors: SpenserCai
# @LastEditTime: 2023-10-08 13:26:09
# @Description: file content
###
# Web接口代码生存
GOPATH=$(go env GOPATH)
# 判断是否安装go-swagger,如果没有则安装(在GOPATH/bin目录下)
if [ ! -f "$GOPATH/bin/swagger" ]; then
echo "go-swagger not found, install go-swagger"
go get -u github.com/go-swagger/go-swagger
go install github.com/go-swagger/go-swagger/cmd/swagger
fi
API_PATH="./api"
API_SWAGGER_PATH="./api/swagger.yml"
# 判断是否传入--gen-api参数,如果传入则重新生成api代码
if [ "$1" = "--gen-api" ]; then
echo "generate api code"
rm -rf $API_PATH/gen
mkdir $API_PATH/gen
$GOPATH/bin/swagger generate server -f $API_SWAGGER_PATH --regenerate-configureapi -t $API_PATH/gen/
fi
export GOOS=linux
go build -o "./release/sd-webui-discord"
# 判断是否安装了gcc-mingw-w64,如果没有则安装
if [ ! -f "/usr/bin/x86_64-w64-mingw32-gcc" ]; then
echo "gcc-mingw-w64 not found, install gcc-mingw-w64"
sudo apt install gcc-mingw-w64
fi
export CC=x86_64-w64-mingw32-gcc
export CXX=x86_64-w64-mingw32-g++
export GOOS=windows
export GOARCH=amd64
export CGO_ENABLED=1
go build -o "./release/sd-webui-discord.exe"
# 判断是否存在config.json
if [ ! -f "./release/config.json" ]; then
echo "config.json not found, copy config.example.json to config.json"
cp ./config.example.json ./release/config.json
fi
# 吧location目录和其中的文件复制到release目录,如果存在location目录则删除后再复制
if [ -d "./release/location" ]; then
rm -rf ./release/location
fi
# 切换到website目录,安装依赖并打包
cd ./website
npm install
npm run build
cd ..
if [ -d "./release/website" ]; then
rm -rf ./release/website
fi
cp -r ./location ./release/location
cp -r ./website/dist ./release/website