Skip to content

Commit

Permalink
Adding Userstyles and mac concatenate
Browse files Browse the repository at this point in the history
  • Loading branch information
Woedenaz committed Mar 12, 2019
1 parent 15a7ee3 commit eeeec95
Show file tree
Hide file tree
Showing 3 changed files with 4,648 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.swp

*.bak
temp.css-e
97 changes: 97 additions & 0 deletions concatenate-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# concatenate.sh
#
# For generating concatenated, minified, stable versions of nu-SCP.
#
# Requires: yui-compressor, java
#
# 1. Takes all CSS files from /styles
# 2. Concatenates them
# 3. Saves this file to /stable/styles as nuscp.css
# 4. Minifies the file and saves it to /stable/styles as nuscp.min.css


# Define an error-handling function
# Parameters:
# 1. Description of error
error() {
echo $1 1>&2
echo "Aborting"
# Delete temp.css, if present
rm temp.css
exit
}

# First let's confirm that we're in /Nu-SCP

echo "Validating directory..."
if [ "${PWD##*/}" != "Nu-SCP" ]; then
error "Script must be executed from nuscp root directory"
fi

# Take main.css and copy to a temp file
echo "Duplicating main.css..."
cp styles/main.css temp.css

# Scrap the @import rules
echo "Removing @imports..."
sed -i ".bak" "/^@import.*\.css.*$/d" temp.css || error "@import removal failed"

# Append this file to root.css
echo "Prepending root.css..."
cat styles/root.css temp.css > temp && mv temp temp.css

# Then we concat all files *except* main.css,root.css
echo "Concatenating CSS..."
shopt -s extglob || error "Unable to extend pattern matching"
cat styles/!(main|root|normalize|overwrite-main).css >> temp.css

# Wrap the whole thing in @supports for IE
echo "Supporting IE..."
sed -i '1 s/^/@supports(--css: variables) {\n/' temp.css
echo "}" >> temp.css
# Extract any imports rules to the top of the file
grep '^@import' temp.css > temp
grep -v '^@import' temp.css >> temp
mv temp temp.css

# Move temp.css
echo "Created nuscp.css"
cp temp.css stable/styles/nuscp.css

# Extract inline images to array
IFS='>'
IMAGES=($(awk -F '>' '/data:image/ && match($0,/\".*\"/){val=val?val ">" substr($0,RSTART+1,RLENGTH-2):substr($0,RSTART+1,RLENGTH-2)} END{print val}' temp.css))
echo "Found ${#IMAGES[@]} images to extract"
echo "Extracting images..."
count=0
for i in "${IMAGES[@]}"; do
#echo "IMAGES[$count]=$i"
sed -i -e "s>$i>!!MARKER$count>g" temp.css || error "Bad sed"
count=$((count + 1))
done

# Minify
echo "Compressing..."
yuicompressor --type css -o temp.css temp.css

# Correct compression errors
# "-(" -> "- ("
sed -i -e "s/-(/- (/g" temp.css
# "or(" -> "or ("
sed -i -e "s/or(/or (/g" temp.css
# "Xrem+Yrem" -> "Xrem + Yrem"
sed -i -E "s/([\)mh])(\+)([\(0-9v])/\1 + \3/g" temp.css

# Reinsert extracted images
echo "Reinserting extracted images..."
count=0
for i in "${IMAGES[@]}"; do
sed -i -E "s>!!MARKER$count>$i>g" temp.css
count=$((count + 1))
done

# Move the minified file to final destination
mv temp.css stable/styles/nuscp.min.css
echo "Created nuscp.min.css"

echo "Done."
Loading

0 comments on commit eeeec95

Please sign in to comment.