-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
compile.sh
executable file
·95 lines (70 loc) · 2.41 KB
/
compile.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
#!/usr/bin/env bash
#--------------------------------------------------#
# This script compiles asset files. #
# #
# Author: Jack Cherng <[email protected]> #
#--------------------------------------------------#
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
THREAD_CNT=$(getconf _NPROCESSORS_ONLN)
PROJECT_ROOT=${SCRIPT_DIR}
LESS_FILES=(
"skins/classic/main.less"
"skins/elastic/main.less"
"skins/larry/main.less"
)
JS_FILES=(
"assets/main.js"
)
PATH=${PROJECT_ROOT}/node_modules/.bin:${PATH}
#-------#
# begin #
#-------#
pushd "${SCRIPT_DIR}" || exit
#--------------------#
# compile LESS files #
#--------------------#
for file_src in "${LESS_FILES[@]}"; do
if [ ! -f "${file_src}" ]; then
echo "'${file_src}' is not a file..."
continue
fi
echo "==================================="
echo "Begin compile '${file_src}'..."
echo "==================================="
file_dst=${file_src%.*}.css
npx lessc --insecure "${file_src}" \
| printf "%s\n" "$(cat -)" \
| npx cleancss -O2 -f 'breaks:afterAtRule=on,afterBlockBegins=on,afterBlockEnds=on,afterComment=on,afterProperty=on,afterRuleBegins=on,afterRuleEnds=on,beforeBlockEnds=on,betweenSelectors=on;spaces:aroundSelectorRelation=on,beforeBlockBegins=on,beforeValue=on;indentBy:2;indentWith:space;breakWith:lf' \
> "${file_dst}"
done
#----------------------------#
# transpile Javascript files #
#----------------------------#
for file_src in "${JS_FILES[@]}"; do
if [ ! -f "${file_src}" ]; then
echo "'${file_src}' is not a file..."
continue
fi
echo "==================================="
echo "Begin transpile '${file_src}'..."
echo "==================================="
file_export=${file_src%.*}.export.js
file_dst=${file_src%.*}.min.js
if [ ! -f "${file_export}" ]; then
has_no_file_export=true
echo ";" > "${file_export}"
fi
# to make the output file more diff-friendly, we beautify it and remove leading spaces
cat "${file_src}" "${file_export}" \
| npx browserify -t [ babelify ] - \
| npx terser --config-file terser.json -- \
| sed -e 's/[[:space:]]+$//' \
> "${file_dst}"
if [ "${has_no_file_export}" = "true" ]; then
rm -f "${file_export}"
fi
done
#-----#
# end #
#-----#
popd || exit