-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-qml-file.sh
executable file
·28 lines (24 loc) · 1.04 KB
/
make-qml-file.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
#!/usr/bin/env bash
# Merge .qml.template with compiled .js files.
set -o errexit -o pipefail -o nounset
main() {
declare version=$1
declare apiUrl=$2
declare templateFile=$3
declare pureFile=$4
declare impureFile=$5
declare polyfillFile=$6
sed -r \
-e "/\/\/ PURE FUNCTIONS HERE:/r $pureFile" \
-e "/\/\/ IMPURE FUNCTIONS HERE:/r $impureFile" \
-e "s/^ +version: +\"[^\"]*\" .*/version: \"$version\"/" \
-e "s/^ +title: +\"[^\"]*\" .*/title: \"Griffschrift (Nn2GS $version)\"/" \
"$templateFile" \
| awk -vpolyfillFile="$polyfillFile" '1; /\/\/ POLYFILL IMPLEMENTATION HERE:/ {if(polyfillFile) system("cat \"" polyfillFile "\"")}' \
| awk -vapiUrl="$apiUrl" '{if(apiUrl) sub(/http:\/\/localhost:[0-9]+\/nn2gs/, apiUrl)};1'
# Alternatives:
# awk '/\/\/ PURE FUNCTIONS HERE:/ { system("cat pure_functions.js"); skip }; 1' $< > $@
# sed '/\/\/ PURE FUNCTIONS HERE:/e cat pure_functions.js' $< > $@
# sed "/\/\/ PURE FUNCTIONS HERE:/a $$(<pure_functions.js)" $< > $@
}
main "$@"