-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sbt
executable file
·121 lines (112 loc) · 4.45 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
//Project settings
lazy val mainSettings = Seq(
name := "Minions",
version := "1.0",
scalaVersion := "2.12.2"
)
//Extra scala compiler options
lazy val extraCompilerOptions = Seq(
"-deprecation",
"-feature",
"-language:existentials",
"-unchecked",
"-Xfatal-warnings",
"-Xlint:-unused,_",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-infer-any",
"-Ywarn-nullary-unit",
"-Ywarn-inaccessible",
"-Ywarn-value-discard",
"-Ywarn-unused:params",
"-Ywarn-unused:patvars",
"-Ywarn-unused:privates",
"-Ywarn-unused:implicits",
"-Ywarn-unused:locals",
"-Xfuture"
)
//This option is actually irrelevant for us because we're using a browser to run and test the client, rather
//than writing something that should run like a server on Node.js or a similar javascript runtime engine.
//Disables Rhino and makes ScalaJS use Node.js instead
//Rhino is slow, but it doesn't require separate installation should work out-of-the-box
//Node.js is fast, but needs separate installation
//scalaJSUseRhino in Global := false
//Helpful docs for the below setup
//https://www.scala-js.org/tutorial/basic/
//https://www.scala-js.org/doc/project/cross-build.html
//https://www.scala-js.org/api/sbt-scalajs/0.6.10/#org.scalajs.sbtplugin.cross.CrossProject
//Define a type of project where we have shared scala files (in core/),
//scala files that are compiled for the jvm only (in server/),
//and scala file that are compiled for javascript only (in client/)
lazy val scalaJSCrossType = new org.scalajs.sbtplugin.cross.CrossType() {
override def sharedSrcDir(projectBase: File, conf: String): Option[File] = {
conf match {
case "main" => Some(new File(projectBase.getParentFile(),"core/src/main/scala"))
case "test" => Some(new File(projectBase.getParentFile(),"core/src/test/scala"))
}
}
override def projectDir(crossBase: File, projectType: String): File = {
projectType match {
case "jvm" => new File(crossBase,"server")
case "js" => new File(crossBase,"client")
case _ => throw new Exception("Invalid projectType: " + projectType)
}
}
}
//Create the project
lazy val minions = crossProject.crossType(scalaJSCrossType).in(file(".")).
settings(mainSettings: _*).
settings(
scalacOptions ++= extraCompilerOptions,
libraryDependencies ++= Seq (
"com.typesafe.play" %%% "play-json" % "2.6.3"
)
).
jvmSettings(
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % "10.0.10"
)
).
jsSettings(
name := "MinionsClient",
//Create a javascript launcher to call the main class for us
persistLauncher in Compile := true,
persistLauncher in Test := false,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.9.1",
"be.doeraene" %%% "scalajs-jquery" % "0.9.1"
)
)
//Pull out the subprojects so that sbt knows they're there
//Note - do NOT modify the project settings here, instead use jvmSettings and jsSettings above
lazy val minionsServer = minions.jvm
lazy val minionsClient = minions.js
//Custom task that copies necessary stuff to web/ directory
val copyStuffTask = taskKey[Unit]("Copy to web directory")
copyStuffTask := {
val unused = (fastOptJS in Compile in minionsClient).value
streams.value.log.info("Copying stuff to web/")
def createDirectory(dst: String) = IO.createDirectory(new File(dst))
def copyFile(src: String, dst: String) = {
streams.value.log.info("Copying " + src + " to " + dst)
IO.copyFile(new File(src), new File(dst))
}
def copyDirectory(src: String, dst: String) = {
streams.value.log.info("Copying " + src + " to " + dst)
IO.delete(new File(dst))
IO.copyDirectory(new File(src), new File(dst))
}
createDirectory("web")
createDirectory("web/js")
createDirectory("web/img")
copyFile("client/minionsclient_dev.html","web/index.html")
copyFile("client/jquery-2.1.1.min.js","web/js/jquery-2.1.1.min.js")
copyFile("client/target/scala-2.12/minionsclient-fastopt.js","web/js/minionsclient-fastopt.js")
copyFile("client/target/scala-2.12/minionsclient-fastopt.js.map","web/js/minionsclient-fastopt.js.map")
copyFile("client/target/scala-2.12/minionsclient-jsdeps.js","web/js/minionsclient-jsdeps.js")
copyFile("client/target/scala-2.12/minionsclient-launcher.js","web/js/minionsclient-launcher.js")
copyDirectory("client/img","web/img")
}
//Custom alias that builds everything and copies it
addCommandAlias("buildEverything", ";project minions;compile;fastOptJS;copyStuffTask")