aboutsummaryrefslogtreecommitdiff
path: root/plugins/scalajs/ScalaJsLib.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-06-17 22:38:18 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-06-19 20:57:54 -0400
commit47cc41ecaa2eaf5677fcb1794db7bbba6533b559 (patch)
tree8708b8cd5954dfa03f2478b77440340c7664972b /plugins/scalajs/ScalaJsLib.scala
parent12d5bad267b5759e941b7101578808aeb6351e66 (diff)
downloadcbt-47cc41ecaa2eaf5677fcb1794db7bbba6533b559.tar.gz
cbt-47cc41ecaa2eaf5677fcb1794db7bbba6533b559.tar.bz2
cbt-47cc41ecaa2eaf5677fcb1794db7bbba6533b559.zip
refactor/simplify scalaJs plugin and example
- Restructure code as 1 library case class and 1 Build mixin trait. A library is generally easier to understand and could be re-used independently. 1 trait seems simpler than several here. - Let not the plugin create the multi-project build, but the user project manually. I think while this adds some minor code overhead it is much simpler to understand. Fewer tasks and other moving parts needed. - Remove verbose nested sbt-style folder structure. It's simpler without it :).
Diffstat (limited to 'plugins/scalajs/ScalaJsLib.scala')
-rw-r--r--plugins/scalajs/ScalaJsLib.scala51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/scalajs/ScalaJsLib.scala b/plugins/scalajs/ScalaJsLib.scala
new file mode 100644
index 0000000..0355850
--- /dev/null
+++ b/plugins/scalajs/ScalaJsLib.scala
@@ -0,0 +1,51 @@
+package cbt
+import java.io.File
+
+case class ScalaJsLib(
+ scalaJsVersion: String, scalaVersion: String,
+ cbtHasChanged: Boolean, classLoaderCache: ClassLoaderCache, mavenCache: File
+)(implicit logger: Logger){
+ sealed trait ScalaJsOutputMode {
+ def option: String
+ def fileSuffix: String
+ }
+ case object FastOptJS extends ScalaJsOutputMode{
+ override val option = "--fastOpt"
+ override val fileSuffix = "fastopt"
+ }
+ case object FullOptJS extends ScalaJsOutputMode{
+ override val option = "--fullOpt"
+ override val fileSuffix = "fullopt"
+ }
+
+ val lib = new Lib(logger)
+ def dep(artifactId: String) = MavenResolver( cbtHasChanged, mavenCache, mavenCentral ).bindOne(
+ MavenDependency("org.scala-js", artifactId, scalaJsVersion)
+ )
+
+ def link(
+ mode: ScalaJsOutputMode, outputPath: File,
+ scalaJsOptions: Seq[String], entriesToLink: Seq[File]
+ ) = {
+ val scalaJsCliDep = dep( "scalajs-cli_"++lib.libMajorVersion(scalaVersion) )
+ lib.runMain(
+ "org.scalajs.cli.Scalajsld",
+ Seq(
+ mode.option,
+ "--sourceMap",
+ "--stdlib", s"${scalaJsLibraryDependency.jar.getAbsolutePath}",
+ "--output", outputPath.string
+ ) ++ scalaJsOptions ++ entriesToLink.map(_.getAbsolutePath),
+ scalaJsCliDep.classLoader(classLoaderCache)
+ )
+ }
+
+ val scalaJsLibraryDependency = dep( "scalajs-library_"++lib.libMajorVersion(scalaVersion) )
+
+ // Has to be full Scala version because the compiler is incompatible between versions
+ val scalaJsCompilerDependency = dep( "scalajs-compiler_"++scalaVersion )
+ val scalacOptions = Seq(
+ "-Xplugin:" ++ scalaJsCompilerDependency.jar.string,
+ "-Xplugin-require:scalajs"
+ )
+}