This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
package.sh
executable file
·136 lines (115 loc) · 2.92 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
#!/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
}
APP="zwave2mqtt"
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 | egrep -o '[0-9].' | head -n 1)
echo "## Clear $PKG_FOLDER folder"
rm -rf $PKG_FOLDER/*
if [ ! -z "$1" ]; then
echo "## Building application..."
echo ''
npm run build
echo "Executing command: pkg package.json -t node12-linux-x64 --out-path $PKG_FOLDER"
pkg package.json -t node12-linux-x64 --out-path $PKG_FOLDER
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"
)
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
;;
*)
echo '####################'
echo '## Invalid option ##'
echo '####################'
exit
esac
done
fi
echo "## Check for .node files to include in executable folder"
mapfile -t TO_INCLUDE < <(find ./node_modules/ -type f -name "*.node" | grep -v obj.target)
TOTAL_INCLUDE=${#TO_INCLUDE[@]}
echo "## Found $TOTAL_INCLUDE files to include"
i=0
while [ "$i" -lt "$TOTAL_INCLUDE" ]
do
IFS='/' path=(${TO_INCLUDE[$i]})
file=${path[-1]}
echo "## Copying $file to $PKG_FOLDER folder"
cp "${TO_INCLUDE[$i]}" "./$PKG_FOLDER"
let "i = $i + 1"
done
echo "## Create folders needed"
cd $PKG_FOLDER
mkdir store -p
echo "## Create zip file $APP-v$VERSION"
zip -r $APP-v$VERSION.zip *