2017-11-06 14:02:51 +00:00
|
|
|
#!/bin/bash
|
2017-10-20 14:30:04 +00:00
|
|
|
|
2021-03-29 05:50:31 +00:00
|
|
|
# Loads user-defined variables at build-config file
|
2017-11-06 14:02:51 +00:00
|
|
|
source build-config.cfg
|
2017-10-20 14:30:04 +00:00
|
|
|
|
2017-12-04 18:34:47 +00:00
|
|
|
## Only run npm build if there was a change in a .js or .vue file
|
2018-01-29 17:24:51 +00:00
|
|
|
current_md5_js=$(<last-js-build.md5)
|
|
|
|
current_md5_sass=$(<last-sass-build.md5)
|
|
|
|
current_md5_composer=$(<last-composer-build.md5)
|
|
|
|
current_md5_package=$(<last-package-build.md5)
|
|
|
|
|
2018-01-22 11:48:51 +00:00
|
|
|
current_OS=`uname`
|
|
|
|
|
|
|
|
# For macOS (Darwin)
|
|
|
|
if [ $current_OS == "Darwin" ]; then
|
2020-11-19 19:22:43 +00:00
|
|
|
find src *.js -type f \( -name "*.js" -or -name "*.vue" -or -name "webpack.common.js" -or -name "webpack.dev.js" -or -name "webpack.prod.js" \) -exec md5 {} \; | sort -k 2 | md5 > last-js-build.md5
|
2021-10-05 21:00:59 +00:00
|
|
|
find ./src/views/admin/scss/ ./src/views/gutenberg-blocks/ ./src/views/gutenberg-blocks/blocks/collections-list ./src/views/gutenberg-blocks/blocks/facets-list ./src/views/gutenberg-blocks/blocks/dynamic-items-list ./src/views/gutenberg-blocks/blocks/items-list ./src/views/gutenberg-blocks/blocks/terms-list -type f \( -name "*.scss" \) -exec md5 {} \; | sort -k 2 | md5 > last-sass-build.md5
|
2018-03-28 18:21:13 +00:00
|
|
|
find ./composer.json -type f \( -name "composer.json" \) -exec md5 {} \; | sort -k 2 | md5 > last-composer-build.md5
|
|
|
|
find ./package.json -type f \( -name "package.json" -or -name "package-lock.json" \) -exec md5 {} \; | sort -k 2 | md5 > last-package-build.md5
|
2018-01-22 11:48:51 +00:00
|
|
|
else
|
2020-11-19 19:22:43 +00:00
|
|
|
find src *.js -type f \( -name "*.js" -or -name "*.vue" -or -name "webpack.common.js" -or -name "webpack.dev.js" -or -name "webpack.prod.js" \) -exec md5sum {} \; | sort -k 2 | md5sum > last-js-build.md5
|
2021-10-05 21:00:59 +00:00
|
|
|
find ./src/views/admin/scss/ ./src/views/gutenberg-blocks ./src/views/gutenberg-blocks/blocks/collections-list ./src/views/gutenberg-blocks/blocks/facets-list ./src/views/gutenberg-blocks/blocks/dynamic-items-list ./src/views/gutenberg-blocks/blocks/items-list ./src/views/gutenberg-blocks/blocks/terms-list -type f \( -name "*.scss" \) -exec md5sum {} \; | sort -k 2 | md5sum > last-sass-build.md5
|
2018-03-28 18:21:13 +00:00
|
|
|
find ./composer.json -type f \( -name "composer.json" \) -exec md5sum {} \; | sort -k 2 | md5sum > last-composer-build.md5
|
|
|
|
find ./package.json -type f \( -name "package.json" -or -name "package-lock.json" \) -exec md5sum {} \; | sort -k 2 | md5sum > last-package-build.md5
|
2018-01-22 11:48:51 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-29 17:33:52 +00:00
|
|
|
new_md5_package=$(<last-package-build.md5)
|
|
|
|
if [ "$current_md5_package" != "$new_md5_package" ]
|
2017-12-04 18:34:47 +00:00
|
|
|
then
|
2018-01-29 18:29:28 +00:00
|
|
|
## Install js dependencies
|
2019-06-19 09:12:54 +00:00
|
|
|
npm ci
|
2018-01-29 17:33:52 +00:00
|
|
|
fi
|
|
|
|
|
2021-12-07 18:10:11 +00:00
|
|
|
is_prod_build=false
|
|
|
|
for i in "$@"
|
|
|
|
do
|
|
|
|
case $i in
|
|
|
|
--prod)
|
|
|
|
is_prod_build=true
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-01-29 17:33:52 +00:00
|
|
|
new_md5_composer=$(<last-composer-build.md5)
|
|
|
|
if [ "$current_md5_composer" != "$new_md5_composer" ]
|
|
|
|
then
|
|
|
|
## Install composer dependencies
|
2021-12-07 18:10:11 +00:00
|
|
|
if [ "$is_prod_build" == false ]
|
|
|
|
then
|
|
|
|
composer install
|
|
|
|
else
|
2021-12-07 19:10:19 +00:00
|
|
|
composer install --no-dev
|
2021-12-07 18:10:11 +00:00
|
|
|
fi
|
2018-01-29 17:24:51 +00:00
|
|
|
fi
|
2018-01-29 16:42:59 +00:00
|
|
|
|
2018-01-29 17:24:51 +00:00
|
|
|
new_md5_sass=$(<last-sass-build.md5)
|
|
|
|
if [ "$current_md5_sass" != "$new_md5_sass" ]
|
|
|
|
then
|
2018-01-29 16:42:59 +00:00
|
|
|
## Compile SASS
|
|
|
|
sh compile-sass.sh
|
2017-12-04 18:34:47 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-29 17:33:52 +00:00
|
|
|
new_md5_js=$(<last-js-build.md5)
|
2020-11-19 19:22:43 +00:00
|
|
|
|
2018-01-29 17:33:52 +00:00
|
|
|
if [ "$current_md5_js" != "$new_md5_js" ]
|
2018-01-29 17:24:51 +00:00
|
|
|
then
|
2020-11-19 19:22:43 +00:00
|
|
|
if [ "$is_prod_build" == false ]
|
|
|
|
then
|
2020-11-20 13:37:54 +00:00
|
|
|
echo "$(tput setab 2) $(tput sgr 0) $(tput setab 2) $(tput sgr 0) Building in development mode $(tput setab 2) $(tput sgr 0) $(tput setab 2) $(tput sgr 0)"
|
2020-11-19 19:22:43 +00:00
|
|
|
npm run build
|
2021-12-07 18:10:11 +00:00
|
|
|
else
|
|
|
|
echo "$(tput setab 4) $(tput sgr 0) $(tput setab 4) $(tput sgr 0) Building in production mode $(tput setab 4) $(tput sgr 0) $(tput setab 4) $(tput sgr 0)"
|
|
|
|
npm run build-prod
|
2020-11-19 19:22:43 +00:00
|
|
|
fi
|
2018-01-29 17:24:51 +00:00
|
|
|
fi
|
|
|
|
|
2018-04-17 17:01:25 +00:00
|
|
|
## Fetch PDF.js
|
2020-01-17 18:02:11 +00:00
|
|
|
## Commented as we have a modified version of its code.
|
|
|
|
# if [ ! -d "src/pdf-viewer/pdfjs-dist" ]; then
|
|
|
|
# echo "Fething PDF.js"
|
|
|
|
# mkdir -p src/pdf-viewer/pdfjs-dist
|
|
|
|
# wget https://github.com/mozilla/pdf.js/releases/download/v1.9.426/pdfjs-1.9.426-dist.zip
|
|
|
|
# unzip pdfjs-1.9.426-dist.zip -d src/pdf-viewer/pdfjs-dist/
|
|
|
|
# rm pdfjs-1.9.426-dist.zip
|
|
|
|
# fi
|
2018-04-17 17:01:25 +00:00
|
|
|
|
2018-03-05 19:47:45 +00:00
|
|
|
echo "Updating files in $wp_plugin_dir"
|
2018-05-23 14:17:14 +00:00
|
|
|
|
2018-03-05 19:47:45 +00:00
|
|
|
rm -rf $wp_plugin_dir
|
2018-05-23 14:17:14 +00:00
|
|
|
|
2018-03-05 19:47:45 +00:00
|
|
|
mkdir $wp_plugin_dir
|
2018-05-23 14:17:14 +00:00
|
|
|
|
2018-05-28 13:29:36 +00:00
|
|
|
rsync -axz --exclude='vendor/bin/phpc*' --exclude='vendor/squizlabs' --exclude='vendor/wimg' \
|
2019-06-19 09:12:54 +00:00
|
|
|
--exclude='vendor/respect/validation/.git' --exclude='vendor/symfony/polyfill-mbstring/.git' \
|
|
|
|
--exclude='vendor/respect/validation/docs' --exclude='vendor/respect/validation/tests' \
|
|
|
|
--exclude='pdf-viewer/pdfjs-dist/web/compressed.tracemonkey-pldi-09.pdf' \
|
2019-09-20 13:07:07 +00:00
|
|
|
--exclude='vendor/tecnickcom/tcpdf/fonts' \
|
2019-10-11 18:13:25 +00:00
|
|
|
--exclude='vendor/smalot/pdfparser/src/Smalot/PdfParser/Tests/' \
|
2019-10-29 17:10:30 +00:00
|
|
|
--exclude='vendor/tecnickcom/tcpdf/examples' \
|
2018-05-28 13:29:36 +00:00
|
|
|
src/* $wp_plugin_dir/
|
2018-05-23 14:17:14 +00:00
|
|
|
|
2020-11-20 13:37:54 +00:00
|
|
|
echo "Removing unecessary source files"
|
2018-03-05 19:47:45 +00:00
|
|
|
rm -rf $wp_plugin_dir/scss
|
2020-11-17 12:31:37 +00:00
|
|
|
find $wp_plugin_dir/views/ -type f -name '*.vue' -exec rm {} +
|
|
|
|
find $wp_plugin_dir/views/ -type f -name '*.scss' -exec rm {} +
|
|
|
|
find $wp_plugin_dir/views/ -type f -name '*.sass' -exec rm {} +
|
|
|
|
find $wp_plugin_dir/views/ -type f -name '*.js' ! -path "${wp_plugin_dir}/views/libs/*" -exec rm {} +
|
|
|
|
find $wp_plugin_dir/views/ -type d -empty -delete
|
2018-03-01 20:41:28 +00:00
|
|
|
|
2020-11-20 13:37:54 +00:00
|
|
|
if [ "$is_prod_build" == true ]
|
|
|
|
then
|
|
|
|
find $wp_plugin_dir/assets/js/ -type f -name '*.js.map' -exec rm {} +
|
|
|
|
fi
|
|
|
|
|
2018-03-01 20:41:28 +00:00
|
|
|
echo "Build complete!"
|