forked from arianra/vmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·126 lines (99 loc) · 3.06 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
echo "Velocity Motion Designer Compiler v0.1 [11/23/2014]"
command -v cleancss >/dev/null 2>&1 || {
echo "\nI require cleancss but it's not installed. Install using:"
echo ""
echo "\t\tnpm install -g cleancss"
echo ""
exit 1
}
command -v uglifyjs >/dev/null 2>&1 || {
echo "\nI require uglifyJS2 but it's not installed. Install using:"
echo ""
echo "\t\tnpm install -g uglify-js"
echo ""
exit 1
}
SRC="./src"
DEST="./dist/vmd.js"
CSS="$(find $SRC -type f | egrep ".css" )"
JS="$(find $SRC -type f | egrep ".js" )"
WOFF="$(find $SRC -type f | egrep ".woff" )"
FILES=()
DIRS=()
declare -a FILES
declare -a DIRS
arr=("${arr[@]}" "newest")
# Compile all found CSS files.
for c in $CSS; do
DIRS=("${DIRS[@]}" ${c%/*})
FILES=("${FILES[@]}" ${c##*/})
done
# Compile all found JS files.
for w in $WOFF; do
DIRS=("${DIRS[@]}" ${w%/*})
FILES=("${FILES[@]}" ${w##*/})
done
# Compile all found JS files.
for j in $JS; do
DIRS=("${DIRS[@]}" ${j%/*})
FILES=("${FILES[@]}" ${j##*/})
done
# Sort
# DIRS=($(printf '%s\n' "${DIRS[@]}"|sort|uniq))
# FILES=($(printf '%s\n' "${FILES[@]}"|sort|uniq))
OUTPUT="// FINAL"
for d in ${!DIRS[@]}; do
FILE=${FILES[d]}
F=${DIRS[d]}/${FILES[d]}
E="${FILES[d]##*.}"
test "$E" == 'css' && {
CSS="$(cleancss --skip-advanced $F)"
# Escape
CSS="$(echo $CSS | sed 's/\"/\\\"/g')"
OUTPUT+="\n\n// "$FILE"\n"
# OUTPUT+="\$(\"body\").append(\"<style>$CSS</style>\");";
OUTPUT+="document.getElementsByTagName('body')[0].innerHTML += \"<style>$CSS</style>\";";
}
test "$E" == 'js' && {
# Skip the development declaration file
test "$FILE" == "00.vmd.development.js" && {
continue;
}
JS="$(uglifyjs $F)"
OUTPUT+="\n\n// "$FILE"\n"
OUTPUT+=$JS
}
test "$E" == 'woff' && {
# Convert the woff file to base64
WOFF="$(base64 $F)"
# Use the file name as the font family name.
FAMILY=(${FILES[d]//./ })
fam=${FAMILY[1]}
c=0
for char in $(sed -E s/'(.)'/'\1 '/g <<<"$fam"); do
let "c++"
test "$c" == 1 && {
FAMILY="$(echo $char | tr [a-z] [A-Z])"
continue;
}
FAMILY+=$char
done
# Generate the font face output
WOFFDATA="@font-face {"
WOFFDATA+="font-family: '$FAMILY';"
WOFFDATA+="src: url('data:application/x-font-woff;base64,$WOFF');"
WOFFDATA+="font-style: normal;"
WOFFDATA+="font-weight: normal;"
WOFFDATA+="font-variant: normal;"
WOFFDATA+="text-decoration: inherit;"
WOFFDATA+="text-transform: none;"
WOFFDATA+="}"
# Escape
WOFFDATA="$(echo $WOFFDATA | sed 's/\"/\\\"/g')"
OUTPUT+="\n\n// "$FILE"\n"
# OUTPUT+="\$(\"body\").append(\"<style>$WOFFDATA</style>\");";
OUTPUT+="document.getElementsByTagName('body')[0].innerHTML += \"<style>$WOFFDATA</style>\";";
}
done
echo $OUTPUT > $DEST