-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-scripts
81 lines (66 loc) · 2.48 KB
/
build-scripts
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
#!/bin/bash
# TODO: find a better way to uglifyjs, remove comments and only keep minified script injection in memory
## inject INJECT.SCRIPT into all scripts
# We want to minify the injection script, but we only want to do it once (in case we're about to batch
# build scripts). Compare the dist version of script inject (should be the same) and also if the minified
# version exists; if not then uglify, otherwise use current min
# Source file js/SCRIPT.INJECTION.js doesn't exist?
if [ ! -f js/SCRIPT.INJECTION.js ]; then
echo "js/SCRIPT.INJECTION.js doesn't exist. Exiting!";
exit
fi
# Do we need to rebuild SCRIPT.INJECTION.min.js?
needToRebuild=0
# Dist file dist/js/SCRIPT.INJECTION.js doesn't exist?
if [ ! -f dist/js/SCRIPT.INJECTION.js ]; then
echo "dist/js/SCRIPT.INJECTION.js doesn't exist. Copying over";
needToRebuild=1;
fi
if [ ! -f dist/js/SCRIPT.INJECTION.min.js ]; then
echo "dist/js/SCRIPT.INJECTION.min.js doesn't exist. Rebuilding";
needToRebuild=1;
fi
# Hashes differ between js/SCRIPT.INJECTION.js and dist/js/SCRIPT.INJECTION.js?
uniques=$( cksum js/SCRIPT.INJECTION.js dist/js/SCRIPT.INJECTION.js | awk '{ print $1 }' | uniq | xargs | wc --words )
if [ "$uniques" -eq "2" ]; then
echo "SCRIPT.INJECTION.js differs from dist/js/SCRIPT.INJECTION.js"
needToRebuild=1;
fi
# - Rebuild
if [ "$needToRebuild" == "1" ]; then
echo "Rebuilding script injection"
cp js/SCRIPT.INJECTION.js dist/js/SCRIPT.INJECTION.js;
node_modules/.bin/uglifyjs dist/js/SCRIPT.INJECTION.js > dist/js/SCRIPT.INJECTION.min.js
printf "\n" >> dist/js/SCRIPT.INJECTION.min.js
fi
BUILD_FILE=""
while [ $# -gt 0 ]; do
case "$1" in
--file ) BUILD_FILE="$2"; shift; shift ;;
-- ) shift; break ;;
* ) echo "Unknown option $1" ; exit ;;
esac
done
if [ "$BUILD_FILE" != "" ]; then
f="$BUILD_FILE"
echo "Building script: $f"
if grep -q "^\s*\/\*\s*SCRIPTINJECT\s*\*\/" $f
then
sed -i '/\/\*\s*SCRIPTINJECT\s*\*\//r dist/js/SCRIPT.INJECTION.min.js' $f
sed -i '/\/\*\s*SCRIPTINJECT\s*\*\//d' $f
echo "$f > $f"
fi
else
#START=$(date +%s.%N)
for f in dist/js/scripts/*.js; do
if grep -q "^\s*\/\*\s*SCRIPTINJECT\s*\*\/" $f
then
sed -i '/\/\*\s*SCRIPTINJECT\s*\*\//r dist/js/SCRIPT.INJECTION.min.js' $f
sed -i '/\/\*\s*SCRIPTINJECT\s*\*\//d' $f
echo "$f > $f"
fi
done
#END=$(date +%s.%N)
#DIFF=$(echo "$END - $START" | bc)
#echo "$DIFF"
fi