Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

git init of a sbt plugin that can compile CoffeeScript files using JC…

…offeeScript and Rhino
  • Loading branch information...
commit 58a72bca499e92427769b1af4d3c43f8c53145aa 0 parents
@rubbish rubbish authored
4 .gitignore
@@ -0,0 +1,4 @@
+target/
+lib_managed/
+src_managed/
+/project/boot
8 project/build.properties
@@ -0,0 +1,8 @@
+#Project properties
+#Sun Aug 15 11:35:30 CDT 2010
+project.organization=org.coffeescript
+project.name=coffee-script-sbt-plugin
+sbt.version=0.7.4
+project.version=0.9.0
+build.scala.versions=2.7.7
+project.initialize=false
14 project/build/CoffeeScriptSbtPluginProject.scala
@@ -0,0 +1,14 @@
+import sbt._
+
+class CoffeeScriptSbtPluginProject(info: ProjectInfo) extends PluginProject(info) with test.ScalaScripted {
+ val jcoffeescript = "org.jcoffeescript" % "jcoffeescript" % "0.9.0" from "http://github.com/downloads/yeungda/jcoffeescript/jcoffeescript-0.9.0.jar"
+
+ override def scriptedSbt = "0.7.4"
+ override def scriptedBufferLog = false
+
+ override def testAction = testNoScripted
+ lazy val default = scripted dependsOn(publishLocal) describedAs("Publishes locally and tests against example projects")
+
+ val publishTo = Resolver.file("local-s3-repo.coderlukes.com-mirror",
+ new java.io.File(Path.userHome.toString, "code/repo.coderlukes.com"))
+}
6 project/plugins/Plugins.scala
@@ -0,0 +1,6 @@
+import sbt._
+
+class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
+ val scriptedDep = "org.scala-tools.sbt" % "scripted" % "0.7.4"
+ val databinder_repo = Resolver.url("Databinder Repository", new java.net.URL("http://databinder.net/repo"))(Resolver.ivyStylePatterns)
+}
3  project/plugins/project/build.properties
@@ -0,0 +1,3 @@
+#Project properties
+#Sun Aug 15 12:05:09 CDT 2010
+plugin.uptodate=true
32 src/main/scala/CoffeeScriptCompile.scala
@@ -0,0 +1,32 @@
+package org.coffeescript
+
+import sbt._
+import scala.io.Source
+import org.jcoffeescript.JCoffeeScriptCompiler
+import java.io.File
+
+trait CoffeeScriptCompile extends DefaultProject {
+ lazy val compileCoffeeScript = task {
+ log.info("Compiling CoffeeScript")
+
+ val coffeeCompiler = new JCoffeeScriptCompiler()
+
+ var coffeeScripts = ("src" / "main" / "coffee-script" ##) ** "*.coffee"
+ coffeeScripts.get.foreach {
+ coffeePath =>
+ val coffeeFile = coffeePath.asFile
+ val jsDestination = new File("src/main/generated-javascript/" + coffeePath.base + ".js")
+
+ log.info("Compiling %s" format (coffeePath.relativePath))
+
+ val coffeeSource = Source.fromFile(coffeeFile).mkString
+ val compiledJs = coffeeCompiler.compile(coffeeSource)
+
+ new File(jsDestination.getParent).mkdirs
+
+ FileUtilities.write(jsDestination, compiledJs, log)
+ }
+
+ None
+ }
+}
3  src/sbt-test/coffee-script-compile/passing/project/build.properties
@@ -0,0 +1,3 @@
+project.organization=empty
+project.name=coffee-script-compile
+project.version=1.0
24 ...sbt-test/coffee-script-compile/passing/project/build/CoffeeScriptCompileTestProject.scala
@@ -0,0 +1,24 @@
+import sbt._
+import org.coffeescript.CoffeeScriptCompile
+
+import scala.io.Source
+import java.io.File
+
+class FailingProject(info: ProjectInfo) extends DefaultProject(info) with CoffeeScriptCompile {
+
+ lazy val checkContains = task { args =>
+ val file = Source.fromFile(new File(args(0)))
+ val expectedLine = args(1) // .slice(1, args.length).mkString(" ")
+ findLine(file, expectedLine)
+ }
+
+ private def findLine(file: Source, expectedLine: String) = task {
+ println(expectedLine)
+ val matchedLines = file.getLines.filter { line => line.contains(expectedLine) }
+ if (matchedLines.hasNext) {
+ None
+ } else {
+ Some("Expected '%s' to contain '%s' but didn't" format (file.mkString, expectedLine) )
+ }
+ }
+}
5 src/sbt-test/coffee-script-compile/passing/project/plugins/Plugins.scala
@@ -0,0 +1,5 @@
+import sbt._
+
+class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
+ val coffeeScriptCompile = "org.coffeescript" % "coffee-script-sbt-plugin" % "0.9.0"
+}
3  src/sbt-test/coffee-script-compile/passing/src/main/coffee-script/hello_world.coffee
@@ -0,0 +1,3 @@
+who = "World"
+
+alert "Hello #{who}!"
4 src/sbt-test/coffee-script-compile/passing/test
@@ -0,0 +1,4 @@
+> compile-coffee-script
+
+> check-contains src/main/generated-javascript/hello_world.js "var who;"
+
Please sign in to comment.
Something went wrong with that request. Please try again.