forked from hectorqin/reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·128 lines (116 loc) · 3.42 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
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
#!/bin/bash
oldJAVAHome=$JAVA_HOME
task=$1
version=""
rootDir=$(dirname $0)
checkJava()
{
if [ -d /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home ]; then
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
fi
javaVersion=$(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;')
if [[ "$javaVersion" -lt "110" ]]; then
echo "Java version must not lower than 11.0"
exit 1
fi
}
getVersion()
{
version=$(grep -Eo "^version = .*" $1 | grep -Eo "['\"].*['\"]" | tr -d "'\"")
}
getVersion $rootDir/build.gradle.kts
case $task in
build)
checkJava
# 调试打包
$rootDir/gradlew buildReader
;;
run)
checkJava
# 运行 javafx UI
port=$2
if [[ -z "$port" ]]; then
port=8080
fi
$rootDir/gradlew assemble --info
if test $? -eq 0; then
shift
shift
java -jar build/libs/reader-$version.jar --reader.app.showUI=true --reader.server.port=$port $@
fi
;;
win)
checkJava
# 打包 windows 安装包
JAVAFX_PLATFORM=win $rootDir/gradlew packageReaderWin
;;
linux)
checkJava
# 打包 linux 安装包
JAVAFX_PLATFORM=linux $rootDir/gradlew packageReaderLinux
;;
mac)
checkJava
# 打包 mac 安装包
JAVAFX_PLATFORM=mac $rootDir/gradlew packageReaderMac
;;
serve)
# 服务端一键运行
port=$2
if [[ -z "$port" ]]; then
port=8080
fi
mv src/main/java/com/htmake/reader/ReaderUIApplication.kt src/main/java/com/htmake/reader/ReaderUIApplication.kt.back
getVersion $rootDir/cli.gradle
$rootDir/gradlew -b cli.gradle assemble --info
if test $? -eq 0; then
shift
shift
mv src/main/java/com/htmake/reader/ReaderUIApplication.kt.back src/main/java/com/htmake/reader/ReaderUIApplication.kt
java -jar build/libs/reader-$version.jar --reader.server.port=$port $@
else
mv src/main/java/com/htmake/reader/ReaderUIApplication.kt.back src/main/java/com/htmake/reader/ReaderUIApplication.kt
fi
;;
cli)
# 服务端打包命令
shift
export JAVA_HOME=$oldJAVAHome
mv src/main/java/com/htmake/reader/ReaderUIApplication.kt src/main/java/com/htmake/reader/ReaderUIApplication.kt.back
getVersion $rootDir/cli.gradle
$rootDir/gradlew -b cli.gradle $@
mv src/main/java/com/htmake/reader/ReaderUIApplication.kt.back src/main/java/com/htmake/reader/ReaderUIApplication.kt
;;
yarn)
# yarn 快捷命令,默认 install
shift
cd $rootDir/web
yarn $@
;;
web)
# 开发web页面
cd $rootDir/web
yarn serve
;;
sync)
# 编译同步web资源
cd $rootDir/web
yarn sync
;;
*)
echo "
USAGE: $0 build|run|win|linux|mac|serve|cli|yarn|web|sync
build 调试打包
run 桌面端编译运行,需要先执行 sync 命令编译同步web资源
win 打包 windows 安装包
linux 打包 linux 安装包
mac 打包 mac 安装包
serve 服务端编译运行
cli 服务端打包命令
yarn web页面 yarn 快捷命令,默认 install
web 开发web页面
sync 编译同步web资源
"
;;
esac
export JAVA_HOME=$oldJAVAHome