dc09.ru-old/build.sh

101 lines
2 KiB
Bash
Raw Normal View History

2022-10-12 16:07:01 +03:00
#!/usr/bin/env bash
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
2022-10-13 12:34:50 +03:00
BOLD='\033[1m'
2022-10-12 16:07:01 +03:00
RESET='\033[0m'
minjs="dist/script.min.js"
mincss="dist/style.min.css"
minhtml="dist/index.html"
minjs_name="script.min.js"
mincss_name="style.min.css"
minhtml_name="index.html"
title() {
echo
echo -e "${BLUE}[*]${RESET} $1"
}
2022-10-13 12:34:50 +03:00
start() {
echo
echo -e "${YELLOW}[+]${RESET} ${BOLD}Building web site in:${RESET}"
echo -e "${BOLD}$PWD${RESET}"
}
2022-10-12 16:07:01 +03:00
success() {
echo
2022-10-13 12:34:50 +03:00
echo -e "${GREEN}[V]${RESET} ${BOLD}Done${RESET}"
2022-10-12 16:07:01 +03:00
echo
}
check_deps() {
which "$1" >/dev/null 2>/dev/null
if [[ $? == 1 ]]; then
echo -e "${RED}[!]${RESET} $1 is required"
echo
exit 1
fi
}
js_minify() {
order=('js/anim.js' 'js/script.js' 'js/init.js' 'js/menu.js' 'js/control.js' 'js/handlers.js')
terser -o "$minjs" ${order[*]}
}
html_minify () {
html-minifier \
--collapse-boolean-attributes \
--collapse-inline-tag-whitespace \
--collapse-whitespace \
--remove-attribute-quotes \
--remove-comments \
--remove-script-type-attributes \
--remove-style-link-type-attributes \
--use-short-doctype \
-o "$minhtml" \
"$1"
}
copy_files() {
exclude=('\.$' '\.git' 'index.html' 'styles.less' 'js' 'dist' 'build.sh' 'html_conv' 'README.md')
items="${exclude[@]}"
regex="${items//[[:space:]]/|}"
find -maxdepth 1 -exec bash -c "if [[ {} =~ $regex ]]; then :; else cp -r {} dist/; fi" \;
}
2022-10-13 12:34:50 +03:00
start
title "Creating dist/"
mkdir -p dist/
2022-10-12 16:07:01 +03:00
title "Checking dependencies"
check_deps terser
check_deps lessc
check_deps cleancss
check_deps html-minifier
check_deps python3
title "Minifying JS"
js_minify
title "Converting LESS"
lessc "styles.less" "$mincss"
title "Minifying CSS"
cleancss -o "$mincss" "$mincss"
2022-10-13 12:34:50 +03:00
title "Editing HTML"
2022-10-12 16:07:01 +03:00
cat index.html | python3 html_conv.py "$minjs_name" "$mincss_name" >"$minhtml"
2022-10-13 12:34:50 +03:00
title "Minifying HTML"
2022-10-12 16:07:01 +03:00
html_minify "$minhtml"
title "Copying other files"
copy_files
success