diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-06-17 22:38:18 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-06-19 20:57:54 -0400 |
commit | 47cc41ecaa2eaf5677fcb1794db7bbba6533b559 (patch) | |
tree | 8708b8cd5954dfa03f2478b77440340c7664972b /plugins/scalajs/ScalaJsBuild.scala | |
parent | 12d5bad267b5759e941b7101578808aeb6351e66 (diff) | |
download | cbt-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/ScalaJsBuild.scala')
-rw-r--r-- | plugins/scalajs/ScalaJsBuild.scala | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/plugins/scalajs/ScalaJsBuild.scala b/plugins/scalajs/ScalaJsBuild.scala new file mode 100644 index 0000000..9374f66 --- /dev/null +++ b/plugins/scalajs/ScalaJsBuild.scala @@ -0,0 +1,52 @@ +package cbt +import java.io.File +import java.net.URL + +trait ScalaJsBuild extends BaseBuild { + final protected val scalaJsLib = ScalaJsLib( + scalaJsVersion, + scalaVersion, + context.cbtHasChanged, + context.classLoaderCache, + context.paths.mavenCache + ) + import scalaJsLib.{link => _,_} + + def scalaJsVersion = "0.6.8" + final protected val scalaJsMajorVersion: String = lib.libMajorVersion(scalaJsVersion) + final protected val artifactIdSuffix = s"_sjs$scalaJsMajorVersion" + + override def dependencies = super.dependencies :+ scalaJsLibraryDependency + override def scalacOptions = super.scalacOptions ++ scalaJsLib.scalacOptions + + /** Note: We make same assumption about scala version. + In order to be able to choose different scala version, one has to use %. */ + implicit class ScalaJsDependencyBuilder(groupId: String){ + def %%%(artifactId: String) = new DependencyBuilder2( + groupId, artifactId + artifactIdSuffix, Some(scalaMajorVersion)) + } + + private def link(mode: ScalaJsOutputMode, outputPath: File) = scalaJsLib.link( + mode, outputPath, scalaJsOptions, + target +: dependencies.collect{case d: BoundMavenDependency => d.jar} + ) + + def scalaJsOptions: Seq[String] = Seq() + def scalaJsOptionsFastOpt: Seq[String] = scalaJsOptions + def scalaJsOptionsFullOpt: Seq[String] = scalaJsOptions + + private def output(mode: ScalaJsOutputMode) = target ++ s"/$projectName-${mode.fileSuffix}.js" + protected def fastOptJSFile: File = output(FastOptJS) + protected def fullOptJSFile: File = output(FullOptJS) + + def fastOptJS = { + compile + link(FastOptJS, fastOptJSFile) + fastOptJSFile + } + def fullOptJS = { + compile + link(FullOptJS, fullOptJSFile) + fullOptJSFile + } +} |