WordPress.org

Make WordPress Core

Ticket #29797: css-check

File css-check, 1.0 KB (added by x2048, 5 years ago)

A shell script to check if an SCSS file compiles to an identical CSS file. Usage: While in a directory that contains file.css and file.scss, call "css-check file"

Line 
1#!/bin/sh
2
3if [ "$#" -ne 1 ]; then
4  echo "WordPress Sass checker"
5  echo "======================"
6  echo ""
7  echo "Usage: css-check filename"
8  echo "Compiles filename.scss and checks if its contents are equivalent to filename.css"
9  echo "Checks out filename.css from git"
10  exit
11fi
12
13FILENAME=$1
14FILENAME="${FILENAME%.*}"
15
16CSS_FILE=$FILENAME.css
17SCSS_FILE=$FILENAME.scss
18COMPILED_SCSS_FILE=/tmp/$FILENAME-compiled.css
19CLEAN_CSS_FILE=/tmp/$FILENAME-clean.css
20CLEAN_COMPILED_SCSS_FILE=/tmp/$FILENAME-clean-scss.css
21
22if [ ! -f $CSS_FILE ]; then
23  echo "CSS file does not exist."
24  exit
25fi
26
27if [ ! -f $SCSS_FILE ]; then
28  echo "SCSS file does not exist."
29  exit
30fi
31
32git checkout $CSS_FILE 2> /dev/null
33node-sass $SCSS_FILE $COMPILED_SCSS_FILE 2> /dev/null
34
35csstidy $CSS_FILE --silent=true --template=low > $CLEAN_CSS_FILE
36csstidy $COMPILED_SCSS_FILE --silent=true --template=low > $CLEAN_COMPILED_SCSS_FILE
37
38echo "Differences between the compiled $SCSS_FILE and $CSS_FILE"
39diff $CLEAN_CSS_FILE $CLEAN_COMPILED_SCSS_FILE --report-identical-files
40