Skip to content

Commit 55dd57f

Browse files
committed
Continued development:
1. Renamed "nodejs-mongodb" to "mongodb" 2. Added support for Kafka-Node 3. Moved express into its own sub-project 4. Updated examples 5. Cleanup
1 parent 39eaa6f commit 55dd57f

File tree

70 files changed

+1561
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1561
-201
lines changed

angularjs/src/main/scala/com/github/ldaniels528/meansjs/angularjs/extensions/FileUpload.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.ldaniels528.meansjs.angularjs.extensions
22

33
import com.github.ldaniels528.meansjs.angularjs.core.HttpPromise
4+
import com.github.ldaniels528.meansjs.util.ScalaJsHelper._
45
import org.scalajs.dom._
56

67
import scala.scalajs.js
@@ -35,17 +36,16 @@ trait FileUploadConfig extends js.Object {
3536
* File Upload Configuration Singleton
3637
3738
*/
38-
@js.native
39-
object FileUploadConfig extends js.Object {
39+
object FileUploadConfig {
4040

41-
def apply[T](url: String, file: File, data: Option[T] = None) = {
41+
def apply(url: String, file: File, data: js.Any = js.undefined) = {
4242
require(url != null || url.isEmpty, "Required property 'url' is missing")
4343
require(file != null, "Required property 'file' is missing")
4444

45-
val config = new js.Object().asInstanceOf[FileUploadConfig]
45+
val config = makeNew[FileUploadConfig]
4646
config.url = url
4747
config.file = file
48-
data.foreach(config.data = _)
48+
config.data = data
4949
config
5050
}
5151
}

build.sbt

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sbt.Keys._
44
import sbt.Project.projectToRef
55
import sbt._
66

7-
val apiVersion = "0.0.5"
7+
val apiVersion = "0.0.6"
88
val paradisePluginVersion = "2.1.0"
99
val _scalaVersion = "2.11.8"
1010
val scalaJsDomVersion = "0.9.0"
@@ -15,7 +15,7 @@ val commonSettings = Seq(
1515
version := apiVersion,
1616
scalaVersion := _scalaVersion,
1717
scalacOptions ++= Seq("-feature", "-deprecation"),
18-
homepage := Some(url("http://github.com.ldaniels528/means")),
18+
homepage := Some(url("http://github.com.ldaniels528/MEANS.js")),
1919
addCompilerPlugin("org.scalamacros" % "paradise" % paradisePluginVersion cross CrossVersion.full),
2020
libraryDependencies ++= Seq(
2121
"be.doeraene" %%% "scalajs-jquery" % scalaJsJQueryVersion,
@@ -25,14 +25,14 @@ val commonSettings = Seq(
2525
)
2626

2727
lazy val root = (project in file(".")).
28-
aggregate(core, angularjs, facebook, linkedin, nodejs, nodejs_mongodb)
28+
aggregate(core, angularjs, express, facebook, kafkanode, linkedin, mongodb, nodejs)
2929

3030
lazy val core = (project in file("core")).
3131
enablePlugins(ScalaJSPlugin).
3232
settings(commonSettings: _*).
3333
settings(
3434
name := "means",
35-
description := "Core utilities for MEANS.js"
35+
description := "Core bindings for MEANS.js"
3636
)
3737

3838
lazy val angularjs = (project in file("angularjs")).
@@ -53,6 +53,15 @@ lazy val facebook = (project in file("facebook")).
5353
description := "Facebook buildings for Scala.js"
5454
)
5555

56+
lazy val express = (project in file("express")).
57+
enablePlugins(ScalaJSPlugin).
58+
dependsOn(core, nodejs).
59+
settings(commonSettings: _*).
60+
settings(
61+
name := "means-express",
62+
description := "Express.js bindings for Scala.js"
63+
)
64+
5665
lazy val linkedin = (project in file("linkedin")).
5766
enablePlugins(ScalaJSPlugin).
5867
dependsOn(core, angularjs).
@@ -62,28 +71,37 @@ lazy val linkedin = (project in file("linkedin")).
6271
description := "LinkedIn buildings for Scala.js"
6372
)
6473

65-
lazy val nodejs = (project in file("nodejs")).
74+
lazy val kafkanode = (project in file("kafkanode")).
6675
enablePlugins(ScalaJSPlugin).
67-
dependsOn(core).
76+
dependsOn(core, nodejs).
6877
settings(commonSettings: _*).
6978
settings(
70-
name := "means-nodejs",
71-
description := "Node.js bindings for Scala.js"
79+
name := "means-kafka-node",
80+
description := "Kafka bindings for Scala.js"
7281
)
7382

74-
lazy val nodejs_mongodb = (project in file("nodejs-mongodb")).
83+
lazy val mongodb = (project in file("mongodb")).
7584
enablePlugins(ScalaJSPlugin).
7685
dependsOn(core, nodejs).
7786
settings(commonSettings: _*).
7887
settings(
79-
name := "means-nodejs-mongodb",
80-
description := "MongoDB bindings for Node.js"
88+
name := "means-mongodb",
89+
description := "MongoDB bindings for Scala.js"
90+
)
91+
92+
lazy val nodejs = (project in file("nodejs")).
93+
enablePlugins(ScalaJSPlugin).
94+
dependsOn(core).
95+
settings(commonSettings: _*).
96+
settings(
97+
name := "means-nodejs",
98+
description := "Node.js bindings for Scala.js"
8199
)
82100

83101
lazy val examples = (project in file("examples")).
84-
aggregate(core, nodejs, nodejs_mongodb).
102+
aggregate(core, express, kafkanode, mongodb, nodejs).
85103
enablePlugins(ScalaJSPlugin).
86-
dependsOn(core, nodejs, nodejs_mongodb).
104+
dependsOn(core, express, kafkanode, mongodb, nodejs).
87105
enablePlugins(ScalaJSPlugin).
88106
settings(commonSettings: _*).
89107
settings(

core/src/main/scala/com/github/ldaniels528/meansjs/util/ScalaJsHelper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ object ScalaJsHelper {
120120
implicit class JsAnyExtensions(val obj: js.Any) extends AnyVal {
121121

122122
def New[T <: js.Any](args: js.Any*): T = {
123-
js.Dynamic.newInstance(obj.asInstanceOf[js.Dynamic])(args).asInstanceOf[T]
123+
js.Dynamic.newInstance(obj.asInstanceOf[js.Dynamic])(args: _*).asInstanceOf[T]
124124
}
125125

126126
def ===[T](value: T): Boolean = {

examples/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "skilldepth",
3+
"version": "0.0.4",
4+
"private": true,
5+
"dependencies": {
6+
"azure": "^0.10.6",
7+
"body-parser": "^1.15.0",
8+
"engine.io": "^1.6.8",
9+
"express": "4.13.4",
10+
"express-ws": "^2.0.0-beta",
11+
"fs": "0.0.2",
12+
"html": "0.0.10",
13+
"mongoose": "4.4.11"
14+
}
15+
}

examples/src/main/javascript/nodejs/events/EventEmitting.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
/**
2+
* Event Emitting
3+
4+
*/
15
(function() {
26
const EventEmitter = require("events");
37
const ee = new EventEmitter();
4-
5-
console.log(Error);
68

79
setImmediate(function () {
810
// This will crash the process because no "error" event
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Producer Example
3+
4+
*/
5+
(function () {
6+
7+
const kafka = require('kafka-node'),
8+
Producer = kafka.Producer,
9+
client = new kafka.Client('dev528:2181'),
10+
producer = new Producer(client);
11+
12+
const payloads = [
13+
{topic: 'test', messages: 'This is the First Message I am sending'/*, partition: 0*/}
14+
];
15+
16+
17+
// producer 'on' ready to send payload to kafka.
18+
producer.on('ready', function () {
19+
console.log("Received ready:");
20+
21+
producer.send(payloads, function (err, data) {
22+
console.log("Received data:");
23+
console.log(data)
24+
});
25+
});
26+
27+
producer.on('error', function (err) {
28+
console.log("Received error:");
29+
console.log(err)
30+
});
31+
});

examples/src/main/scala/examples/Examples.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.github.ldaniels528.meansjs.nodejs._
44
import examples.nodejs.events.EventEmitting
55
import examples.nodejs.express.ExpressTest
66
import examples.nodejs.http.HttpServerTest
7+
import examples.nodejs.kafka.{ProducerEnhanced, ProducerExample}
78
import examples.nodejs.mongodb.MongoClientTest
89
import examples.nodejs.net.NetServerTest
910
import examples.nodejs.timers.IntermediateTimers
@@ -24,11 +25,13 @@ object Examples extends js.JSApp {
2425

2526
def start(require: Require) = {
2627
process.argv.drop(2) foreach {
27-
case "events" => new EventEmitting(require)
28+
case "EventEmitting" => new EventEmitting(require)
2829
case "express" => new ExpressTest(require)
2930
case "http" => new HttpServerTest(require)
3031
case "mongodb" => new MongoClientTest(require)
3132
case "net" => new NetServerTest(require)
33+
case "ProducerExample" => new ProducerExample(require)
34+
case "ProducerEnhanced" => new ProducerEnhanced(require)
3235
case "timers" => new IntermediateTimers(require)
3336
case arg =>
3437
console.warn(s"No example found for $arg - Choose from ${names.mkString(", ")}")

examples/src/main/scala/examples/nodejs/events/EventEmitting.scala

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@ package examples.nodejs.events
22

33
import com.github.ldaniels528.meansjs.nodejs._
44
import com.github.ldaniels528.meansjs.nodejs.events.EventEmitter
5-
import com.github.ldaniels528.meansjs.util.ScalaJsHelper._
6-
import org.scalajs.dom.console
7-
8-
import scala.scalajs.js
95

106
/**
11-
* Event Emitting
7+
* Event Emitting Example
128
139
*/
1410
class EventEmitting(require: Require) {
15-
val eventEmitter = require[js.Function0[EventEmitter]]("events")
16-
val ee = eventEmitter.New[EventEmitter]()
17-
18-
console.log(Error)
11+
val eventEmitter = require[EventEmitter]("events")
12+
val ee = eventEmitter()
1913

2014
setImmediate(() => {
2115
// This will crash the process because no "error" event
2216
// handler has been added.
23-
ee.emit("error", Error.New("This will crash"))
17+
ee.emit("error", Error("This will crash"))
2418
})
2519

2620
}

examples/src/main/scala/examples/nodejs/http/HttpServerTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.github.ldaniels528.meansjs.nodejs.http._
66
import scala.scalajs.js
77

88
/**
9-
* Http Server Test
9+
* Http Server Example
1010
1111
*/
1212
class HttpServerTest(require: Require) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package examples.nodejs.kafka
2+
3+
import com.github.ldaniels528.meansjs.kafkanode.KafkaNode._
4+
import com.github.ldaniels528.meansjs.kafkanode.{KafkaNode, Payload}
5+
import com.github.ldaniels528.meansjs.nodejs.Require
6+
import org.scalajs.dom._
7+
8+
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
9+
import scala.scalajs.js
10+
11+
/**
12+
* Producer Scala.js-enhanced Example
13+
14+
*/
15+
class ProducerEnhanced(require: Require) {
16+
17+
val kafka = require[KafkaNode]("kafka-node")
18+
val client = kafka.Client("dev528:2181")
19+
val producer = kafka.Producer(client)
20+
21+
val payloads = js.Array(Payload(
22+
topic = "test", messages = "This is the First Message I am sending", partition = 1
23+
))
24+
25+
// producer "on" ready to send payload to kafka.
26+
producer.onReady(() => {
27+
console.log("Received ready:")
28+
29+
producer.sendAsync(payloads) foreach { data =>
30+
console.log("Received data:")
31+
console.log(data)
32+
}
33+
})
34+
35+
producer.onError((err: KafkaError) => {
36+
console.log("Received error:")
37+
console.log(err)
38+
})
39+
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package examples.nodejs.kafka
2+
3+
import com.github.ldaniels528.meansjs.kafkanode.KafkaNode._
4+
import com.github.ldaniels528.meansjs.kafkanode._
5+
import com.github.ldaniels528.meansjs.nodejs.Require
6+
import org.scalajs.dom.console
7+
8+
import scala.scalajs.js
9+
10+
/**
11+
* Producer Example
12+
13+
*/
14+
class ProducerExample(require: Require) {
15+
16+
val kafka = require[KafkaNode]("kafka-node")
17+
val client = kafka.Client("dev528:2181")
18+
val producer = kafka.Producer(client)
19+
20+
val payloads = js.Array(Payload(
21+
topic = "test", messages = "This is the First Message I am sending", partition = 1
22+
))
23+
24+
// producer "on" ready to send payload to kafka.
25+
producer.on("ready", () => {
26+
console.log("Received ready:")
27+
28+
producer.send(payloads, (err: KafkaError, data: js.Any) => {
29+
console.log("Received data:")
30+
console.log(data)
31+
})
32+
})
33+
34+
producer.on("error", (err: KafkaError) => {
35+
console.log("Received error:")
36+
console.log(err)
37+
})
38+
39+
}

examples/src/main/scala/examples/nodejs/mongodb/MongoClientTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package examples.nodejs.mongodb
22

3+
import com.github.ldaniels528.meansjs.mongodb.MongoDB.MongoError
4+
import com.github.ldaniels528.meansjs.mongodb.{MongoDB, MongoDatabase}
35
import com.github.ldaniels528.meansjs.nodejs._
4-
import com.github.ldaniels528.meansjs.nodejs.mongodb.MongoDB.MongoError
5-
import com.github.ldaniels528.meansjs.nodejs.mongodb.{MongoDB, MongoDatabase}
66
import org.scalajs.dom.console
77

88
/**

0 commit comments

Comments
 (0)