Template
1
0
Fork 0
goth.stack/lib/stylegen/gen.sh

136 lines
3 KiB
Bash
Raw Normal View History

2025-01-04 21:24:45 -07:00
# Define the version of the binary to download
VERSION="v1.7.27"
2024-05-07 18:03:54 -06:00
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-e|--extensions)
EXTENSIONS="$2"
shift; shift
;;
-d|--directory)
DIRECTORY="$2"
shift; shift
;;
-o|--output-dir)
OUTPUT_DIR="$2"
shift; shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
2023-05-18 20:04:55 -06:00
2024-12-18 23:21:12 -06:00
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Script directory: $SCRIPT_DIR"
2023-05-18 20:04:55 -06:00
OS=$(uname -s)
ARCH=$(uname -m)
# Normalize OS and ARCH identifiers
case $OS in
"Darwin")
OS="macos"
;;
"Linux")
OS="linux"
;;
"CYGWIN"*|"MINGW"*|"MSYS"*)
OS="windows"
;;
*)
echo "Unknown operating system: $OS"
exit 1
;;
esac
2024-04-17 18:37:39 -06:00
case $ARCH in
"x86_64")
ARCH="x64"
;;
2024-12-18 23:21:12 -06:00
"arm64"|"aarch64")
2024-04-17 18:37:39 -06:00
ARCH="arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
2024-12-18 23:21:12 -06:00
echo "Detected OS: $OS"
echo "Detected Architecture: $ARCH"
2025-01-04 21:24:45 -07:00
# Function to construct the binary download URL based on version, OS, and architecture
get_binary_url() {
echo "https://github.com/dobicinaitis/tailwind-cli-extra/releases/download/$VERSION/tailwindcss-extra-$OS-$ARCH"
}
# Create the 'tw' directory for storing the downloaded binary
TW_DIR="${SCRIPT_DIR}/tw"
mkdir -p "$TW_DIR"
2023-05-18 20:04:55 -06:00
2025-01-04 21:24:45 -07:00
# Set the binary path
BINARY="${TW_DIR}/tailwindcss-extra-${OS}-${ARCH}"
2024-05-07 18:03:54 -06:00
2025-01-04 21:24:45 -07:00
# Check if the binary is already downloaded, otherwise download it
2024-12-18 23:21:12 -06:00
if [ ! -f "$BINARY" ]; then
2025-01-04 21:24:45 -07:00
echo "Binary not found, downloading version $VERSION..."
DOWNLOAD_URL=$(get_binary_url)
if [ -z "$DOWNLOAD_URL" ]; then
echo "No suitable release found for this OS and architecture."
2024-05-07 18:03:54 -06:00
exit 1
2025-01-04 21:24:45 -07:00
fi
# Download the binary
curl -L "$DOWNLOAD_URL" -o "$BINARY"
echo "Downloaded binary to: $BINARY"
2024-05-07 18:03:54 -06:00
fi
2025-01-04 21:24:45 -07:00
# Make the binary executable
2024-12-18 23:21:12 -06:00
chmod +x "$BINARY"
echo "Using binary: $BINARY"
echo "Extensions: $EXTENSIONS"
echo "Directory: $DIRECTORY"
echo "Output Directory: $OUTPUT_DIR"
2024-05-07 18:03:54 -06:00
# Initialize an array for name conditions
name_conditions=()
# Assuming $EXTENSIONS is a comma-separated list of extensions
IFS=',' read -ra ADDR <<< "$EXTENSIONS"
for ext in "${ADDR[@]}"; do
name_conditions+=(-name "*.$ext")
2023-05-18 20:04:55 -06:00
done
2024-05-07 18:03:54 -06:00
# Use find with the array of conditions
INCLUDE_FILES=$(find "$DIRECTORY" -type f \( "${name_conditions[@]}" \))
echo "Files found: $INCLUDE_FILES"
INCLUDE_FILES_ARRAY=$(echo "$INCLUDE_FILES" | awk '{printf "\"%s\",", $0}' | sed 's/,$//')
2024-12-18 23:21:12 -06:00
# Generate Tailwind config in script directory
CONFIG_FILE="${SCRIPT_DIR}/tailwind.config.js"
2024-05-07 18:03:54 -06:00
echo "module.exports = {
content: [$INCLUDE_FILES_ARRAY],
theme: {
extend: {},
},
daisyui: {
themes: [\"night\"],
},
plugins: [require('daisyui'), require('@tailwindcss/typography')],
2024-12-18 23:21:12 -06:00
}" > "$CONFIG_FILE"
2024-08-06 14:37:44 -06:00
2024-05-07 18:03:54 -06:00
# Run the binary with the generated config
2024-12-18 23:21:12 -06:00
"$BINARY" build -i "${SCRIPT_DIR}/base.css" -c "$CONFIG_FILE" -o "${OUTPUT_DIR}/styles.css" --minify
2024-05-07 18:03:54 -06:00
2023-05-18 20:04:55 -06:00
# Wait for all background processes to finish
2024-12-18 23:21:12 -06:00
wait