Created
April 1, 2014 22:15
-
-
Save basejump/9924224 to your computer and use it in GitHub Desktop.
This file contains 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
//import org.grails.plugins.coffee.compiler.CoffeeCompilerManager | |
import grails.util.GrailsUtil | |
import grails.util.Environment | |
printMessage = { String message -> event('StatusUpdate', [message]) } | |
errorMessage = { String message -> event('StatusError', [message]) } | |
configSlurp = { -> new ConfigSlurper(GrailsUtil.environment).parse(new File("./grails-app/conf/Config.groovy").toURL())} | |
eventCleanStart = { | |
def config = configSlurp() | |
println "deleting ${config."coffeescript-compiler".appSource.jsOutputPath} with compiled coffee files" | |
//printMessage "deleting is ${config."coffeescript-compiler".appSource.jsOutputPath}" | |
ant.delete('dir':config."coffeescript-compiler".appSource.jsOutputPath) | |
} | |
eventCompileEnd = { kind -> | |
println "coffeescript-compiler compiling...." | |
def config = configSlurp() | |
//hack to work around the CoffeeCompiler needing the Holder.grailsApplication.classLoader | |
def ga = [getClassLoader:{-> classLoader}] as org.codehaus.groovy.grails.commons.GrailsApplication | |
grails.util.Holders.setGrailsApplication(ga) | |
def coffeeCompilerManager = classLoader.loadClass("org.grails.plugins.coffee.compiler.CoffeeCompilerManager").newInstance() | |
//println "got ${coffeeCompilerManager} " | |
def csconfig = config."coffeescript-compiler".pluginConfig | |
//println "got coffeescript-compiler config ${csconfig}" | |
coffeeCompilerManager.minifyJS = getMinifyJSFlag( csconfig ) | |
coffeeCompilerManager.minifyJS = false | |
coffeeCompilerManager.purgeJS = csconfig.containsKey( "purgeJS" ) ? csconfig.purgeJS as Boolean : false | |
coffeeCompilerManager.wrapJS = ( csconfig.containsKey( "wrapJS" ) ) ? csconfig.wrapJS as Boolean : true | |
coffeeCompilerManager.overrideJS = ( csconfig.containsKey( "overrideJS" ) ) ? csconfig.overrideJS as Boolean : true | |
coffeeCompilerManager.forceRhino = ( csconfig.containsKey( "forceRhino" ) ) ? csconfig.forceRhino as Boolean : false | |
coffeeCompilerManager.compileFromConfig( config ) | |
println "coffeescript-compiler finished" | |
} | |
/** | |
* Will only minifyJS in configured environments or production of config is left out. | |
* @param config The application config | |
* @return Boolean if current environment matches one in the config | |
*/ | |
getMinifyJSFlag = { csconfig -> | |
csconfig?.containsKey( "minifyInEnvironment" ) ? | |
csconfig.minifyInEnvironment.intersect( [ Environment.current, Environment.current.toString() ] ).size() > 0 : | |
Environment.current == Environment.PRODUCTION | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment