-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·79 lines (61 loc) · 2.04 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·79 lines (61 loc) · 2.04 KB
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
#/bin/sh
set -o errexit
set -o errtrace; trap 'echo "Error ${?} ${BASH_SOURCE[0]:-?}:${LINENO:-?}"' ERR
set -o nounset
set -o pipefail
# The list of files to include in the service.
files=$(find -s\
css\
icons\
js\
manifest.json\
webfonts\
-type f)
# The current version in index.html.
version=$(grep 'name="version" content=' index.html | sed -E 's#.*content="(.*)".*#\1#')
case "${1:-}" in
help)
echo "http - local server"
echo "bump - increment version in index.html"
echo "sync - update local files with the version from the V2Web repository"
;;
http)
echo "Serving version: ${version}"
exec python3 -m http.server
;;
bump)
new=$(($version + 1))
echo "New version: $version -> ${new}"
sed -i '' -E 's#name="version" content=".*"#name="version" content="'${new}'"#' index.html
version=${new}
;;
sync)
echo "Syncing files:"
rsync -a --log-format=%f --exclude=.git --exclude=README.md --omit-dir-times --checksum --existing ../../versioduo/V2Web/ .
;;
"")
;;
*)
echo "Unknown command"
exit 1
;;
esac
echo "Building version: ${version}"
echo "Checking unsynced files:"
rsync -an --log-format=%f --exclude=.git --exclude=README.md --omit-dir-times --checksum --existing ../../versioduo/V2Web/ .
# The list of source files as a JavaScript array.
array=\'./\'
for file in $files; do
array="${array},\n \'${file}\'"
done
# The project name; used as the name of the cache database.
name=$(grep 'name="name" content=' index.html | sed -E 's#.*content="(.*)".*#\1#')
# The ISO date for the 'revised' field in index.html.
date=$(date "+%Y-%m-%d")
# Create a service-worker script file with the current version and the list of source files.
cp service-worker-template.js service-worker.js
sed -i '' -E "s#__NAME__#${name}#" service-worker.js
sed -i '' -E "s#__VERSION__#${version}#" service-worker.js
sed -i '' -E "s#__FILES__#${array}#" service-worker.js
# Update the date in index.html.
sed -i '' -E 's#name="revised" content=".*"#name="revised" content="'${date}'"#' index.html