Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to sbt 1.x #183

Merged
merged 6 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The documentation is generated from the lagom main project as unstyled HTML snip

## Developing the website

A static version of the website can be generated by running `sbt web-stage`. This will output the entire website to the `target/web/stage` directory. You should start a simple HTTP server from here to serve the docs, eg using `python -m SimpleHTTPServer`. The `sbt ~web-stage` command can be used to tell sbt to watch for changes and rebuild the site whenever anything changes.
A static version of the website can be generated by running `sbt webStage`. This will output the entire website to the `target/web/stage` directory. You should start a simple HTTP server from here to serve the docs, eg using `python -m SimpleHTTPServer`. The `sbt ~web-stage` command can be used to tell sbt to watch for changes and rebuild the site whenever anything changes.

For convenience, `sbt run` does the above for you, starting a static Akka HTTP server in the stage directory, and then watching the filesystem for changes and rebuilding the site whenever it changes.

Expand Down
21 changes: 13 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import scala.sys.process._
import java.io.Closeable
import sbt.PathFinder

import scala.concurrent.Await

Expand Down Expand Up @@ -61,8 +63,8 @@ val runCommand = Command.make("run") { state =>
javaOptions += "-Ddev",
fork := true // required for javaOptions to take effect
)
val stateWithExtraSettings = extracted.append(extraSettings, stateWithStop)
Parser.parse("~web-stage", stateWithExtraSettings.combinedParser) match {
val stateWithExtraSettings = extracted.appendWithSession(extraSettings, stateWithStop)
Parser.parse("~webStage", stateWithExtraSettings.combinedParser) match {
case Right(cmd) => cmd()
case Left(msg) => throw sys.error(s"Invalid command:\n$msg")
}
Expand All @@ -74,7 +76,7 @@ commands ++= Seq(runCommand, stopCommand)
val generateHtml = taskKey[Seq[File]]("Generate the site HTML")

target in generateHtml := WebKeys.webTarget.value / "generated-html"
generateHtml <<= Def.taskDyn {
generateHtml := Def.taskDyn {
val outputDir = (target in generateHtml).value
val docsDir = sourceDirectory.value / "docs"
val markdownDir = (sourceDirectory in Compile).value / "markdown"
Expand All @@ -88,9 +90,9 @@ generateHtml <<= Def.taskDyn {
blogDir,
assetFingerPrint
).mkString(" ", " ", "")).value
outputDir.***.filter(_.isFile).get
outputDir.allPaths.filter(_.isFile).get
}
}
}.value

def path(segments: String*): String = segments.mkString(java.io.File.separator)

Expand All @@ -115,11 +117,14 @@ StylusKeys.compress := true

pipelineStages := Seq(uglify, concat)
WebKeys.pipeline ++= {
generateHtml.value pair relativeTo((target in generateHtml).value)
generateHtml.value pair Path.relativeTo((target in generateHtml).value)
}
watchSources ++= {
((sourceDirectory in Compile).value / "markdown").***.get ++
(sourceDirectory.value / "blog").***.get
val markdownFolder: File = (sourceDirectory in Compile).value / "markdown"
val blogFolder: File = sourceDirectory.value / "blog"
val markdown: Seq[File] = markdownFolder.allPaths.get
val blog: Seq[File] = blogFolder.allPaths.get
markdown ++ blog
}

// Include hidden files in the output (e.g., src/main/public/.well-known)
Expand Down
28 changes: 14 additions & 14 deletions project/SimpleHTTPServer.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.io.{ Closeable, File }

import akka.actor.ActorSystem
import akka.actor.{ ActorSystem, CoordinatedShutdown }
import akka.http.scaladsl.Http
import akka.http.scaladsl.Http.ServerBinding
import akka.http.scaladsl.server.Directives._
Expand All @@ -21,25 +21,25 @@ class SimpleHTTPServer(webDirectory: File, port: Int) extends Closeable {
// needed for the future flatMap/onComplete in the end
private implicit val executionContext = system.dispatcher

private val route404 = getFromFile(new File(webDirectory, "404.html"))
.andThen(_.map {
case Complete(response) => Complete(response.copy(status = 404))
case other => other
})
private val route404 = getFromFile(new File(webDirectory, "404.html"))
.andThen(_.map {
case Complete(response) => Complete(response.copy(status = 404))
case other => other
})

private val route =
getFromDirectory(webDirectory.getAbsolutePath) ~
pathPrefix(Segments) { folderNameSeq =>
val absoluteFolder = folderNameSeq.foldLeft(webDirectory)((acc, subfolder) => new File(acc, subfolder))
getFromFile(new File(absoluteFolder, "index.html"))
} ~ route404
private val route =
getFromDirectory(webDirectory.getAbsolutePath) ~
pathPrefix(Segments) { folderNameSeq =>
val absoluteFolder = folderNameSeq.foldLeft(webDirectory)((acc, subfolder) => new File(acc, subfolder))
getFromFile(new File(absoluteFolder, "index.html"))
} ~ route404


val bindingFuture: Future[ServerBinding] = Http().bindAndHandle(route, "localhost", port)
val bindingFuture: Future[ServerBinding] = Http().bindAndHandle(route, "localhost", port)

def close(): Unit = {
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.shutdown())
.onComplete(_ => CoordinatedShutdown(system).run(CoordinatedShutdown.JvmExitReason))
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.17
sbt.version=1.2.8
15 changes: 8 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.3.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-js-engine" % "1.1.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-stylus" % "1.0.1")
addSbtPlugin("net.ground5hark.sbt" % "sbt-concat" % "0.1.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.4.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-js-engine" % "1.2.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-stylus" % "1.1.0")
addSbtPlugin("net.ground5hark.sbt" % "sbt-concat" % "0.2.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "2.0.0")

resolvers += "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/"

// Used for our SimpleHTTPServer in Akka HTTP
libraryDependencies += "com.typesafe.akka" % "akka-http-experimental_2.10" % "2.0.4"
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.1.8"
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.21"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import play.twirl.api._
@import com.lightbend.lagom.docs.BlogPost
@import com.lightbend.lagom.docs.LagomContext

Expand Down
1 change: 1 addition & 0 deletions src/main/twirl/com/lightbend/lagom/docs/main.scala.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import play.twirl.api._
@import com.lightbend.lagom.docs.svg.html._
@import com.lightbend.lagom.docs.LagomContext

Expand Down