-
Notifications
You must be signed in to change notification settings - Fork 10
/
hack.sh
executable file
·73 lines (54 loc) · 1.8 KB
/
hack.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
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# This assumes the source dir is $(pwd)/src
FILENAME="$1"
NAMESPACE_PREFIX="_mordrax\$cotwelm"
ELMSTUFF="$(pwd)/elm-stuff"
ELMDIST="$(pwd)/dist/js/cotw.js"
echo "Namespace prefix: " $NAMESPACE_PREFIX
echo "elm-stuff: " $ELMSTUFF
echo "output: " $ELMDIST
if [ ! -d "$ELMSTUFF" ]; then
echo "Fail! $ELMSTUFF was not found, try a full make instead?"
exit -1
fi
if [ ! -f "$ELMDIST" ]; then
echo "Fail! $ELMDIST was not found, try a full make instead?"
exit -1
fi
elm-format --yes "./$FILENAME"
RES=$?
if [ $RES != 0 ]; then
exit $RES
fi
echo "elm-format - ok"
elm-make "./$FILENAME" --output=/dev/null
RES=$?
if [ $RES != 0 ]; then
exit $RES
fi
echo "elm-make ./${FILENAME} - ok"
MODULE="${FILENAME/.elm/}"
MODULE="${MODULE/src\//}"
MODULE="$(printf $MODULE | awk '{gsub("/","."); print}')"
MANGLED="${NAMESPACE_PREFIX}\$$(printf $MODULE | awk '{gsub("[.]","_"); print}')\$"
echo "Namespace: " $MANGLED
ELMO="$(printf $MODULE | awk '{gsub("[.]","-"); print}').elmo"
ELMO="$(find $ELMSTUFF -iname $ELMO)"
echo "Elmo: " $ELMO
MANGLEDREGX="$(printf $MANGLED | awk '{gsub("[$]","\\$"); print}')"
echo "Namespace to replace: " $MANGLEDREGX
FIRSTLINE=$(cat $ELMDIST | grep -n "^var $MANGLEDREGX" | head -1 | cut -d":" -f1)
if [ "Z$FIRSTLINE" == "Z" ]; then
echo "Fail! $MODULE was not found, try a full make instead?"
exit -1
fi
echo "First line found at: " $FIRSTLINE
LAST=$(cat $ELMDIST | grep -n "^var $MANGLEDREGX" | tail -1 | cut -d":" -f1)
LAST=$((LAST+1))
LASTFUNCTIONSIZE=$(tail -n +$LAST $ELMDIST | grep -n "^var ${NAMESPACE_PREFIX}" | head -1 | cut -d":" -f1)
LASTLINE=$((LAST+LASTFUNCTIONSIZE-2))
echo "Last line found at: " $LASTLINE
head -$((FIRSTLINE-1)) $ELMDIST > elm-hack.js
cat $ELMO >> elm-hack.js
tail -n +$((LASTLINE+1)) $ELMDIST >> elm-hack.js
mv elm-hack.js $ELMDIST