-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathbuild.sh
executable file
·63 lines (51 loc) · 1.63 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
#!/usr/bin/env bash
set -e
npm ci
mkdir -p cache
# get sqlite3 version
sqlite3_pkg=$(cat node_modules/sqlite3/package.json)
sqlite3_version=$(node -e "console.log(JSON.parse(\`$sqlite3_pkg\`).version)")
# download sqlite3 binary that need to pkg
if [[ $1 == "docker" ]]; then
targets=("napi-v6-linux-glibc-x64")
else
targets=("napi-v6-darwin-unknown-x64" "napi-v6-win32-unknown-x64" "napi-v6-linux-glibc-x64")
fi
for target in ${targets[@]}; do
if [ -f cache/$target.tar.gz ]; then
echo "$target.tar.gz has cache and skip to download."
else
wget -P cache https://github.com/TryGhost/node-sqlite3/releases/download/v$sqlite3_version/$target.tar.gz
fi
tar -zxvf cache/$target.tar.gz
cp -rf $target ./node_modules/sqlite3/lib/binding
rm -rf $target
done
npm run build:pwa
npm run build:cli
# backup package.json
cp package.json package.json.bak
# write pkg targets to package.json
pkg="$(cat package.json)"
if [[ $1 == "docker" ]]; then
node -e "const pkg = JSON.parse(\`$pkg\`); pkg.pkg.targets = [\"node18-linux-x64\"]; console.log(JSON.stringify(pkg))" >package.json
else
node -e "const pkg = JSON.parse(\`$pkg\`); pkg.pkg.targets = [\"node18-macos-x64\",\"node18-win-x64\",\"node18-linux-x64\"]; console.log(JSON.stringify(pkg))" >package.json
fi
if [ -d "build" ]; then
rm -rf build
fi
npm run pkg
# recover package.json
rm package.json
mv package.json.bak package.json
if [[ $1 == "docker" ]]; then
echo 'skip compression on docker building.'
else
cd build
tag=$(git describe --abbrev=0 --tags)
for binary in ./*; do
tar zcvf $(echo $binary | sed -e 's/.exe//g')-x64-$tag.tar.gz $binary
rm $binary
done
fi