-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
package.sh
executable file
·178 lines (152 loc) · 4.05 KB
/
package.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
set -e
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question
read -p "$1 [$prompt] " REPLY
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
pkg() {
echo "Executing command: npx pkg $@"
npx pkg $@
}
APP=$(node -p "require('./package.json').name")
PKG_FOLDER="pkg"
echo "Destination folder: $PKG_FOLDER"
echo "App-name: $APP"
VERSION=$(node -p "require('./package.json').version")
echo "Version: $VERSION"
NODE_MAJOR=$(node -v | grep -E -o '[0-9].' | head -n 1)
echo "## Clear $PKG_FOLDER folder"
rm -rf $PKG_FOLDER/*
# if --arch is passed as argument, use it as value for ARCH
if [[ "$@" == *"--arch"* ]]; then
ARCH=$(echo "$@" | grep -oP '(?<=--arch=)[^ ]+')
else
ARCH=$(uname -m)
fi
echo "## Architecture: $ARCH"
if [ ! -z "$1" ]; then
echo "## Building application..."
echo ''
# skip build if args contains --skip-build
if [[ "$@" != *"--skip-build"* ]]; then
npm run build
else
echo "## Skipping build..."
fi
# if --bundle is passed as argument, cd to `build` folder
if [[ "$@" == *"--bundle"* ]]; then
echo "## Building bundle..."
echo ''
npm run bundle
echo "## Changing directory to build folder"
cd build
fi
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
pkg package.json -t node$NODE_MAJOR-linux-arm64 --out-path $PKG_FOLDER
elif [ "$ARCH" = "armv7" ]; then
pkg package.json -t node$NODE_MAJOR-linux-armv7 --out-path $PKG_FOLDER --public-packages=*
else
pkg package.json -t node$NODE_MAJOR-linux-x64,node$NODE_MAJOR-win-x64 --out-path $PKG_FOLDER
fi
else
if ask "Re-build $APP?"; then
echo "## Building application"
npm run build
fi
echo '###################################################'
echo '## Choose architecture to build'
echo '###################################################'
echo ' '
echo 'Your architecture is' $ARCH
PS3="Architecture: >"
options=(
"x64"
"armv7"
"armv6"
"x86"
"alpine"
"arm64"
)
echo ''
select option in "${options[@]}"; do
case "$REPLY" in
1)
echo "## Creating application package in $PKG_FOLDER folder"
pkg package.json -t node$NODE_MAJOR-linux-x64 --out-path $PKG_FOLDER
break
;;
2)
echo "## Creating application package in $PKG_FOLDER folder"
pkg package.json -t node$NODE_MAJOR-linux-armv7 --out-path $PKG_FOLDER --public-packages=*
break
;;
3)
echo "## Creating application package in $PKG_FOLDER folder"
pkg package.json -t node$NODE_MAJOR-linux-armv6 --out-path $PKG_FOLDER --public-packages=*
break
;;
4)
echo "## Creating application package in $PKG_FOLDER folder"
pkg package.json -t node$NODE_MAJOR-linux-x86 --out-path $PKG_FOLDER
break
;;
5)
echo "## Creating application package in $PKG_FOLDER folder"
pkg package.json -t node$NODE_MAJOR-alpine-x64 --out-path $PKG_FOLDER
break
;;
6)
echo "## Creating application package in $PKG_FOLDER folder"
pkg package.json -t node$NODE_MAJOR-linux-arm64 --out-path $PKG_FOLDER --public-packages=*
break
;;
*)
echo '####################'
echo '## Invalid option ##'
echo '####################'
exit
esac
done
fi
echo "## Create folders needed"
cd $PKG_FOLDER
mkdir store -p
if [ ! -z "$1" ]; then
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
echo "## Create zip file $APP-v$VERSION-linux-arm64"
zip -r $APP-v$VERSION-linux-arm64.zip store $APP
elif [ "$ARCH" = "armv7" ]; then
echo "## Create zip file $APP-v$VERSION-linux-armv7"
zip -r $APP-v$VERSION-linux-armv7.zip store $APP
else
echo "## Create zip file $APP-v$VERSION-win"
zip -r $APP-v$VERSION-win.zip store $APP-win.exe
echo "## Create zip file $APP-v$VERSION-linux"
zip -r $APP-v$VERSION-linux.zip store $APP-linux
fi
else
echo "## Create zip file $APP-v$VERSION"
zip -r $APP-v$VERSION.zip store $APP
fi