-
-
Notifications
You must be signed in to change notification settings - Fork 422
/
include.sh
272 lines (219 loc) · 6.62 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#
# DataTables build environment variables and common functions
#
INCLUDE_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CLOSURE="/usr/local/closure_compiler/compiler.jar"
JSHINT="/usr/bin/jshint"
SASS="${INCLUDE_SCRIPT_DIR}/../node_modules/.bin/sass"
ESLINT="${INCLUDE_SCRIPT_DIR}/../node_modules/.bin/eslint"
UGLIFY="${INCLUDE_SCRIPT_DIR}/../node_modules/.bin/uglifyjs"
# CSS styling frameworks that DataTables supports
FRAMEWORKS=(
'bootstrap5'
'bootstrap4'
'bootstrap'
'bulma'
'foundation'
'jqueryui'
'semanticui'
'material'
'uikit'
'dataTables'
'tailwindcss'
)
# $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
local FILE=$(basename $1 .css)
local DIR=$(dirname $1)
echo_msg "CSS compressing $FILE.css"
$SASS --no-charset --stop-on-error --style compressed $DIR/$FILE.css > $DIR/$FILE.min.css
# compressed style will add a UTF8 BOM which messes with concatination - remove it.
sed -i '1s/^\xEF\xBB\xBF//' $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 {
local FILE=$(basename $1 .scss)
local 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 {
local EXTN=$1
local 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
# $3 string - Require libs `FW` will be replaced with the framework code
function js_frameworks {
local EXTN=$1
local DIR=$2
local REQUIRE=$3
for FRAMEWORK in ${FRAMEWORKS[*]}; do
if [ -e $DIR/$1.$FRAMEWORK.js ]; then
js_wrap $DIR/$EXTN.$FRAMEWORK.js "$REQUIRE"
fi
done
}
# Wrap a source file for ES and UMD loaders
# Note that this is not used by DataTables core itself
# (although the styling frameworks do).
#
# $1 - string - Full path to the file to wrap
# $2 - string - Require libs
function js_wrap {
local FULL=$1
local REQUIRE=$2
local EXTN="${FULL##*.}"
local FILE=$(basename $1 ".${EXTN}")
local DIR=$(dirname $1)
local WRAPPER="${SCRIPT_DIR}/wrapper.js"
if [ ! -z "$DT_DIR" ]; then
WRAPPER="$DT_DIR/build/wrapper.js"
fi
echo_msg "JS processing $FILE"
echo_msg " Creating ES module"
node $WRAPPER $FULL es $DIR/$FILE "$REQUIRE"
js_compress "$DIR/$FILE.mjs"
echo_msg " Creating UMD"
node $WRAPPER $FULL umd $DIR/$FILE "$REQUIRE"
js_compress "$DIR/$FILE.js"
if [[ $FILE == *"searchPanes"* ]]; then
echo_msg " Skipping lint of SearchPanes"
else
if [ -f $ESLINT ]; then
echo_msg " Linting UMD"
$ESLINT "$DIR/$FILE.js"
else
echo "No ESLint"
fi
fi
}
# Will compress a JS file, saving the new file into the
# same directory as the uncompressed file, but with `.min.`
# added into the file's extension
#
# $1 - string - Full path to the file to compress
# $2 - string - Require libs
function js_compress {
local LOG=$2
if [ -z "$DEBUG" ]; then
local FULL=$1
local COMP_EXTN="${FULL##*.}"
local FILE=$(basename $1 ".${COMP_EXTN}")
local DIR=$(dirname $1)
echo_msg " Minification - $COMP_EXTN"
cp $DIR/$FILE.$COMP_EXTN /tmp/$FILE.$COMP_EXTN
if [ -e $UGLIFY ]; then
$UGLIFY /tmp/$FILE.$COMP_EXTN -c -m --comments /^!/ -o /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 }')"
else
echo_error "NO UGLIFY - PLEASE RUN npm install"
fi
fi
}
# $1 - string - Full path to input file
# $2 - string - Full path to use for the output file
function js_require {
local IN_FILE=$(basename $1)
local DIR=$(dirname $1)
local OUT=$2
local 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}" \
-l "css:syntax css:demo js:syntax js:demo"
}