Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further update dependencies #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ target/
.settings/
.idea
.idea_modules
.vscode
24 changes: 14 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import sbt.Keys._

val defaultSettings = Seq(
scalacOptions ++= Seq("-feature", "-deprecation"),
unmanagedSourceDirectories in Compile += baseDirectory.value / "shared" / "main" / "scala",
unmanagedSourceDirectories in Compile += baseDirectory.value / "shared" / "main" / "scala",
unmanagedSourceDirectories in Test += baseDirectory.value / "shared" / "test" / "scala"
)

lazy val root = project.in(file(".")).settings(defaultSettings:_*).settings(
lazy val root = project.in(file(".")).settings(defaultSettings: _*).settings(
name := "workbench",
version := "0.4.1",
organization := "com.lihaoyi",
scalaVersion := "2.12.4",
version := "0.4.4",
organization := "com.sa",
scalaVersion := "2.12.12",
sbtPlugin := true,
publishArtifact in Test := false,
publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"),
publishTo := Some("releases" at "https://nexus.s-art.co.nz/repository/maven-releases"),
// publishTo := Some("Nexus" at "http:https://nexus.financialplatforms.co.nz:8081/nexus/content/repositories/releases"),
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials.sa"),
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials.fp"),
pomExtra :=
<url>https://github.com/lihaoyi/workbench</url>
<licenses>
Expand All @@ -35,13 +38,14 @@ lazy val root = project.in(file(".")).settings(defaultSettings:_*).settings(
</developers>
,
(resources in Compile) += {
(fullOptJS in (client, Compile)).value
(artifactPath in (client, Compile, fullOptJS)).value
(fullOptJS in(client, Compile)).value
(artifactPath in(client, Compile, fullOptJS)).value
},
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.21"),
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.1.1"),
libraryDependencies ++= Seq(
Dependencies.akkaHttp,
Dependencies.akka,
Dependencies.akkaStream,
Dependencies.autowire.value,
Dependencies.upickle.value
)
Expand All @@ -57,5 +61,5 @@ lazy val client = project.in(file("client"))
Dependencies.dom.value,
Dependencies.upickle.value
),
emitSourceMaps := false
scalaJSLinkerConfig ~= { _.withSourceMap(false) }
)
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
package com.lihaoyi.workbench

import upickle.Js
import upickle.default
import upickle.default.{Reader, Writer}
import upickle.json
import org.scalajs.dom
import org.scalajs.dom.ext._
import org.scalajs.dom.raw._
import ujson.Value.Value
import upickle.default
import upickle.default.{Reader, Writer}

import scala.collection.mutable.ArrayBuffer
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scalajs.concurrent.JSExecutionContext.Implicits.queue
import org.scalajs.dom.raw._

/**
* The connection from workbench server to the client
*/
object Wire extends autowire.Server[Js.Value, Reader, Writer] with ReadWrite {
def wire(parsed: Js.Arr): Unit = {
val Js.Arr(path, args: Js.Obj) = parsed
val req = new Request(default.readJs[Seq[String]](path), args.value.toMap)
Wire.route[Api](WorkbenchClient).apply(req)
object Wire extends autowire.Server[ujson.Value, Reader, Writer] with ReadWrite {
def wire(parsed: ArrayBuffer[Value]): Unit = {
val jsObj = parsed.drop(1).head.obj.toMap
val req = new Request(default.read[Seq[String]](parsed.head), jsObj)
Wire.route[WorkbenchApi](WorkbenchClient).apply(req)
}
}

@JSExportTopLevel("WorkbenchClient")
object WorkbenchClient extends Api {
object WorkbenchClient extends WorkbenchApi {
@JSExport
lazy val shadowBody = dom.document.body.cloneNode(deep = true)
lazy val shadowBody: Node = dom.document.body.cloneNode(deep = true)

@JSExport
var interval = 1000
@JSExport
var success = false

@JSExport
def main(host: String, port: Int): Unit = {
def rec(): Unit = {
Expand All @@ -40,10 +41,10 @@ object WorkbenchClient extends Api {
if (!success) println("Workbench connected")
success = true
interval = 1000
json.read(data.responseText)
.asInstanceOf[Js.Arr]
.value
.foreach(v => Wire.wire(v.asInstanceOf[Js.Arr]))
ujson
.read(data.responseText)
.arr
.foreach(v => Wire.wire(v.arr))
rec()
case util.Failure(e) =>
if (success) println("Workbench disconnected " + e)
Expand Down
2 changes: 1 addition & 1 deletion example/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enablePlugins(WorkbenchPlugin)

name := "Example"

scalaVersion := "2.12.3"
scalaVersion := "2.12.6"

version := "0.1-SNAPSHOT"

Expand Down
2 changes: 1 addition & 1 deletion example/project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.19")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.24")

lazy val workbench = RootProject(file("../.."))
lazy val root = project.in(file(".")).dependsOn(workbench)
2 changes: 1 addition & 1 deletion example/src/main/resources/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script type="text/javascript" src="../example-fastopt.js"></script>

<script>
example.ScalaJSExample().main();
example.ScalaJSExample.main();
</script>
</body>
</html>
26 changes: 15 additions & 11 deletions example/src/main/scala/example/ScalaJSExample.scala
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
package example
import scala.scalajs.js.annotation.JSExport
import org.scalajs.dom
import org.scalajs.dom.html
import scala.scalajs.js.annotation.{JSExportTopLevel, JSExport}
import org.scalajs.dom.{html, document, window, CanvasRenderingContext2D}
import scala.util.Random

case class Point(x: Int, y: Int){
case class Point(x: Int = Random.nextInt(255),
y: Int = Random.nextInt(255),
dx: Int = Random.nextInt(3) - 1,
dy: Int = Random.nextInt(3) - 1){
def +(p: Point) = Point(x + p.x, y + p.y)
def /(d: Int) = Point(x / d, y / d)
}

@JSExport
@JSExportTopLevel("example.ScalaJSExample")
object ScalaJSExample {
val ctx =
dom.document
document
.getElementById("canvas")
.asInstanceOf[html.Canvas]
.getContext("2d")
.asInstanceOf[dom.CanvasRenderingContext2D]
.asInstanceOf[CanvasRenderingContext2D]

var p = Point(128, 128)
var color = "black"

var enemiess = List.fill(10)(Point(util.Random.nextInt(255), util.Random.nextInt(255)))
var enemiess = List.fill(10)(Point())
def clear() = {
ctx.fillStyle = color
ctx.fillRect(0, 0, 255, 255)
}

def run = {
def run(time: Double): Unit = {
clear()
ctx.fillStyle = "yellow"
p = Point(p.x, (p.y + 2) % 255)
ctx.fillRect(p.x, p.y, 5, 20)
enemiess = for (enemy <- enemiess) yield {
ctx.fillStyle = "red"
ctx.fillRect(enemy.x, enemy.y, 10, 10)
Point((enemy.x + 1) % 255, (enemy.y + 1) % 255)
enemy.copy(x = (enemy.x + enemy.dx + 255) % 255, y = (enemy.y + enemy.dy + 255) % 255)
}
window.requestAnimationFrame(this.run)
}

@JSExport
def main(): Unit = {
dom.window.setInterval(() => run, 10)
run(0)
}
}
14 changes: 7 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import sbt._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._

object Dependencies {

// jvm dependencies
val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.0.10"
val akka = "com.typesafe.akka" %% "akka-actor" % "2.4.19"
val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.1.12"
val akka = "com.typesafe.akka" %% "akka-actor" % "2.6.5"
val akkaStream = "com.typesafe.akka" %% "akka-stream" % "2.6.5"

// js and shared dependencies
val autowire = Def.setting("com.lihaoyi" %%% "autowire" % "0.2.6")
val dom = Def.setting("org.scala-js" %%% "scalajs-dom" % "0.9.3")
val upickle = Def.setting("com.lihaoyi" %%% "upickle" % "0.4.4")

val autowire = Def.setting("com.lihaoyi" %%% "autowire" % "0.3.2")
val dom = Def.setting("org.scala-js" %%% "scalajs-dom" % "1.0.0")
val upickle = Def.setting("com.lihaoyi" %%% "upickle" % "1.2.0")
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.0.3
sbt.version=1.3.8
2 changes: 1 addition & 1 deletion project/build.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.21")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.1.1")
42 changes: 42 additions & 0 deletions shared/main/scala/com/lihaoyi/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.lihaoyi

package object workbench {

import upickle.default.{Reader, Writer}

/**
* A standard way to read and write `Js.Value`s with autowire/upickle
*/
trait ReadWrite {
def write[Result: Writer](r: Result) = upickle.default.writeJs(r)
def read[Result: Reader](p: ujson.Value) = upickle.default.read[Result](p)
}

/**
* Shared API between the workbench server and the workbench client,
* comprising methods the server can call on the client to make it do
* things
*/
trait WorkbenchApi {
/**
* Reset the HTML page to its initial state
*/
def clear(): Unit

/**
* Reload the entire webpage
*/
def reload(): Unit

/**
* Print a `msg` with the given logging `level`
*/
def print(level: String, msg: String): Unit

/**
* Execute the javascript file available at the given `path`.
*/
def run(path: String): Unit
}

}
39 changes: 0 additions & 39 deletions shared/main/scala/workbench/Shared.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lihaoyi.workbench


import java.io.File

import akka.event.LoggingAdapter
Expand Down
Loading