35 | sys.error(err) 36 | }, { compiled => 37 | IO.write(js, compiled) 38 | log.debug("Wrote to file %s" format js) 39 | js 40 | }) 41 | } catch { case e: Exception => 42 | throw new RuntimeException( 43 | "error occured while compiling %s with %s: %s" format( 44 | pair._1, if(iced) Iced else Vanilla, e.getMessage), e 45 | ) 46 | } 47 | 48 | private def compiled(under: File) = (under ** "*.js").get 49 | 50 | private def compileChanged( 51 | sources: File, target: File, incl: FileFilter, excl: FileFilter, 52 | bare: Boolean, charset: Charset, iced: Boolean, log: Logger) = 53 | (for (coffee <- sources.descendantsExcept(incl, excl).get; 54 | js <- javascript(sources, coffee, target) 55 | if (coffee newerThan js)) yield { 56 | (coffee, js) 57 | }) match { 58 | case Nil => 59 | log.debug("No CoffeeScripts to compile") 60 | compiled(target) 61 | case xs => 62 | log.info("Compiling %d CoffeeScripts to %s" format(xs.size, target)) 63 | xs map compileSources(bare, charset, iced, log) 64 | log.debug("Compiled %s CoffeeScripts" format xs.size) 65 | compiled(target) 66 | } 67 | 68 | private def coffeeCleanTask = 69 | (streams, resourceManaged in coffee) map { 70 | (out, target) => 71 | out.log.info("Cleaning generated JavaScript under " + target) 72 | IO.delete(target) 73 | } 74 | 75 | private def coffeeCompilerTask = 76 | (streams, sourceDirectory in coffee, resourceManaged in coffee, 77 | filter in coffee, excludeFilter in coffee, charset in coffee, bare in coffee, iced in coffee) map { 78 | (out, sourceDir, targetDir, incl, excl, charset, bare, iced) => 79 | compileChanged(sourceDir, targetDir, incl, excl, bare, charset, iced, out.log) 80 | } 81 | 82 | // move defaultExcludes to excludeFilter in unmanagedSources later 83 | private def coffeeSourcesTask = 84 | (sourceDirectory in coffee, filter in coffee, excludeFilter in coffee) map { 85 | (sourceDir, filt, excl) => 86 | sourceDir.descendantsExcept(filt, excl).get 87 | } 88 | 89 | def coffeeSettingsIn(c: Configuration): Seq[Setting[_]] = 90 | inConfig(c)(coffeeSettings0 ++ Seq( 91 | sourceDirectory in coffee <<= (sourceDirectory in c) { _ / "coffee" }, 92 | resourceManaged in coffee <<= (resourceManaged in c) { _ / "js" }, 93 | cleanFiles in coffee <<= (resourceManaged in coffee)(_ :: Nil), 94 | watchSources in coffee <<= (unmanagedSources in coffee) 95 | )) ++ Seq( 96 | cleanFiles <+= (resourceManaged in coffee in c), 97 | watchSources <++= (unmanagedSources in coffee in c), 98 | resourceGenerators in c <+= coffee in c, 99 | compile in c <<= (compile in c).dependsOn(coffee in c) 100 | ) 101 | 102 | def coffeeSettings: Seq[Setting[_]] = 103 | coffeeSettingsIn(Compile) ++ coffeeSettingsIn(Test) 104 | 105 | def coffeeSettings0: Seq[Setting[_]] = Seq( 106 | bare in coffee := false, 107 | iced in coffee := false, 108 | charset in coffee := Charset.forName("utf-8"), 109 | filter in coffee <<= (iced in coffee)((iced) => if(iced) "*.coffee" || "*.iced" else "*.coffee"), 110 | // change to (excludeFilter in Global) when dropping support of sbt 0.10.* 111 | excludeFilter in coffee := (".*" - ".") || HiddenFileFilter, 112 | unmanagedSources in coffee <<= coffeeSourcesTask, 113 | clean in coffee <<= coffeeCleanTask, 114 | coffee <<= coffeeCompilerTask 115 | ) 116 | } 117 | -------------------------------------------------------------------------------- /src/main/scala/compiler.scala: -------------------------------------------------------------------------------- 1 | package coffeescript 2 | 3 | import org.mozilla.javascript.{ 4 | Context, Function, JavaScriptException, NativeObject } 5 | import java.io.InputStreamReader 6 | import java.nio.charset.Charset 7 | 8 | /** 9 | * A Scala / Rhino Coffeescript compiler. 10 | * @author daggerrz 11 | * @author doug (to a lesser degree) 12 | */ 13 | abstract class Compiler(src: String) { 14 | val utf8 = Charset.forName("utf-8") 15 | 16 | /** compiler arguments in addition to `bare` */ 17 | def args: Map[String, Any] = Map.empty[String, Any] 18 | 19 | override def toString = "%s(%s)" format(getClass.getSimpleName, src) 20 | 21 | /** 22 | * Compiles a string of Coffeescript code to Javascript. 23 | * 24 | * @param code the Coffeescript source code 25 | * @param bare whether the Coffeescript compiler should run in "bare" mode 26 | * @return Either a compilation error description or 27 | * the compiled Javascript code 28 | */ 29 | def compile(code: String, bare: Boolean): Either[String, String] = 30 | withContext { ctx => 31 | val coffee = scope.get("CoffeeScript", scope).asInstanceOf[NativeObject] 32 | val compileFunc = coffee.get("compile", scope).asInstanceOf[Function] 33 | val opts = ctx.evaluateString(scope, jsArgs(bare), null, 1, null) 34 | try { 35 | Right(compileFunc.call( 36 | ctx, scope, coffee, Array(code, opts)).asInstanceOf[String]) 37 | } catch { 38 | case e : JavaScriptException => 39 | Left(e.getValue.toString) 40 | } 41 | } 42 | 43 | lazy val scope = withContext { ctx => 44 | val scope = ctx.initStandardObjects() 45 | ctx.evaluateReader( 46 | scope, 47 | new InputStreamReader( 48 | getClass().getResourceAsStream("/%s" format src), utf8 49 | ), src, 1, null 50 | ) 51 | 52 | scope 53 | } 54 | 55 | private def withContext[T](f: Context => T): T = 56 | try { 57 | val ctx = Context.enter() 58 | // Do not compile to byte code (max 64kb methods) 59 | ctx.setOptimizationLevel(-1) 60 | f(ctx) 61 | } finally { 62 | Context.exit() 63 | } 64 | 65 | private def jsArgs(bare: Boolean) = 66 | ((List.empty[String] /: (Map("bare" -> bare) ++ args)) { 67 | (a,e) => e match { 68 | case (k, v) => 69 | "%s:%s".format(k, v match { 70 | case s: String => "'%s'" format s 71 | case lit => lit 72 | }) :: a 73 | } 74 | }).mkString("({",",","});") 75 | 76 | } 77 | 78 | object Vanilla extends Compiler("vanilla/coffee-script.js") 79 | 80 | object Iced extends Compiler("iced/coffee-script.js") { 81 | override def args = Map("runtime" -> "inline") 82 | } 83 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/bare/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings:_*) 2 | 3 | (CoffeeKeys.bare in (Compile, CoffeeKeys.coffee)) := true 4 | 5 | InputKey[Unit]("contents") <<= inputTask { (argsTask: TaskKey[Seq[String]]) => 6 | (argsTask, streams) map { 7 | (args, out) => 8 | args match { 9 | case Seq(given, expected) => 10 | if(IO.read(file(given)).trim.equals(IO.read(file(expected)).trim)) out.log.debug( 11 | "Contents match" 12 | ) 13 | else error( 14 | "Contents of (%s)\n%s does not match (%s)\n%s" format( 15 | given, IO.read(file(given)), expected, IO.read(file(expected)) 16 | ) 17 | ) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/bare/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | alert("hi"); -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/bare/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/bare/src/main/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | alert "hi" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/bare/test: -------------------------------------------------------------------------------- 1 | # should generate javascript 2 | > coffee 3 | $ exists target/scala-2.9.2/resource_managed/main/js/foo.js 4 | > contents target/scala-2.9.2/resource_managed/main/js/foo.js fixtures/foo.js -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/coffee-no-ice/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings:_*) 2 | 3 | InputKey[Unit]("contents") <<= inputTask { (argsTask: TaskKey[Seq[String]]) => 4 | (argsTask, streams) map { 5 | (args, out) => 6 | args match { 7 | case Seq(given, expected) => 8 | if(IO.read(file(given)).trim.equals(IO.read(file(expected)).trim)) out.log.debug( 9 | "Contents match" 10 | ) 11 | else error( 12 | "Contents of (%s)\n%s does not match (%s)\n%s" format( 13 | given, IO.read(file(given)), expected, IO.read(file(expected)) 14 | ) 15 | ) 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/coffee-no-ice/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | alert("hi"); 4 | 5 | }).call(this); -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/coffee-no-ice/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/coffee-no-ice/src/main/coffee/bar.iced: -------------------------------------------------------------------------------- 1 | search = (keyword, cb) -> 2 | host = "http://search.twitter.com/" 3 | url = "#{host}/search.json?q=#{keyword}&callback=?" 4 | await $.getJSON url, defer json 5 | cb json.results -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/coffee-no-ice/src/main/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | alert "hi" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/coffee-no-ice/test: -------------------------------------------------------------------------------- 1 | # should generate javascript from coffeescript and ignore iced files 2 | > coffee 3 | $ exists target/scala-2.9.2/resource_managed/main/js/foo.js 4 | > contents target/scala-2.9.2/resource_managed/main/js/foo.js fixtures/foo.js 5 | -$ exists target/scala-2.9.2/resource_managed/main/js/bar.js -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings: _*) 2 | 3 | logLevel := Level.Debug 4 | 5 | InputKey[Unit]("contents") <<= inputTask { (argsTask: TaskKey[Seq[String]]) => 6 | (argsTask, streams) map { 7 | (args, out) => 8 | args match { 9 | case Seq(given, expected) => 10 | if(IO.read(file(given)).trim.equals(IO.read(file(expected)).trim)) out.log.debug( 11 | "Contents match" 12 | ) 13 | else error( 14 | "Contents of (%s)\n%s does not match (%s)\n%s" format( 15 | given, IO.read(file(given)), expected, IO.read(file(expected)) 16 | ) 17 | ) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/fixtures/hello-test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | alert("hello test"); 4 | 5 | }).call(this); 6 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/fixtures/hello.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | alert("hello"); 4 | 5 | }).call(this); 6 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/src/main/coffee/hello.coffee: -------------------------------------------------------------------------------- 1 | alert "hello" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/src/test/coffee/hello-test.coffee: -------------------------------------------------------------------------------- 1 | alert "hello test" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-test-coffee/test: -------------------------------------------------------------------------------- 1 | # compile should compile main sources 2 | > compile 3 | $ exists target/scala-2.9.2/resource_managed/main/js/hello.js 4 | > contents target/scala-2.9.2/resource_managed/main/js/hello.js fixtures/hello.js 5 | 6 | # (but not test sources) 7 | -$ exists target/scala-2.9.2/resource_managed/test/js/hello-test.js 8 | 9 | # test:compile should compile test sources 10 | > test:compile 11 | $ exists target/scala-2.9.2/resource_managed/test/js/hello-test.js 12 | > contents target/scala-2.9.2/resource_managed/test/js/hello-test.js fixtures/hello-test.js -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-triggers-coffee/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings:_*) 2 | 3 | InputKey[Unit]("contents") <<= inputTask { (argsTask: TaskKey[Seq[String]]) => 4 | (argsTask, streams) map { 5 | (args, out) => 6 | args match { 7 | case Seq(given, expected) => 8 | if(IO.read(file(given)).trim.equals(IO.read(file(expected)).trim)) out.log.debug( 9 | "Contents match" 10 | ) 11 | else error( 12 | "Contents of (%s)\n%s does not match (%s)\n%s" format( 13 | given, IO.read(file(given)), expected, IO.read(file(expected)) 14 | ) 15 | ) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-triggers-coffee/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | alert("foo"); 4 | 5 | }).call(this); -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-triggers-coffee/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-triggers-coffee/src/main/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | alert "foo" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/compile-triggers-coffee/test: -------------------------------------------------------------------------------- 1 | # compile should trigger the coffee task 2 | > compile 3 | $ exists target/scala-2.9.2/resource_managed/main/js/foo.js 4 | > contents target/scala-2.9.2/resource_managed/main/js/foo.js fixtures/foo.js -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/custom-filter/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings:_*) 2 | 3 | (CoffeeKeys.filter in (Compile, CoffeeKeys.coffee)) := ("*.coffee" - "*.no.coffee") 4 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/custom-filter/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/custom-filter/src/main/coffee/bar.no.coffee: -------------------------------------------------------------------------------- 1 | alert "no!" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/custom-filter/src/main/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | alert "hi" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/custom-filter/test: -------------------------------------------------------------------------------- 1 | # should only compile coffee sources 2 | # matching filter 3 | > coffee 4 | $ exists target/scala-2.9.2/resource_managed/main/js/foo.js 5 | -$ exists target/scala-2.9.2/resource_managed/main/js/bar.no.js 6 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings:_*) 2 | 3 | (CoffeeKeys.iced in (Compile, CoffeeKeys.coffee)) := true 4 | 5 | InputKey[Unit]("contents") <<= inputTask { (argsTask: TaskKey[Seq[String]]) => 6 | (argsTask, streams) map { 7 | (args, out) => 8 | args match { 9 | case pair @ Seq(given, expected) => 10 | pair.zip(pair map { f => IO.read(file(f)).trim }) match { 11 | case Seq((_, givenC), (_, expectedC)) => 12 | if(givenC.equals(expectedC)) out.log.debug( 13 | "Contents match" 14 | ) else { IO.write(new java.io.File("/Users/dougtangren/Desktop/foo.txt"), givenC);error( 15 | "Contents of (%s)\n'%s' does not match (%s)\n'%s'" format( 16 | given, givenC, expected, expectedC) 17 | )} 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/fixtures/bar.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var iced, parallelSearch, __iced_k, __iced_k_noop, 3 | __slice = [].slice; 4 | 5 | iced = { 6 | Deferrals: (function() { 7 | 8 | function _Class(_arg) { 9 | this.continuation = _arg; 10 | this.count = 1; 11 | this.ret = null; 12 | } 13 | 14 | _Class.prototype._fulfill = function() { 15 | if (!--this.count) return this.continuation(this.ret); 16 | }; 17 | 18 | _Class.prototype.defer = function(defer_params) { 19 | var _this = this; 20 | ++this.count; 21 | return function() { 22 | var inner_params, _ref; 23 | inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 24 | if (defer_params != null) { 25 | if ((_ref = defer_params.assign_fn) != null) { 26 | _ref.apply(null, inner_params); 27 | } 28 | } 29 | return _this._fulfill(); 30 | }; 31 | }; 32 | 33 | return _Class; 34 | 35 | })(), 36 | findDeferral: function() { 37 | return null; 38 | } 39 | }; 40 | __iced_k = __iced_k_noop = function() {}; 41 | 42 | parallelSearch = function(keywords, cb) { 43 | var i, k, out, ___iced_passed_deferral, __iced_deferrals, __iced_k, 44 | _this = this; 45 | __iced_k = __iced_k_noop; 46 | ___iced_passed_deferral = iced.findDeferral(arguments); 47 | out = []; 48 | (function(__iced_k) { 49 | var _i, _len; 50 | __iced_deferrals = new iced.Deferrals(__iced_k, { 51 | parent: ___iced_passed_deferral, 52 | funcname: "parallelSearch" 53 | }); 54 | for (i = _i = 0, _len = keywords.length; _i < _len; i = ++_i) { 55 | k = keywords[i]; 56 | search(k, __iced_deferrals.defer({ 57 | assign_fn: (function(__slot_1, __slot_2) { 58 | return function() { 59 | return __slot_1[__slot_2] = arguments[0]; 60 | }; 61 | })(out, i), 62 | lineno: 5 63 | })); 64 | } 65 | __iced_deferrals._fulfill(); 66 | })(function() { 67 | return cb(out); 68 | }); 69 | }; 70 | 71 | }).call(this); -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var iced, search, __iced_k, __iced_k_noop, 3 | __slice = [].slice; 4 | 5 | iced = { 6 | Deferrals: (function() { 7 | 8 | function _Class(_arg) { 9 | this.continuation = _arg; 10 | this.count = 1; 11 | this.ret = null; 12 | } 13 | 14 | _Class.prototype._fulfill = function() { 15 | if (!--this.count) return this.continuation(this.ret); 16 | }; 17 | 18 | _Class.prototype.defer = function(defer_params) { 19 | var _this = this; 20 | ++this.count; 21 | return function() { 22 | var inner_params, _ref; 23 | inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : []; 24 | if (defer_params != null) { 25 | if ((_ref = defer_params.assign_fn) != null) { 26 | _ref.apply(null, inner_params); 27 | } 28 | } 29 | return _this._fulfill(); 30 | }; 31 | }; 32 | 33 | return _Class; 34 | 35 | })(), 36 | findDeferral: function() { 37 | return null; 38 | } 39 | }; 40 | __iced_k = __iced_k_noop = function() {}; 41 | 42 | search = function(keyword, cb) { 43 | var host, json, url, ___iced_passed_deferral, __iced_deferrals, __iced_k, 44 | _this = this; 45 | __iced_k = __iced_k_noop; 46 | ___iced_passed_deferral = iced.findDeferral(arguments); 47 | host = "http://search.twitter.com/"; 48 | url = "" + host + "/search.json?q=" + keyword + "&callback=?"; 49 | (function(__iced_k) { 50 | __iced_deferrals = new iced.Deferrals(__iced_k, { 51 | parent: ___iced_passed_deferral, 52 | funcname: "search" 53 | }); 54 | $.getJSON(url, __iced_deferrals.defer({ 55 | assign_fn: (function() { 56 | return function() { 57 | return json = arguments[0]; 58 | }; 59 | })(), 60 | lineno: 4 61 | })); 62 | __iced_deferrals._fulfill(); 63 | })(function() { 64 | return cb(json.results); 65 | }); 66 | }; 67 | 68 | }).call(this); -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/src/main/coffee/bar.iced: -------------------------------------------------------------------------------- 1 | parallelSearch = (keywords, cb) -> 2 | out = [] 3 | await 4 | for k,i in keywords 5 | search k, defer out[i] 6 | cb out -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/src/main/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | search = (keyword, cb) -> 2 | host = "http://search.twitter.com/" 3 | url = "#{host}/search.json?q=#{keyword}&callback=?" 4 | await $.getJSON url, defer json 5 | cb json.results -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/iced/test: -------------------------------------------------------------------------------- 1 | # should generate javascript from iced coffeescript with .iced and .coffee extensions 2 | > coffee 3 | $ exists target/scala-2.9.2/resource_managed/main/js/foo.js 4 | > contents target/scala-2.9.2/resource_managed/main/js/foo.js fixtures/foo.js 5 | $ exists target/scala-2.9.2/resource_managed/main/js/bar.js 6 | > contents target/scala-2.9.2/resource_managed/main/js/bar.js fixtures/bar.js -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/simple/build.sbt: -------------------------------------------------------------------------------- 1 | seq(coffeeSettings:_*) 2 | 3 | InputKey[Unit]("contents") <<= inputTask { (argsTask: TaskKey[Seq[String]]) => 4 | (argsTask, streams) map { 5 | (args, out) => 6 | args match { 7 | case Seq(given, expected) => 8 | if(IO.read(file(given)).trim.equals(IO.read(file(expected)).trim)) out.log.debug( 9 | "Contents match" 10 | ) 11 | else error( 12 | "Contents of (%s)\n%s does not match (%s)\n%s" format( 13 | given, IO.read(file(given)), expected, IO.read(file(expected)) 14 | ) 15 | ) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/simple/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | alert("hi"); 4 | 5 | }).call(this); -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/simple/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "latest.integration") 2 | -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/simple/src/main/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | alert "hi" -------------------------------------------------------------------------------- /src/sbt-test/coffeescripted-sbt/simple/test: -------------------------------------------------------------------------------- 1 | # should generate javascript 2 | > coffee 3 | $ exists target/scala-2.9.2/resource_managed/main/js/foo.js 4 | > contents target/scala-2.9.2/resource_managed/main/js/foo.js fixtures/foo.js --------------------------------------------------------------------------------