aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--examples/scalajs-plain-example/README.md9
-rw-r--r--examples/scalajs-plain-example/js/App.scala27
-rw-r--r--examples/scalajs-plain-example/js/Plotly.scala8
-rw-r--r--examples/scalajs-plain-example/js/build/build.scala18
-rw-r--r--examples/scalajs-plain-example/js/build/build/build.scala4
-rw-r--r--examples/scalajs-plain-example/jvm/build/build.scala6
-rw-r--r--examples/scalajs-plain-example/server/public/index.html17
-rw-r--r--examples/scalajs-plain-example/shared/SomeSharedClass.scala2
-rw-r--r--examples/scalajs-react-example/README.md7
-rw-r--r--examples/scalajs-react-example/js/build/build.scala5
-rw-r--r--examples/scalajs-react-example/server/app.js28
-rw-r--r--examples/scalajs-react-example/server/public/index.html2
-rw-r--r--plugins/essentials/build/build.scala10
-rw-r--r--plugins/scalajs/ScalaJsBuild.scala37
-rw-r--r--plugins/scalajs/ScalaJsLib.scala4
-rw-r--r--plugins/scalatest/build/build.scala13
-rw-r--r--stage2/BasicBuild.scala4
-rw-r--r--stage2/Lib.scala10
-rw-r--r--stage2/Plugin.scala3
-rw-r--r--test/test.scala4
21 files changed, 156 insertions, 63 deletions
diff --git a/.gitignore b/.gitignore
index 5692c12..953f0a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@ node_modules
*fastopt*
*fullopt*
examples/dotty-example/_site
+examples/scalajs-plain-example/server/public/generated
diff --git a/examples/scalajs-plain-example/README.md b/examples/scalajs-plain-example/README.md
new file mode 100644
index 0000000..280a555
--- /dev/null
+++ b/examples/scalajs-plain-example/README.md
@@ -0,0 +1,9 @@
+
+Compilation instructions
+-------------------------------------------
+1. `cd js`
+2. `cbt compile` or `cbt fullOpt.compile`
+
+Execution instructions
+-------------------------------------------
+1. open `server/public/index.html` in a browser
diff --git a/examples/scalajs-plain-example/js/App.scala b/examples/scalajs-plain-example/js/App.scala
new file mode 100644
index 0000000..71a285e
--- /dev/null
+++ b/examples/scalajs-plain-example/js/App.scala
@@ -0,0 +1,27 @@
+package prototype
+
+import org.scalajs.dom
+
+import scala.scalajs.js
+import scala.scalajs.js.JSON
+import scala.scalajs.js.JSApp
+import scala.scalajs.js.annotation.JSExport
+
+@JSExport("App")
+object App extends JSApp {
+ def main(): Unit = {
+ val trace1 = """{
+ | "x": [1, 2, 3, 4],
+ | "y": [10, 15, 13, 17],
+ | "type": "scatter"
+ |} """.stripMargin
+ val trace2 = """{
+ | "x": [1, 2, 3, 4],
+ | "y": [16, 5, 11, 9],
+ | "type": "scatter"
+ |} """.stripMargin
+ val data = js.Array(trace1, trace2).map(trace => JSON.parse(trace))
+ val doc = dom.document
+ Plotly.newPlot("plotly", data)
+ }
+}
diff --git a/examples/scalajs-plain-example/js/Plotly.scala b/examples/scalajs-plain-example/js/Plotly.scala
new file mode 100644
index 0000000..a4623c6
--- /dev/null
+++ b/examples/scalajs-plain-example/js/Plotly.scala
@@ -0,0 +1,8 @@
+package prototype
+
+import scala.scalajs.js
+
+@js.native
+object Plotly extends js.Object {
+ def newPlot(id: String, data: js.Array[js.Dynamic]): js.Any = js.native
+}
diff --git a/examples/scalajs-plain-example/js/build/build.scala b/examples/scalajs-plain-example/js/build/build.scala
new file mode 100644
index 0000000..06e4876
--- /dev/null
+++ b/examples/scalajs-plain-example/js/build/build.scala
@@ -0,0 +1,18 @@
+import cbt._
+class Build(val context: Context) extends ScalaJsBuild{
+ override def projectName = "my-project"
+
+ override def sources = super.sources ++ Seq(
+ projectDirectory.getParentFile ++ "/shared"
+ )
+
+ override def dependencies = (
+ super.dependencies ++
+ Resolver( mavenCentral ).bind(
+ "org.scala-js" %%% "scalajs-dom" % "0.9.0"
+ )
+ )
+
+ override def scalaJsTargetFile =
+ projectDirectory.getParentFile ++ ("/server/public/generated/" ++ projectName ++ ".js")
+}
diff --git a/examples/scalajs-plain-example/js/build/build/build.scala b/examples/scalajs-plain-example/js/build/build/build.scala
new file mode 100644
index 0000000..b30e005
--- /dev/null
+++ b/examples/scalajs-plain-example/js/build/build/build.scala
@@ -0,0 +1,4 @@
+import cbt._
+class Build(val context: Context) extends BuildBuild{
+ override def dependencies = super.dependencies :+ plugins.scalaJs
+}
diff --git a/examples/scalajs-plain-example/jvm/build/build.scala b/examples/scalajs-plain-example/jvm/build/build.scala
new file mode 100644
index 0000000..327d705
--- /dev/null
+++ b/examples/scalajs-plain-example/jvm/build/build.scala
@@ -0,0 +1,6 @@
+import cbt._
+class Build(val context: Context) extends BaseBuild{
+ override def sources = super.sources ++ Seq(
+ projectDirectory.getParentFile ++ "/shared"
+ )
+}
diff --git a/examples/scalajs-plain-example/server/public/index.html b/examples/scalajs-plain-example/server/public/index.html
new file mode 100644
index 0000000..a06fc3a
--- /dev/null
+++ b/examples/scalajs-plain-example/server/public/index.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Prototype</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.min.css">
+</head>
+<body>
+ execute <pre style="display: inline">cbt fastOptJs</pre> in <pre style="display: inline">js/</pre> to generate/update the .js file
+ <div id="plotly"></div>
+ <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
+ <script type="text/javascript" src="./generated/my-project.js"></script>
+ <script type="text/javascript">
+ App().main();
+ </script>
+</body>
+</html>
diff --git a/examples/scalajs-plain-example/shared/SomeSharedClass.scala b/examples/scalajs-plain-example/shared/SomeSharedClass.scala
new file mode 100644
index 0000000..44d4ca8
--- /dev/null
+++ b/examples/scalajs-plain-example/shared/SomeSharedClass.scala
@@ -0,0 +1,2 @@
+package prototype
+case class SomeSharedClass(i: Int)
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/app.js b/examples/scalajs-react-example/server/app.js
index 620c26a..d44adcc 100644
--- a/examples/scalajs-react-example/server/app.js
+++ b/examples/scalajs-react-example/server/app.js
@@ -9,20 +9,20 @@ app.get('/data', function(req, res){
//'https://api.instagram.com/v1/media/popular?client_id=642176ece1e7445e99244cec26f4de1f&callback=?',
'https://pixabay.com/api/?key=2741116-9706ac6d4a58f2b5416225505&q=yellow+flowers&image_type=photo',
function(response) {
-
- var body = "";
- response.on('data', function(data) {
- body += data;
- });
- response.on('end', function() {
- console.log(body);
- try {
- res.send(JSON.parse(body));
- } catch (e) {
- return console.error(e);
- }
- });
- });
+ var body = "";
+ response.on('data', function(data) {
+ body += data;
+ });
+ response.on('end', function() {
+ console.log(body);
+ try {
+ res.send(JSON.parse(body));
+ } catch (e) {
+ return console.error(e);
+ }
+ });
+ }
+ );
request.on('error', function(e) {
console.log('Problem with request: ' + e.message);
});
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/essentials/build/build.scala b/plugins/essentials/build/build.scala
index 1288367..91c3a0f 100644
--- a/plugins/essentials/build/build.scala
+++ b/plugins/essentials/build/build.scala
@@ -1,6 +1,8 @@
import cbt._
-class Build(val context: Context) extends Plugin{
- override def dependencies =
- super.dependencies :+ // don't forget super.dependencies here for scala-library, etc.
- DirectoryDependency( context.cbtHome ++ "/libraries/eval" )
+class Build(val context: Context) extends BaseBuild{
+ override def dependencies = (
+ super.dependencies
+ :+ context.cbtDependency
+ :+ DirectoryDependency( context.cbtHome ++ "/libraries/eval" )
+ )
}
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/plugins/scalatest/build/build.scala b/plugins/scalatest/build/build.scala
index dd21898..ce07b36 100644
--- a/plugins/scalatest/build/build.scala
+++ b/plugins/scalatest/build/build.scala
@@ -1,9 +1,10 @@
import cbt._
-class Build(val context: Context) extends Plugin{
- override def dependencies =
- super.dependencies ++
- Resolver( mavenCentral ).bind(
- ScalaDependency("org.scalatest","scalatest","2.2.4")
- )
+class Build(val context: Context) extends BaseBuild{
+ override def dependencies = (
+ super.dependencies
+ :+ context.cbtDependency
+ ) ++ Resolver( mavenCentral ).bind(
+ ScalaDependency("org.scalatest","scalatest","2.2.4")
+ )
}
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index e3b1c1b..8d72f9a 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -153,9 +153,11 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
)
}
+ def cleanFiles: Seq[File] = Seq( target )
+
def clean: ExitCode = {
lib.clean(
- target,
+ cleanFiles,
context.args.contains("force"),
context.args.contains("dry-run"),
context.args.contains("list"),
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index 700f18d..b6187ce 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -223,7 +223,7 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
)
}
- def clean(target: File, force: Boolean, dryRun: Boolean, list: Boolean, help: Boolean): ExitCode = {
+ def clean(targets: Seq[File], force: Boolean, dryRun: Boolean, list: Boolean, help: Boolean): ExitCode = {
def depthFirstFileStream(file: File): Vector[File] = {
(
if (file.isDirectory) {
@@ -231,7 +231,7 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
} else Vector()
) :+ file
}
- lazy val files = depthFirstFileStream( target )
+ lazy val files = targets.filter(_.exists).flatMap( depthFirstFileStream )
if( help ){
System.err.println( s"""
@@ -240,8 +240,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
dry-run does not actually delete files
""" )
ExitCode.Success
- } else if (!target.exists){
- System.err.println( "Nothing to clean. Does not exist: " ++ target.string )
+ } else if (files.isEmpty){
+ System.err.println( "Nothing to clean." )
ExitCode.Success
} else if( list ){
files.map(_.string).foreach( println )
@@ -250,7 +250,7 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
val performDelete = (
force || {
val console = consoleOrFail("Use `cbt direct clean` or `cbt clean help`")
- System.err.println("Files to be deleted:\n\n")
+ System.err.println("Files to be deleted:\n")
files.foreach( System.err.println )
System.err.println("")
System.err.print("To delete the above files type 'delete': ")
diff --git a/stage2/Plugin.scala b/stage2/Plugin.scala
index 94a8749..4d52fcc 100644
--- a/stage2/Plugin.scala
+++ b/stage2/Plugin.scala
@@ -1,4 +1,5 @@
package cbt
trait Plugin extends BaseBuild{
- override def dependencies = super.dependencies :+ context.cbtDependency
+ override def dependencies =
+ super.dependencies :+ context.cbtDependency :+ DirectoryDependency( context.cbtHome ++ "/plugins/essentials" )
}
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")
{