Last active
August 29, 2015 14:02
-
-
Save Yasushi/aeee41d6bd175f7e85ba 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
apply plugin: 'groovy' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile gradleApi() | |
compile localGroovy() | |
compile "com.theoryinpractise:coffee-maven-plugin:1.4.10" | |
} |
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 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