-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
144 lines (122 loc) · 3.5 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
135
136
137
138
139
140
141
142
143
144
Global / onChangedBuildSource := ReloadOnSourceChanges
inThisBuild(Seq(
organization := "de.djini",
version := "0.50.0",
scalaVersion := "3.5.0",
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-source:future",
"-Wunused:all",
"-Xfatal-warnings",
"-Xkind-projector:underscores",
),
versionScheme := Some("early-semver")
))
lazy val noTestSettings =
Seq(
test := {},
testQuick := {}
)
lazy val `sjs-diffless` =
project.in(file("."))
.aggregate(
`sjs-diffless-core`,
`sjs-diffless-example`
)
.settings(
publishArtifact := false
//publish := {},
//publishLocal := {}
)
//------------------------------------------------------------------------------
lazy val `sjs-diffless-core` =
project.in(file("modules/core"))
.enablePlugins(
ScalaJSPlugin
)
.dependsOn()
.settings(
noTestSettings,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.8.0" % "compile"
)
)
//------------------------------------------------------------------------------
lazy val appSource = SettingKey[File] ("appSource")
lazy val appSjs = SettingKey[File] ("appSjs")
lazy val appTarget = SettingKey[File] ("appTarget")
lazy val appBuild = TaskKey[File] ("appBuild")
val jsCompiler =
Def.taskDyn {
Compile / fastOptJS
/*
if (development.value) Compile / fastOptJS
else Compile / fullOptJS
*/
}
lazy val `sjs-diffless-example` =
project.in(file("modules/example"))
.enablePlugins(
ScalaJSPlugin
)
.dependsOn(
`sjs-diffless-core`
)
.settings(
noTestSettings,
appSource := (Compile / sourceDirectory).value / "webapp",
appSjs := crossTarget.value / "sjs",
appTarget := crossTarget.value / "webapp",
appBuild := {
// fetch JS files
val (js, jsMap) = {
val attrd = jsCompiler.value
val src = attrd.data
val map = attrd get scalaJSSourceMap getOrElse (sys error s"missing map file for $src")
// file names have been fixed with artifactPath and scalaJSLinkerConfig below
(src, map)
}
val jsToCopy =
Vector(
js -> (appTarget.value / js.getName),
jsMap -> (appTarget.value / jsMap.getName)
)
// fetch static assets
val staticToCopy =
appSource.value.allPaths ** -DirectoryFilter pair Path.rebase(appSource.value, appTarget.value)
// copy together
streams.value.log info s"building app in ${appTarget.value}"
IO delete appTarget.value
appTarget.value mkdirs ()
IO copy (staticToCopy ++ jsToCopy)
// BETTER return path mappings
appTarget.value
},
// automatically start on import
scalaJSUseMainModuleInitializer := true,
// NOTE somehow this was cleaner
//relativeSourceMaps := true,
scalaJSLinkerConfig := scalaJSLinkerConfig.value withRelativizeSourceMapBase Some((appSjs.value / "index.js").toURI),
// final name to ensure the .map reference doesn't have to be patched later
Compile / fastOptJS / artifactPath := appSjs.value / "index.js",
Compile / fullOptJS / artifactPath := appSjs.value / "index.js",
watchSources := watchSources.value :+ Watched.WatchSource(appSource.value)
)
//------------------------------------------------------------------------------
TaskKey[File]("bundle") :=
(`sjs-diffless-example` / appBuild).value
TaskKey[Unit]("demo") := {
import java.awt.Desktop
import java.net.URI
val log = streams.value.log
val file = (`sjs-diffless-example` / appBuild).value / "index.html"
if (Desktop.isDesktopSupported) {
log info s"opening $file"
Desktop.getDesktop browse file.toURI
}
else {
log info s"Desktop is not supported"
}
}