-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.sbt
134 lines (111 loc) · 4.28 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import scala.sys.process._
import java.io.Closeable
import sbt.PathFinder
import scala.concurrent.Await
lazy val `lagom-docs` = (project in file("."))
.enablePlugins(SbtTwirl, SbtWeb)
scalaVersion := "2.12.9"
scalacOptions += "-deprecation"
resolvers += "Lightbend ivy releases repository" at "https://dl.cloudsmith.io/public/lightbend/ivy-releases/maven/"
libraryDependencies ++= Seq(
"org.webjars" % "normalize.css" % "3.0.2",
"org.webjars" % "foundation" % "6.2.0",
"org.webjars" % "jquery" % "2.2.1",
"org.webjars.bower" % "waypoints" % "4.0.0",
"org.webjars" % "prettify" % "4-Mar-2013",
"com.lightbend.markdown" %% "lightbend-markdown-server" % "1.7.0",
"org.yaml" % "snakeyaml" % "1.12",
"org.parboiled" % "parboiled-java" % "1.4.1"
)
lazy val assetFingerPrint = "git rev-parse HEAD".!!.trim
val httpServer = AttributeKey[Closeable]("http-server")
val stopCommand = Command.command("stop") { state =>
state.attributes.get(httpServer) match {
case Some(server) =>
server.close()
state.remove(httpServer)
case None => state
}
}
val runCommand = Command.make("run") { state =>
import complete.Parsers._
import complete.Parser
import scala.concurrent.duration._
(Space ~> NatBasic).?.map { maybePort =>
() =>
val port = maybePort.getOrElse(8080)
val log = state.log
val extracted = Project.extract(state)
val stageDir = extracted.get(WebKeys.stagingDirectory)
log.info(s"\u001b[32mRunning HTTP server on http://localhost:$port, press ENTER to exit...\u001b[0m")
val simpleHttpServer = SimpleHTTPServer(stageDir, port)
Await.ready(simpleHttpServer.bindingFuture, 5.seconds)
val stateWithStop = "stop" :: state.put(httpServer, new Closeable {
override def close(): Unit = {
log.info("Shutting down HTTP server")
simpleHttpServer.close()
}
}).addExitHook(() => simpleHttpServer.close())
val extraSettings = Seq(
javaOptions += "-Ddev",
fork := true // required for javaOptions to take effect
)
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")
}
}
}
commands ++= Seq(runCommand, stopCommand)
val generateHtml = taskKey[Seq[File]]("Generate the site HTML")
target in generateHtml := WebKeys.webTarget.value / "generated-html"
generateHtml := Def.taskDyn {
val outputDir = (target in generateHtml).value
val docsDir = sourceDirectory.value / "docs"
val markdownDir = (sourceDirectory in Compile).value / "markdown"
val blogDir = sourceDirectory.value / "blog"
Def.task {
(runMain in Compile).toTask(Seq(
"com.lightbend.lagom.docs.DocumentationGenerator",
outputDir,
docsDir,
markdownDir,
blogDir,
assetFingerPrint
).mkString(" ", " ", "")).value
outputDir.allPaths.filter(_.isFile).get
}
}.value
def path(segments: String*): String = segments.mkString(java.io.File.separator)
Concat.groups := Seq(
s"$assetFingerPrint-all-styles-concat.css" -> group(Seq(
path("css", "oss-banners.css"),
path("lib", "foundation", "dist", "foundation.min.css"),
path("lib", "prettify", "prettify.css"),
"main.min.css"
)),
s"$assetFingerPrint-all-scripts-concat.js" -> group(Seq(
path("lib", "jquery", "jquery.min.js"),
path("lib", "foundation", "dist", "foundation.min.js"),
path("lib", "waypoints", "lib", "jquery.waypoints.min.js"),
path("lib", "waypoints", "lib", "shortcuts", "sticky.min.js"),
path("lib", "prettify", "prettify.js"),
path("lib", "prettify", "lang-scala.js"),
"main.min.js"
))
)
StylusKeys.compress := true
pipelineStages := Seq(uglify, concat)
WebKeys.pipeline ++= {
generateHtml.value pair Path.relativeTo((target in generateHtml).value)
}
watchSources ++= {
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)
excludeFilter in Assets := NothingFilter