Skip to content

Commit

Permalink
Use only container for CSS and JS updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
awinterstein committed Jan 4, 2025
1 parent b4195a7 commit debe2c9
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions update-css.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,12 @@
# get the directory in which this script is located (the theme source dir)
SOURCE_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

TAILWINDCSS_COMMAND="tailwindcss -i src/css/main.css -o static/css/main.css --minify"
UGLIFYJS_COMMAND="uglifyjs"

# call the tailwindcss cli executable, if it can be found in the path
if command -v tailwindcss >/dev/null; then
pushd "${SOURCE_DIR}" >/dev/null
${TAILWINDCSS_COMMAND}
popd >/dev/null

# alternatively use docker to create and run a container and execute tailwinds cli from there
elif command -v docker >/dev/null; then

# create the container for zola builds and tailwindcss updates
docker build -t develop-zola-tailwindcss "${SOURCE_DIR}" || exit 2

# update the CSS file using tailwindcss
docker run --user $UID:$(id -g) --mount type=bind,source=${SOURCE_DIR},target=/source -w /source develop-zola-tailwindcss \
sh -c "uglifyjs ./src/js/main.js --compress --mangle -o ./static/js/main.js &&
uglifyjs ./src/js/page.js --compress --mangle -o ./static/js/page.js &&
uglifyjs ./src/js/search.js --compress --mangle -o ./static/js/search.js &&
${TAILWINDCSS_COMMAND}" || exit 3


# print an error message if neither tailwindcss nor the docker executable could be found
else
echo "Need either 'tailwindcss' or 'docker' executable in the path." >&2
exit 1
fi
# create the container for zola builds and tailwindcss updates
docker build -t develop-zola-tailwindcss "${SOURCE_DIR}" || exit 2

# update the CSS file using tailwindcss and the JavaScript files using uglifyjs
docker run -v ${SOURCE_DIR}:/source:Z -w /source develop-zola-tailwindcss \
sh -c "uglifyjs ./src/js/main.js --compress --mangle -o ./static/js/main.js &&
uglifyjs ./src/js/page.js --compress --mangle -o ./static/js/page.js &&
uglifyjs ./src/js/search.js --compress --mangle -o ./static/js/search.js &&
tailwindcss -i src/css/main.css -o static/css/main.css --minify" || exit 3

0 comments on commit debe2c9

Please sign in to comment.