-
-
Save alexo/5347352 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment