forked from DataTables/DataTablesSrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
include.sh
227 lines (182 loc) · 5.58 KB
/
include.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#
# DataTables build environment variables and common functions
#
CLOSURE="/usr/local/closure_compiler/compiler.jar"
JSHINT="/usr/bin/jshint"
# CSS styling frameworks that DataTables supports
FRAMEWORKS=(
'bootstrap5'
'bootstrap4'
'bootstrap'
'bulma'
'foundation'
'jqueryui'
'semanticui'
'material'
'uikit'
'dataTables'
)
# $1 - string - file to get the version from
function version_from_file {
echo $(grep " * @version " $1 | awk -F" " '{ print $3 }')
}
# $1 - string - section name to echo
function echo_section {
# Cyan
printf "\033[0;36m %s\033[0m \n" "$1"
}
# $1 - string - message to echo
function echo_msg {
# Green
printf "\033[0;32m %s\033[0m \n" "$1"
}
# $1 - string - error to echo
function echo_error {
# Red
printf "\033[0;31m %s\033[0m \n" "$1"
}
# Will compress a CSS file using SASS, saving the new file into the same
# directory as the uncompressed file, but with `.min.css` as the extension.
#
# $1 - string - Full path to the file to compress
function css_compress {
# Only compresses CSS at the moment
if [ -z "$DEBUG" ]; then
FILE=$(basename $1 .css)
DIR=$(dirname $1)
echo_msg "CSS compressing $FILE.css"
sass --no-charset --stop-on-error --style compressed $DIR/$FILE.css > $DIR/$FILE.min.css
echo_msg " File size: $(ls -l $DIR/$FILE.min.css | awk -F" " '{ print $5 }')"
fi
}
# Compile a SCSS file
#
# $1 - string - Full path to the file to compile
function scss_compile {
FILE=$(basename $1 .scss)
DIR=$(dirname $1)
echo_msg "SCSS compiling $FILE.scss"
sass --no-charset --stop-on-error --style expanded $DIR/$FILE.scss > $DIR/$FILE.css
css_compress $DIR/$FILE.css
}
# Compile SCSS files for a specific extension and the supported frameworks
#
# $1 - string - Extension name (camelCase)
# $2 - string Build directory where the CSS files should be created
function css_frameworks {
EXTN=$1
DIR=$2
for FRAMEWORK in ${FRAMEWORKS[*]}; do
if [ -e $DIR/$1.$FRAMEWORK.scss ]; then
scss_compile $DIR/$EXTN.$FRAMEWORK.scss
rm $DIR/$EXTN.$FRAMEWORK.scss
fi
done
}
# Compress JS files for a specific extension and the supported frameworks
#
# $1 string - Extension name (camelCase)
# $2 string - Build directory where the JS min files should be created
function js_frameworks {
EXTN=$1
DIR=$2
for FRAMEWORK in ${FRAMEWORKS[*]}; do
if [ -e $DIR/$1.$FRAMEWORK.js ]; then
js_compress $DIR/$EXTN.$FRAMEWORK.js
fi
done
}
# Will compress a JS file using Closure compiler, saving the new file into the
# same directory as the uncompressed file, but with `.min.js` as the extension.
#
# $1 - string - Full path to the file to compress
# $2 - string - Enable ('on' - default) errors or disable ('off')
function js_compress {
LOG=$2
if [ -z "$DEBUG" ]; then
FULL=$1
COMP_EXTN="${FULL##*.}"
FILE=$(basename $1 ".${COMP_EXTN}")
DIR=$(dirname $1)
echo_msg "JS compressing $FILE.${COMP_EXTN}"
# Closure Compiler doesn't support "important" comments so we add a
# @license jsdoc comment to the license block to preserve it
cp $DIR/$FILE.$COMP_EXTN /tmp/$FILE.$COMP_EXTN
perl -i -0pe "s/^\/\*! (.*)$/\/** \@license \$1/s" /tmp/$FILE.$COMP_EXTN
rm /tmp/closure_error.log
java -jar $CLOSURE --charset 'utf-8' --language_out=ES5 --js /tmp/$FILE.$COMP_EXTN > /tmp/$FILE.min.$COMP_EXTN 2> /tmp/closure_error.log
if [ -e /tmp/closure_error.log ]; then
if [ -z "$LOG" -o "$LOG" = "on" ]; then
cat /tmp/closure_error.log
fi
fi
# And add the important comment back in
perl -i -0pe "s/^\/\*/\/*!/s" /tmp/$FILE.min.$COMP_EXTN
mv /tmp/$FILE.min.$COMP_EXTN $DIR/$FILE.min.$COMP_EXTN
rm /tmp/$FILE.$COMP_EXTN
echo_msg " File size: $(ls -l $DIR/$FILE.min.$COMP_EXTN | awk -F" " '{ print $5 }')"
fi
}
# $1 - string - Full path to input file
# $2 - string - Full path to use for the output file
function js_require {
IN_FILE=$(basename $1)
DIR=$(dirname $1)
OUT=$2
CURR_DIR=$(pwd)
cd $DIR
OLD_IFS=$IFS
IFS='%'
cp $IN_FILE $IN_FILE.build
grep "_buildInclude('" $IN_FILE.build > /dev/null
while [ $? -eq 0 ]; do
REQUIRE=$(grep "_buildInclude('" $IN_FILE.build | head -n 1)
SPACER=$(echo ${REQUIRE} | cut -d _ -f 1)
FILE=$(echo ${REQUIRE} | sed -e "s#^.*_buildInclude('##g" -e "s#');##")
DIR=$(echo ${FILE} | cut -d \. -f 1)
sed "s#^#${SPACER}#" < ${DIR}/${FILE} > ${DIR}/${FILE}.build
sed -e "/${REQUIRE}/r ${DIR}/${FILE}.build" -e "/${REQUIRE}/d" < $IN_FILE.build > $IN_FILE.out
mv $IN_FILE.out $IN_FILE.build
rm ${DIR}/${FILE}.build
grep "_buildInclude('" $IN_FILE.build > /dev/null
done
mv $IN_FILE.build $OUT
IFS=$OLD_IFS
cd $CURR_DIR
}
# Run JSHint over a JS file
#
# $1 - string - Full path to input file
function js_hint {
FILE=$1
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# JSHint
if [ -e $JSHINT ]; then
$JSHINT --config $DIR/jshint.config $FILE
if [ $? -eq 0 ]; then
echo_msg "JSHint passed"
else
echo_error "JSHint failed"
fi
else
echo_error "JSHint not installed at $JSHINT - skipping"
fi
}
# Process XML example files into HTML files - in place! The XML files will be
# removed.
#
# $1 - string - Path to the examples to processing - note that /examples is
# added automatically
function examples_process {
php ${DT_SRC}/build/examples.php \
-d \
-o $1 \
-u ${DT_SRC}/build/templates/example_index.html \
-t ${DT_SRC}/build/templates/example.html \
-c "demo:${DT_BUILT}/examples/resources/demo.css" \
-j "demo:${DT_BUILT}/examples/resources/demo.js" \
-c "syntax:${DT_BUILT}/examples/resources/syntax/shCore.css" \
-j "syntax:${DT_BUILT}/examples/resources/syntax/shCore.js" \
-m "${DT_BUILT}/media" \
-l "css:syntax css:demo js:syntax js:demo"
}