Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yasushi/aeee41d6bd175f7e85ba to your computer and use it in GitHub Desktop.
Save Yasushi/aeee41d6bd175f7e85ba to your computer and use it in GitHub Desktop.
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile gradleApi()
compile localGroovy()
compile "com.theoryinpractise:coffee-maven-plugin:1.4.10"
}
import com.theoryinpractise.coffeescript.CoffeeScriptCompiler
import org.gradle.api.InvalidUserDataException
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileVisitDetails
import org.gradle.internal.classloader.ClasspathUtil
import org.gradle.api.tasks.*
import org.gradle.api.logging.LogLevel
class TaliosCoffeeScriptCompiler extends SourceTask {
@OutputDirectory
File destinationDir
boolean bare = false
boolean sourceMap = true
boolean header = false
String version = "1.7.1"
@TaskAction
def compile () {
def compiler = new CoffeeScriptCompiler(version)
source.visit { FileVisitDetails fvd ->
if (fvd.isDirectory()) {
return
}
File jsFile = fvd.relativePath.replaceLastName(fvd.file.name.replaceAll('.coffee$', '.js')).getFile(destinationDir)
jsFile.parentFile.mkdirs()
File mapFile = fvd.relativePath.replaceLastName(fvd.file.name.replaceAll('.coffee$', '.js.map')).getFile(destinationDir)
logger.info("Compiling : ${fvd.name}")
def compiled = compiler.compile(fvd.file.getText("UTF-8"), fvd.file.getName(), bare, sourceMap ? CoffeeScriptCompiler.SourceMap.V3 : CoffeeScriptCompiler.SourceMap.NONE, header, false)
jsFile.write(compiled.getJs(), "UTF-8")
if (compiled.getMap() != null) {
mapFile.write(compiled.getMap(), "UTF-8")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment