Created
August 22, 2013 14:52
-
-
Save MadeByPi/6308243 to your computer and use it in GitHub Desktop.
Example Ant build task to check for SASS debug info in CSS files, and fail a build if it finds some.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project name="sass-debug-info-check" default="default" basedir="./"> | |
<taskdef resource="net/sf/antcontrib/antlib.xml"> | |
<classpath> | |
<pathelement location="${basedir}/tools/ant-contrib/ant-contrib-0.3.jar"/> | |
</classpath> | |
</taskdef> | |
<!-- Provide a css-check.properties file to override the default property settings... | |
cssDir = ${basedir}../path/to/your/built/site/files | |
cssIncludes = **/*.css | |
--> | |
<property file='${basedir}/css-check.properties'/> | |
<property name='cssDir' value='${basedir}'/> | |
<property name='cssIncludes' value='**/*.css'/> | |
<target name="default" depends="checkCSSForSASSDebugInfo"> | |
<echo>checkCSSForSASSDebugInfo - All is well, there's no naughty SASS action here!</echo> | |
</target> | |
<target name="checkCSSForSASSDebugInfo"> | |
<echo>Testing all files matching ${cssIncludes} within ${cssDir}</echo> | |
<!-- select all css files to be checked --> | |
<fileset id="cssToCheck" dir="${cssDir}" includes="${cssIncludes}"> | |
<!-- checking for occurances of the string "@media -sass-debug-info" in our css... --> | |
<contains text="@media -sass-debug-info"/> | |
</fileset> | |
<!-- convert matches to a string for logging, seperate with a newline pathsep --> | |
<pathconvert pathsep=" " property="badCSSMatches" refid="cssToCheck"/> | |
<!-- set haveBadCSS property true when badCSSMatches length > 0 --> | |
<condition property="haveBadCSS"> | |
<length string="${badCSSMatches}" trim="true" when="greater" length="0" /> | |
</condition> | |
<!-- if haveBadCSS - log the offending files and fail the build --> | |
<if> | |
<equals arg1="${haveBadCSS}" arg2="true" /> | |
<then> | |
<echo level="error">Found SASS debug info in the following files:</echo> | |
<echo level="error">${badCSSMatches}</echo> | |
<fail message="Found SASS debug info in the CSS!" /> | |
</then> | |
<else> | |
<echo>No SASS debug info found in the tested CSS files.</echo> | |
</else> | |
</if> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment