Created
June 29, 2012 16:41
-
-
Save hlship/3019081 to your computer and use it in GitHub Desktop.
CompileCoffeeScript task for Gradle
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 ro.isdc.wro.model.resource.* | |
import ro.isdc.wro.extensions.processor.js.* | |
buildscript { | |
repositories { mavenCentral() } | |
dependencies { | |
classpath "ro.isdc.wro4j:wro4j-extensions:${versions.wro4j}" | |
} | |
} | |
class CompileCoffeeScript extends DefaultTask { | |
def srcDir = "src/main/coffeescript" | |
def outputDir = "${project.buildDir}/compiled-coffeescript" | |
@InputDirectory | |
File getSrcDir() { project.file(srcDir) } | |
@OutputDirectory | |
File getOutputDir() { project.file(outputDir) } | |
@TaskAction | |
void doCompile() { | |
logger.info "Compiling CoffeeScript sources from $srcDir into $outputDir" | |
def outputDirFile = getOutputDir() | |
// Recursively delete output directory if it exists | |
outputDirFile.deleteDir() | |
def tree = project.fileTree srcDir, { | |
include '**/*.coffee' | |
} | |
tree.visit { visit -> | |
if (visit.directory) return | |
def inputFile = visit.file | |
def inputPath = visit.path | |
def outputPath = inputPath.replaceAll(/\.coffee$/, '.js') | |
def outputFile = new File(outputDirFile, outputPath) | |
logger.info "Compiling ${inputPath}" | |
outputFile.parentFile.mkdirs() | |
def resource = Resource.create(inputFile.absolutePath, ResourceType.JS) | |
new CoffeeScriptProcessor().process(resource, inputFile.newReader(), outputFile.newWriter()) | |
} | |
} | |
} | |
project.ext.CompileCoffeeScript = CompileCoffeeScript |
I'll give that a try ... I don't have enough .coffee files to compile that I'll be able to tell the difference, I suspect.
The processor itself uses a pool to reuse rhino instance. The idea was to make rhino perform faster. Here is a wiki page describing it: http://code.google.com/p/wro4j/wiki/RhinoPerformanceImprovement
No appreciable difference; maybe once I have a few dozen source files to
compile it will be worthwhile. I committed the change anyway as it doesn't
hurt.
On Fri, Jun 29, 2012 at 1:41 PM, Alex Objelean < ***@***.*** > wrote:
The processor itself uses a pool to reuse rhino instance. The idea was to
make rhino perform faster. Here is a wiki page describing it:
http://code.google.com/p/wro4j/wiki/RhinoPerformanceImprovement
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/3019081
##
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can improve the script performance by reusing CoffeeScriptProcessor instance across all resource processing. I've tried to add a comment to tapestry central, but posting a comment there is not quite user-friendly.