-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·69 lines (63 loc) · 3.34 KB
/
build
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
#!/bin/bash
# ----------------------------------------------------------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------------------------------------------------------
SOURCE_DIR="www/"
DEPLOY_DIR="www-deploy/"
BUILD_INFO_MMR="1.0.0"
BUILD_INFO_FILE_APP="${SOURCE_DIR}index.html"
BUILD_INFO_FILE_SW="${SOURCE_DIR}sw.js"
# ----------------------------------------------------------------------------------------------------------------------
# Update build info in files
# ----------------------------------------------------------------------------------------------------------------------
function updateBuildInfoInFile() {
local file=$1
printf "\n::::: Updating Build Info in ${file}:\n"
# Update MMR --
sed -i -r "s|(const BUILD_MMR = ').*(';)|\1${BUILD_INFO_MMR}\2|g" ${file}
# Update the BUILD_DATE constant --
BUILD_DATE_OLD=$(grep "const BUILD_DATE" ${file} | sed -r -e "s/^.*'(.*)';/\1/g")
printf -v BUILD_DATE_NEW '%(%Y%m%d)T'
sed -i -r "s|(const BUILD_DATE = ').*(';)|\1${BUILD_DATE_NEW}\2|g" ${file}
# Update the BUILD_NUMBER constant --
# Reset build number if this is the first build of a new day.
BUILD_NUMBER=$(grep "const BUILD_NUMBER" ${file} | sed -r -e "s/^.*'(.*)';/\1/g")
if [[ "$BUILD_DATE_NEW" != "$BUILD_DATE_OLD" ]]; then
BUILD_NUMBER=1
else
BUILD_NUMBER=$((BUILD_NUMBER + 1))
fi
sed -i -r "s|(const BUILD_NUMBER = ').*(';)|\1${BUILD_NUMBER}\2|g" ${file}
export APP_VERSION="${BUILD_INFO_MMR}.${BUILD_DATE_NEW}#${BUILD_NUMBER}"
echo "APP_VERSION=${UPLIFT_VERSION}"
echo "APP_VERSION=${BUILD_INFO_MMR}.${BUILD_DATE_NEW}#${BUILD_NUMBER}" > ./app-version.txt
}
updateBuildInfoInFile $BUILD_INFO_FILE_APP
updateBuildInfoInFile $BUILD_INFO_FILE_SW
# ----------------------------------------------------------------------------------------------------------------------
# Sync the source dir into the deploy dir (just the diffs)
# ----------------------------------------------------------------------------------------------------------------------
printf "\n::::: Syncing ${SOURCE_DIR} to ${DEPLOY_DIR}:\n\n"
rsync -v -a $SOURCE_DIR $DEPLOY_DIR --delete
# ----------------------------------------------------------------------------------------------------------------------
# Generate the list of pre-cached files with fingerprints and inject into the service worker file.
# ----------------------------------------------------------------------------------------------------------------------
# See https://developers.google.com/web/tools/workbox/guides/precache-files/cli
#workbox wizard --injectManifest
printf "\n::::: Injecting precache manifest:\n"
workbox injectManifest workbox-config-precache.js
printf "\n::::: Injecting runtime manifest:\n"
workbox injectManifest workbox-config-runtime.js
# ----------------------------------------------------------------------------------------------------------------------
# Deploy to Firebase?
# ----------------------------------------------------------------------------------------------------------------------
if [ "$1" == "deploy" ]; then
printf "\n::::: Deploying app to firebase:\n"
if [ "$2" == "debug" ]; then
firebase --debug --only hosting deploy
else
firebase deploy
fi
fi
printf "\n::::: BUILD DONE!\n"
cat ./app-version.txt