From 3c56b93d1f93f0e29fa66f9cc9823b0780fdf062 Mon Sep 17 00:00:00 2001 From: ehab Date: Sun, 25 May 2025 23:03:05 +0300 Subject: [PATCH] add last version of tailwind --- build.sh | 58 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/build.sh b/build.sh index 2910b18..68441f3 100755 --- a/build.sh +++ b/build.sh @@ -1,20 +1,13 @@ +#!/bin/bash + echo "Starting build..." SOURCE=${BASH_SOURCE[0]} DIR_OF_THIS_SCRIPT="$( dirname "$SOURCE" )" ABS_DIR_OF_SCRIPT="$( realpath $DIR_OF_THIS_SCRIPT )" -# TODO: Check if current version is latest to avoid redundant installation -if [[ -f "tailwindcss" ]] -then - rm tailwindcss -fi - -# checks os and architecture for correct release -# https://stackoverflow.com/a/8597411 -echo "Installing & building tailwind..." +# Determine platform ASSET="tailwindcss" - if [[ "$OSTYPE" == "linux-gnu"* ]]; then ASSET="$ASSET-linux" elif [[ "$OSTYPE" == "darwin"* ]]; then @@ -26,21 +19,38 @@ elif [[ "$(uname -m)" == "arm64"* ]]; then ASSET="$ASSET-arm64" fi -curl -sLO "https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/${ASSET}" -chmod +x $ASSET -mv $ASSET tailwindcss +# Get the latest version from GitHub +LATEST_VERSION=$(curl -s https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest | grep '"tag_name":' | cut -d '"' -f 4) - -# initialized and configures tailwind if not configured -echo "Initializing tailwind..." -if [[ ! -f "tailwind.config.js" ]] -then - ./tailwindcss init - sed -i '' "s| content: \\[\\],| content: \\['./templates/**/*.html'\\],|g" tailwind.config.js +# Get current version (if exists) +CURRENT_VERSION="" +if [[ -f "./tailwindcss" ]]; then + CURRENT_VERSION=$(./tailwindcss -v | awk '{print $2}') fi -# compiles tailwind css for prod & builds project -echo "Compiling tailwindcss and building zola project..." +echo "Current Tailwind version: $CURRENT_VERSION" +echo "Latest Tailwind version: $LATEST_VERSION" + +# Download only if outdated or not installed +if [[ "$CURRENT_VERSION" != "$LATEST_VERSION" ]]; then + echo "Updating Tailwind to latest version..." + rm -f tailwindcss + curl -sLO "https://github.com/tailwindlabs/tailwindcss/releases/download/${LATEST_VERSION}/${ASSET}" + chmod +x $ASSET + mv $ASSET tailwindcss +else + echo "Tailwind is already up to date." +fi + +# Initialize tailwind.config.js if not exists +if [[ ! -f "tailwind.config.js" ]]; then + echo "Initializing tailwind.config.js..." + ./tailwindcss init + sed -i '' "s| content: \[\],| content: \['./templates/**/*.html'\],|g" tailwind.config.js +fi + +# Build Tailwind CSS and Zola +echo "Compiling Tailwind CSS and building Zola site..." rm -rf public static/css -./tailwindcss -i css/index.css -o ./static/css/index.css --minify -zola --root $ABS_DIR_OF_SCRIPT build \ No newline at end of file +./tailwindcss -i css/index.css -o static/css/index.css --minify +zola --root "$ABS_DIR_OF_SCRIPT" build