Browse files

add docgen

  • Loading branch information...
1 parent 0b81cb6 commit 4b63109fc7a3b60ed5c4051d92884383ba11b7ba Sam Ritchie committed Feb 13, 2013
Showing with 44 additions and 18 deletions.
  1. +1 −18 project/Build.scala
  2. +43 −0 project/DocGen.scala
View
19 project/Build.scala
@@ -3,24 +3,7 @@ package algebird
import sbt._
import Keys._
-import com.typesafe.sbt.SbtSite.{ site, SiteKeys }
-import com.typesafe.sbt.SbtGhPages.ghpages
-import com.typesafe.sbt.SbtGit.GitKeys.gitRemoteRepo
-
object AlgebirdBuild extends Build {
- lazy val unidocSettings: Seq[sbt.Setting[_]] =
- site.includeScaladoc("target/site") ++ Seq(
- scalacOptions in doc <++= (version, baseDirectory in LocalProject("algebird")).map { (v, rootBase) =>
- val tagOrBranch = if (v.endsWith("-SNAPSHOT")) "develop" else v
- val docSourceUrl = "https://github.com/twitter/algebird/tree/" + tagOrBranch + "€{FILE_PATH}.scala"
- Seq("-sourcepath", rootBase.getAbsolutePath, "-doc-source-url", docSourceUrl)
- },
- Unidoc.unidocDirectory <<= target/ "site",
- gitRemoteRepo := "git@github.com:twitter/algebird.git"
- )
-
- lazy val publishSettings = site.settings ++ Unidoc.settings ++ ghpages.settings ++ unidocSettings
-
val sharedSettings = Project.defaultSettings ++ Seq(
organization := "com.twitter",
version := "0.1.9-SNAPSHOT",
@@ -82,7 +65,7 @@ object AlgebirdBuild extends Build {
lazy val algebird = Project(
id = "algebird",
base = file("."),
- settings = sharedSettings ++ publishSettings
+ settings = sharedSettings ++ DocGen.publishSettings
).settings(
test := { }
).aggregate(algebirdTest,
View
43 project/DocGen.scala
@@ -0,0 +1,43 @@
+package algebird
+
+import sbt._
+import Keys._
+
+import com.typesafe.sbt.git.GitRunner
+import com.typesafe.sbt.SbtGit.GitKeys
+import com.typesafe.sbt.SbtSite.{ site, SiteKeys }
+import com.typesafe.sbt.SbtGhPages.{ ghpages, GhPagesKeys => ghkeys }
+import com.typesafe.sbt.SbtGit.GitKeys.gitRemoteRepo
+
+object DocGen {
+ val docDirectory = "target/site"
+
+ def syncLocal = (ghkeys.updatedRepository, GitKeys.gitRunner, streams) map { (repo, git, s) =>
+ cleanSite(repo, git, s) // First, remove 'stale' files.
+ val rootPath = file(docDirectory) // Now copy files.
+ IO.copyDirectory(rootPath, repo)
+ IO.touch(repo / ".nojekyll")
+ repo
+ }
+
+ private def cleanSite(dir: File, git: GitRunner, s: TaskStreams): Unit = {
+ val toClean = IO.listFiles(dir).filterNot(_.getName == ".git").map(_.getAbsolutePath).toList
+ if(!toClean.isEmpty)
+ git(("rm" :: "-r" :: "-f" :: "--ignore-unmatch" :: toClean) :_*)(dir, s.log)
+ ()
+ }
+
+ lazy val unidocSettings: Seq[sbt.Setting[_]] =
+ site.includeScaladoc(docDirectory) ++ Seq(
+ scalacOptions in doc <++= (version, baseDirectory in LocalProject("algebird")).map { (v, rootBase) =>
+ val tagOrBranch = if (v.endsWith("-SNAPSHOT")) "develop" else v
+ val docSourceUrl = "https://github.com/twitter/algebird/tree/" + tagOrBranch + "€{FILE_PATH}.scala"
+ Seq("-sourcepath", rootBase.getAbsolutePath, "-doc-source-url", docSourceUrl)
+ },
+ Unidoc.unidocDirectory := file(docDirectory),
+ gitRemoteRepo := "git@github.com:twitter/algebird.git",
+ ghkeys.synchLocal <<= syncLocal
+ )
+
+ lazy val publishSettings = site.settings ++ Unidoc.settings ++ ghpages.settings ++ unidocSettings
+}

0 comments on commit 4b63109

Please sign in to comment.