forked from Duet3D/DuetWebControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·121 lines (99 loc) · 3.82 KB
/
build.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
#!/bin/sh
# Script to compress and build additional spiffs file system for DWC
#
# This script requires the following tools:
# - mkspiffs from https://github.com/igrr/mkspiffs/releases
# - yui-compressor from https://yui.github.io/yuicompressor
# Make sure both tools are accessible via your PATH environment variable!
# Get the current version
VERSION=$(grep -oP "Duet Web Control v\K(.*)" ./core/reprap.htm)
# Core directory must contain reprap.htm
if [ -f !"./core/reprap.htm" ] ; then
echo "core directory doesn't contain rerap.htm"
exit
fi
# Create an empty build directory
if [ -d "./build" ] ; then
rm -r ./build
fi
mkdir ./build
echo "=> Building Duet Web Control for Duet WiFi"
# Compress favicon
echo "Compressing favicon"
gzip -c ./core/favicon.ico > ./build/favicon.ico.gz
# Copy HTML files and change CSS and JS rels
echo "Changing CSS and JS paths"
cp ./core/reprap.htm ./build/reprap.htm
cp ./core/html404.htm ./build/html404.htm
sed -i "/<link href/d" ./build/reprap.htm
sed -i "/<script src/d" ./build/reprap.htm
sed -i "/<!-- CSS/a <link href=\"css/dwc.css\" rel=\"stylesheet\">" ./build/reprap.htm
sed -i "/<!-- Placed/a <script src=\"js/dwc.js\"></script>" ./build/reprap.htm
# Compress HTML files
#echo "Compressing HTML files"
#gzip -c ./build/reprap.htm > ./build/reprap.htm.gz
#gzip -c ./build/html404.htm > ./build/html404.htm.gz
#rm ./build/reprap.htm
#rm ./build/html404.htm
# Compress XML files
echo "Compressing XML files"
gzip -c ./core/language.xml > ./build/language.xml.gz
# Minify CSS files
echo "Minifying CSS files and changing font paths"
mkdir ./build/css
yui-compressor -o ./build/css/slate.css ./core/css/slate.css
CSS_FILES=$(grep -e "\.css" ./core/reprap.htm | cut -d '"' -f 2 | sed -e 's/^/core\//')
for FILE in $CSS_FILES; do
echo "- Minifying $FILE..."
yui-compressor $FILE >> ./build/css/dwc.css
done
sed -i "s/-halflings-regular\./\./g" ./build/css/dwc.css
# Compress minified CSS files
echo "Compressing CSS files"
gzip -c ./build/css/dwc.css > ./build/css/dwc.css.gz
rm ./build/css/dwc.css
gzip -c ./build/css/slate.css > ./build/css/slate.css.gz
rm ./build/css/slate.css
# Minify JS files
echo "Minifying JS files"
mkdir ./build/js
JS_FILES=$(grep -e "\.js" ./core/reprap.htm | cut -d '"' -f 2 | sed -e 's/^/core\//' | tr '\n' ' ')
for FILE in $JS_FILES; do
echo "- Minifying $FILE..."
yui-compressor $FILE >> ./build/js/dwc.js
done
# Compress minified JS file
echo "Compressing JS file"
gzip -c ./build/js/dwc.js > ./build/js/dwc.js.gz
rm ./build/js/dwc.js
# Compress font files
echo "Compressing fonts"
mkdir ./build/fonts
gzip -c ./core/fonts/glyphicons-halflings-regular.eot > ./build/fonts/glyphicons.eot.gz
gzip -c ./core/fonts/glyphicons-halflings-regular.svg > ./build/fonts/glyphicons.svg.gz
gzip -c ./core/fonts/glyphicons-halflings-regular.ttf > ./build/fonts/glyphicons.ttf.gz
gzip -c ./core/fonts/glyphicons-halflings-regular.woff > ./build/fonts/glyphicons.woff.gz
gzip -c ./core/fonts/glyphicons-halflings-regular.woff2 > ./build/fonts/glyphicons.woff2.gz
gzip -c ./core/fonts/Homenaje-Regular.ttf > ./build/fonts/Homenaje-Regular.ttf.gz
# Create SPIFFS image for DuetWiFi
echo "Creating SPIFFS image for Duet WiFi"
mkspiffs -c ./build -b 8192 -p 256 -s 3125248 ./DuetWebControl-$VERSION.bin
# Now build DWC for first-gen Duets
echo "=> Building Duet Web Control for first-gen Duets"
rm -r ./build/*
# Copy target files
echo "Moving JavaScript files in place"
cp -r ./core/* ./build/
mv ./build/js/3rd-party/* ./build/js
rmdir ./build/js/3rd-party
echo "Fixing JavaScript file paths"
sed -i "s/js\/3rd-party/js/" ./build/reprap.htm
# create final ZIP file for first-gen Duets
echo "Creating final DuetWebControl.zip"
# TODO: Pack build directory instead of core once compression support has been added to RRF-Duet
cd ./build
zip -r -o ../DuetWebControl-$VERSION.zip ./*
cd ..
# clean up again
rm -r ./build
echo "Done"