diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-22 17:12:41 +0800 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-22 17:38:45 +0800 |
commit | 63d77017a205a394e604ec9f943d0ef6d2511ef4 (patch) | |
tree | 072287c838bdd75373c959724e7025c2a404845c | |
parent | 66b668b9cdcefcbdb5db1b3e8a0d9adb08b608ff (diff) | |
download | cbt-63d77017a205a394e604ec9f943d0ef6d2511ef4.tar.gz cbt-63d77017a205a394e604ec9f943d0ef6d2511ef4.tar.bz2 cbt-63d77017a205a394e604ec9f943d0ef6d2511ef4.zip |
refactor scalajs to make use of nested builds for scoping
-rw-r--r-- | examples/scalajs-react-example/README.md | 7 | ||||
-rw-r--r-- | examples/scalajs-react-example/js/build/build.scala | 5 | ||||
-rw-r--r-- | examples/scalajs-react-example/server/public/index.html | 2 | ||||
-rw-r--r-- | plugins/scalajs/ScalaJsBuild.scala | 37 | ||||
-rw-r--r-- | plugins/scalajs/ScalaJsLib.scala | 4 | ||||
-rw-r--r-- | test/test.scala | 4 |
6 files changed, 27 insertions, 32 deletions
diff --git a/examples/scalajs-react-example/README.md b/examples/scalajs-react-example/README.md index 74e015a..82936eb 100644 --- a/examples/scalajs-react-example/README.md +++ b/examples/scalajs-react-example/README.md @@ -1,11 +1,12 @@ Compilation instructions ------------------------------------------- -1. `cbt fastOptJS` +1. `cd js` +2. `cbt compile` or `cbt fullOpt.compile` Execution instructions ------------------------------------------- -1. `cd server` +1. `cd ../server` 2. `npm install` 3. `node app.js` -4. Go to http://localhost:3000 in a browser
\ No newline at end of file +4. Go to http://localhost:3000 in a browser diff --git a/examples/scalajs-react-example/js/build/build.scala b/examples/scalajs-react-example/js/build/build.scala index f5fe33f..6db866b 100644 --- a/examples/scalajs-react-example/js/build/build.scala +++ b/examples/scalajs-react-example/js/build/build.scala @@ -16,7 +16,6 @@ class Build(val context: Context) extends ScalaJsBuild{ ) ) - override protected def fastOptJSFile = { - projectDirectory.getParentFile ++ "/server/public" ++ ("/"++super.fastOptJSFile.getName) - } + override def scalaJsTargetFile = + projectDirectory.getParentFile ++ ("/server/public/generated/" ++ projectName ++ ".js") } diff --git a/examples/scalajs-react-example/server/public/index.html b/examples/scalajs-react-example/server/public/index.html index 08de20d..e07687c 100644 --- a/examples/scalajs-react-example/server/public/index.html +++ b/examples/scalajs-react-example/server/public/index.html @@ -10,7 +10,7 @@ <script src="https://fb.me/react-15.1.0.min.js"></script> <script src="https://fb.me/react-dom-15.1.0.min.js"></script> - <script type="text/javascript" src="./my-project-fastopt.js"></script> + <script type="text/javascript" src="generated/my-project.js"></script> <script type="text/javascript"> App().main(); </script> diff --git a/plugins/scalajs/ScalaJsBuild.scala b/plugins/scalajs/ScalaJsBuild.scala index 1694aea..0c7222c 100644 --- a/plugins/scalajs/ScalaJsBuild.scala +++ b/plugins/scalajs/ScalaJsBuild.scala @@ -2,7 +2,7 @@ package cbt import java.io.File import java.net.URL -trait ScalaJsBuild extends BaseBuild { +trait ScalaJsBuild extends DynamicOverrides{ final protected val scalaJsLib = ScalaJsLib( scalaJsVersion, scalaVersion, context.cbtLastModified, context.paths.mavenCache ) @@ -21,28 +21,23 @@ trait ScalaJsBuild extends BaseBuild { 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} - ) + + override def compile = { + super.compile + scalaJsLib.link( + scalaJsTargetFile, scalaJsOptions, target +: dependencies.collect{case d: BoundMavenDependency => d.jar} + ) + None // FIXME: we need to rethink the concept of a "compile" task I think. There is no time to return here. + } 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) + /** Where to put the generated js file */ + def scalaJsTargetFile: File - def fastOptJS = { - compile - link(FastOptJS, fastOptJSFile) - fastOptJSFile - } - def fullOptJS = { - compile - link(FullOptJS, fullOptJSFile) - fullOptJSFile - } + override def cleanFiles = super.cleanFiles :+ scalaJsTargetFile :+ (scalaJsTargetFile ++ ".map") + + def fullOpt = newBuild[ScalaJsBuild](""" + override def scalaJsOptions = "--fullOpt" +: super.scalaJsOptions + """) } diff --git a/plugins/scalajs/ScalaJsLib.scala b/plugins/scalajs/ScalaJsLib.scala index 393ebfe..ae37bde 100644 --- a/plugins/scalajs/ScalaJsLib.scala +++ b/plugins/scalajs/ScalaJsLib.scala @@ -23,14 +23,14 @@ case class ScalaJsLib( ) def link( - mode: ScalaJsOutputMode, outputPath: File, + outputPath: File, scalaJsOptions: Seq[String], entriesToLink: Seq[File] ) = { val scalaJsCliDep = dep( "scalajs-cli_"++lib.libMajorVersion(scalaVersion) ) + outputPath.getParentFile.mkdirs lib.runMain( "org.scalajs.cli.Scalajsld", Seq( - mode.option, "--sourceMap", "--stdlib", s"${scalaJsLibraryDependency.jar.getAbsolutePath}", "--output", outputPath.string diff --git a/test/test.scala b/test/test.scala index 5359029..9a70b6c 100644 --- a/test/test.scala +++ b/test/test.scala @@ -216,8 +216,8 @@ object Main{ task("run","../examples/dotty-example") task("doc","../examples/dotty-example") } - task("fastOptJS","../examples/scalajs-react-example/js") - task("fullOptJS","../examples/scalajs-react-example/js") + task("compile","../examples/scalajs-react-example/js") + task("fullOpt.compile","../examples/scalajs-react-example/js") compile("../examples/uber-jar-example") { |