Skip to content

Instantly share code, notes, and snippets.

@cfmitrah
Last active March 18, 2019 05:30
Show Gist options
  • Save cfmitrah/3f75119f24e1e587d53b8bdd795beaf3 to your computer and use it in GitHub Desktop.
Save cfmitrah/3f75119f24e1e587d53b8bdd795beaf3 to your computer and use it in GitHub Desktop.
Lucee Event Gateway - Sass Compiler Listener Component
<cfcomponent>
<cffunction name="compileSASS" access="public" output="no" returntype="void">
<cfargument name="data" type="struct" required="yes">
<cftry>
<cfset fileCompile(
arguments.data.directory,
arguments.data.name,
replaceNoCase(arguments.data.name, "scss", "css", "ALL")
)>
<cfscript>
for(files in scssDirectory){
if( !listFindNoCase(".,_", left(files.name, 1)) ){
if(!directoryExists(replaceNoCase(files.directory, "sass", "css","all"))){
directoryCreate(replaceNoCase(files.directory, "sass", "css","all"));
}
}
}
</cfscript>
<cfcatch type="any">
<cflog text="change:#serialize(data)#" type="information" file="DirectoryWatcher">
</cfcatch>
</cftry>
</cffunction>
<cffunction name="fileCompile" access="private" returntype="void">
<cfargument name="basePath" type="string" required="true">
<cfargument name="inFileName" type="string" required="true">
<cfargument name="outFileName" type="string" required="true">
<cfscript>
var jars = directoryList( arguments.basePath & "/model/java/sassLib", false, "path", "*.jar" );
var compiler = createObject( "java", "io.bit3.jsass.Compiler", jars );
var file = createObject( "java", "java.io.File", jars );
var options = createObject( "java", "io.bit3.jsass.Options", jars );
var inFile = arguments.basePath & "/" & arguments.inFileName;
var outFile = arguments.basePath & "/" & arguments.outFileName;
options.setOmitSourceMapUrl(false);
options.setSourceMapContents(true);
options.setSourceComments(true);
options.setSourceMapFile(file.init(replaceNocase(outFile, ".css", "")&".map").toURI());
var compilerResult = compiler.compileFile( file.init(inFile).toURI(),
file.init(replaceNoCase(inFile,".scss",".css")).toURI(),
options );
fileWrite( outFile, compilerResult.getCss() );
fileWrite( replaceNocase(outFile, ".css", "") & ".map", compilerResult.getSourceMap());
</cfscript>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment