-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·65 lines (53 loc) · 1.9 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
#!/bin/bash
MAIN_FILE_NAME="index"
SRC_FOLDER="src"
DIST_FOLDER="dist"
JS_LIBS_FOLDER="libs"
ASSETS_FOLDER="assets"
SCRIPTS_FOLDER="$ASSETS_FOLDER/js"
STYLES_FOLDER="$ASSETS_FOLDER/css"
IMAGES_FOLDER="$ASSETS_FOLDER/images"
DOCUMENTS_FOLDER="$ASSETS_FOLDER/documents"
MANIFEST="manifest.json"
SERVICE_WORKER="service-worker.js"
NOJEKYLL=".nojekyll"
CNAME="CNAME"
VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo "Cleaning up..."
rm -rf $DIST_FOLDER/
mkdir -p $DIST_FOLDER/$SCRIPTS_FOLDER
mkdir -p $DIST_FOLDER/$STYLES_FOLDER
mkdir -p $DIST_FOLDER/$IMAGES_FOLDER
echo "Building..."
# Minify HTML
./node_modules/.bin/html-minifier --collapse-whitespace --remove-comments $SRC_FOLDER/$MAIN_FILE_NAME.html -o $DIST_FOLDER/$MAIN_FILE_NAME.html
# Minify CSS files
for file in $(ls $SRC_FOLDER/$STYLES_FOLDER)
do
npx postcss $SRC_FOLDER/$STYLES_FOLDER/$file > $DIST_FOLDER/$STYLES_FOLDER/$file
done
# Minify JS files (excluded libs folder)
for file in $(ls -p $SRC_FOLDER/$SCRIPTS_FOLDER | grep -v $JS_LIBS_FOLDER)
do
./node_modules/.bin/uglifyjs --compress --mangle -o $DIST_FOLDER/$SCRIPTS_FOLDER/$file -- $SRC_FOLDER/$SCRIPTS_FOLDER/$file
done
# Copy JS libs folder content
cp -a $SRC_FOLDER/$SCRIPTS_FOLDER/$JS_LIBS_FOLDER/. $DIST_FOLDER/$SCRIPTS_FOLDER/$JS_LIBS_FOLDER/
# Copy images
cp -a $SRC_FOLDER/$IMAGES_FOLDER/. $DIST_FOLDER/$IMAGES_FOLDER/
rm $DIST_FOLDER/$IMAGES_FOLDER/*.svg
# Copy documents folder content
cp -a $SRC_FOLDER/$DOCUMENTS_FOLDER/. $DIST_FOLDER/$DOCUMENTS_FOLDER/
# Copy other files
cp $SRC_FOLDER/$MANIFEST $DIST_FOLDER/$MANIFEST
cp $SRC_FOLDER/$SERVICE_WORKER $DIST_FOLDER/$SERVICE_WORKER
cp $NOJEKYLL $DIST_FOLDER/$NOJEKYLL
cp $CNAME $DIST_FOLDER/$CNAME
# Bump service worker version
sed -i.bak "s/VERSION/$VERSION/g" $DIST_FOLDER/$SERVICE_WORKER && rm $DIST_FOLDER/$SERVICE_WORKER.bak
echo "Build complete!"