Skip to content

Commit 64677a4

Browse files
author
Mateusz Starzec
committed
Improved jQuery demo build configuration: two modules with shared sources
1 parent b07abaa commit 64677a4

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dist: trusty
44
jdk: oraclejdk8
55
scala:
66
- 2.11.12
7-
- 2.12.6
7+
- 2.12.7
88

99
before_script:
1010
- "export DISPLAY=:99.0"
@@ -24,4 +24,4 @@ before_script:
2424
script:
2525
- sbt ++$TRAVIS_SCALA_VERSION test
2626
- sbt ++$TRAVIS_SCALA_VERSION publishLocal
27-
- cd example && sbt ++$TRAVIS_SCALA_VERSION compile jquery-demo/fullOptJS jquery-bundler-demo/compileStatics
27+
- cd example && sbt ++$TRAVIS_SCALA_VERSION compile jquery-global-demo/fullOptJS jquery-bundler-demo/compileStatics

example/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ The `build.sbt` file contains two configurations:
44

55
### How to use?
66

7-
Run `sbt fastOptJS` or `sbt fullOptJS` to compile this demo. You can find all generated files
8-
in the `generated` directory. Open `index.html` in your browser.
7+
Run `sbt jquery-global-demo/fastOptJS` or `sbt jquery-global-demo/fullOptJS` to compile this demo. You can find all generated files
8+
in the `generated/global` directory. Open `index.html` in your browser.
99

1010
### How to use? (ScalaJSBundlerPlugin)
1111

12-
Run `sbt compileStatics` to compile this demo. You can find all generated files
13-
in the `generated` directory. Open `index.html` in your browser.
12+
Run `sbt jquery-bundler-demo/compileStatics` to compile this demo. You can find all generated files
13+
in the `generated/bundler` directory. Open `index.html` in your browser.

example/build.sbt

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ inThisBuild(Seq(
2727
},
2828
))
2929

30-
val generatedDir = file("generated")
31-
val compileStatics = taskKey[Unit]("Compiles all static files.")
30+
val generatedGlobalDir = file("generated/global")
3231
val copyAssets = taskKey[Unit]("Copies all assets to the target directory.")
33-
val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin)
32+
val `jquery-global-demo` = project.in(file("global-demo")).enablePlugins(ScalaJSPlugin)
3433
.settings(
3534
libraryDependencies ++= Dependencies.deps.value,
3635
jsDependencies ++= Dependencies.jsDeps.value,
3736

37+
sourceDirsSettings(_.getParentFile),
38+
3839
/* move these files out of target/. */
39-
Compile / fullOptJS / crossTarget := generatedDir,
40-
Compile / fastOptJS / crossTarget := generatedDir,
41-
Compile / packageJSDependencies / crossTarget := generatedDir,
42-
Compile / packageMinifiedJSDependencies / crossTarget := generatedDir,
40+
Compile / fullOptJS / crossTarget := generatedGlobalDir,
41+
Compile / fastOptJS / crossTarget := generatedGlobalDir,
42+
Compile / packageJSDependencies / crossTarget := generatedGlobalDir,
43+
Compile / packageMinifiedJSDependencies / crossTarget := generatedGlobalDir,
4344

4445
Compile / fastOptJS := (Compile / fastOptJS).dependsOn(copyAssets).value,
4546
Compile / fullOptJS := (Compile / fullOptJS).dependsOn(copyAssets).value,
@@ -48,8 +49,8 @@ val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin)
4849

4950
copyAssets := {
5051
IO.copyFile(
51-
sourceDirectory.value / "main/assets/index-global.html",
52-
generatedDir / "index.html"
52+
sourceDirectory.value / "main/assets/index.html",
53+
generatedGlobalDir / "index.html"
5354
)
5455
},
5556

@@ -63,30 +64,55 @@ val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin)
6364
(Compile / packageMinifiedJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js"
6465
)
6566

66-
val `jquery-bundler-demo` = project.in(file("."))
67+
val generatedBundlerDir = file("generated/bundler")
68+
val compileStatics = taskKey[Unit]("Compiles all static files.")
69+
val `jquery-bundler-demo` = project.in(file("bundler-demo"))
6770
.enablePlugins(ScalaJSBundlerPlugin)
6871
.settings(
6972
libraryDependencies ++= Dependencies.deps.value,
73+
74+
sourceDirsSettings(_.getParentFile),
7075

7176
Compile / scalaJSUseMainModuleInitializer := true,
7277

7378
copyAssets := {
7479
IO.copyFile(
75-
sourceDirectory.value / "main/assets/index-bundler.html",
76-
generatedDir / "index.html"
80+
sourceDirectory.value / "main/assets/index.html",
81+
generatedBundlerDir / "index.html"
7782
)
7883
},
7984

8085
compileStatics := {
8186
val sjsFileName = (Compile / fastOptJS).value.data.name.stripSuffix(".js")
8287
IO.copyFile(
8388
(Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js",
84-
generatedDir / "scripts/frontend.js"
89+
generatedBundlerDir / "scripts/frontend.js"
8590
)
8691
IO.copyFile(
8792
(Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js.map",
88-
generatedDir / "scripts/frontend.js.map"
93+
generatedBundlerDir / "scripts/frontend.js.map"
8994
)
9095
},
9196
compileStatics := compileStatics.dependsOn(Compile / fastOptJS / webpack, copyAssets).value,
92-
)
97+
)
98+
99+
def mkSourceDirs(base: File, scalaBinary: String, conf: String): Seq[File] = Seq(
100+
base / "src" / conf / "scala",
101+
base / "src" / conf / s"scala-$scalaBinary",
102+
base / "src" / conf / "java"
103+
)
104+
105+
def mkResourceDirs(base: File, conf: String): Seq[File] = Seq(
106+
base / "src" / conf / "resources"
107+
)
108+
109+
def sourceDirsSettings(baseMapper: File => File) = Seq(
110+
Compile / unmanagedSourceDirectories ++=
111+
mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "main"),
112+
Compile / unmanagedResourceDirectories ++=
113+
mkResourceDirs(baseMapper(baseDirectory.value), "main"),
114+
Test / unmanagedSourceDirectories ++=
115+
mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "test"),
116+
Test / unmanagedResourceDirectories ++=
117+
mkResourceDirs(baseMapper(baseDirectory.value), "test"),
118+
)

0 commit comments

Comments
 (0)