Skip to content

Commit

Permalink
it writes, it removes
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Sep 19, 2011
0 parents commit 3878459
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
target
project/boot
project/build/target
project/plugins/target
*/project/boot
*/target
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2011 Doug Tangren

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
@@ -0,0 +1,3 @@
# screen writer

Doug Tangren (softprops) 2011
7 changes: 7 additions & 0 deletions build.sbt
@@ -0,0 +1,7 @@
sbtPlugin := true

organization := "me.lessis"

name := "screen-writer"

version <<= sbtVersion(v => "0.1.0-%s-SNAPSHOT".format(v))
79 changes: 79 additions & 0 deletions src/main/scala/screenwriter.scala
@@ -0,0 +1,79 @@
package screenwriter

object Keys {
import sbt._
val script = InputKey[Unit]("script", "Generates a new sbt test script")
val scrap = InputKey[Unit]("scrap", "Deletes a sbt test script")
}

object TestFile {
def defaultContent =
"""# write your tests below
|# commands start with $ cmd
|# tasks start with > task""".stripMargin
}

object PluginsFile {
def apply(org: String, name: String, version: String) =
"""libraryDependencies += "%s" %%%% "%s" %% "%s" """.format(
org, name, version
)
}

object BuildFile {
def defaultContent =
"# seq(yourPluginSettings:_*)"
}

object Plugin extends sbt.Plugin {
import sbt._
import sbt.Keys._
import screenwriter.Keys._
import java.io.File

val ScreenWriter = config("screen-writer")

def options: Seq[Setting[_]] = inConfig(ScreenWriter)(Seq(
scrap <<= inputTask { (argsTask: TaskKey[Seq[String]]) =>
(argsTask, sourceDirectory, name, streams) map {
(args, src, name, out) =>
args match {
case Seq(scrpt) =>
val sroot = new File(src, "sbt-test/%s/%s".format(name, scrpt))
IO.delete(sroot)
out.log.info("scraped script %s" format sroot)
case _ => error("usage screenwriter:scrap script-name")
}
}
},
script <<= inputTask { (argsTask: TaskKey[Seq[String]]) =>
(argsTask, streams, version, name, organization, sourceDirectory) map {
(args, out, vers, name, org, src) =>
args match {
case Seq(scrpt) =>
val sroot = new File(src, "sbt-test/%s/%s" format(name, scrpt))
if(sroot.exists) error("%s script already exists" format scrpt)
else {
IO.createDirectory(sroot)
val Seq(testFile, pluginsFile, buildFile) =
Seq("test", "project/plugins/build.sbt", "build.sbt") map {
new File(sroot, _)
}

IO.touch(testFile)
IO.write(testFile, TestFile.defaultContent)

IO.touch(pluginsFile)
IO.write(pluginsFile, PluginsFile(org, name, vers))

IO.touch(buildFile)
IO.write(buildFile, BuildFile.defaultContent)

out.log.info("Generated script %s" format scrpt)
}
case _ => error("usage: screen-writer:script script-name")
}
}
}
))
}

0 comments on commit 3878459

Please sign in to comment.