Name: | pack-styles |
Version: | 1.0 |
Released: | February 5th, 2011 |
Licence: | Free to use without restriction. |
Description
This script will minify all CSS and Javascript files in a specified directory
that have the extension .in.css
or .in.js
, and will output them as .css
or .js
files.
Requires yui-compressor (install using sudo apt-get install yui-compressor
).
For example: pack-styles public_html
will minify all *.in.css and
*.in.js files in the public_html directory.
Usage
Call pack-styles
with an optional directory argument. If no
directory argument is supplied, it will scan the current directory and its
subdirectories.
Code
#!/bin/bash echo "Processing Files" fileNameList=$(find $1 -name "*.in.*s") beforeSize=0 afterSize=0 # Convert to array i=0; for f in $fileNameList; do fileNames[$i]="$f" ((i++)) done for inputFile in "${fileNames[@]}" do outputFile=${inputFile/.in./.} beforeSize=$((beforeSize+$(stat -c%s "$inputFile"))) echo " o $inputFile" yui-compressor -o $outputFile $inputFile --charset utf-8 afterSize=$((afterSize+$(stat -c%s "$outputFile"))) done echo "Size Before: $beforeSize" echo "Size After : $afterSize"