├── .npmignore ├── .gitignore ├── main ├── build.sbt └── src │ └── main │ ├── scala │ └── Example.scala │ └── coffeescript │ └── example.coffee ├── project ├── build.properties ├── build.sbt └── build.scala ├── test └── src │ └── test │ ├── coffeescript │ └── example-test.coffee │ └── scala │ └── ExampleSpec.scala ├── .travis.yml ├── package.json ├── Gruntfile.coffee └── readme.md /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | target 3 | -------------------------------------------------------------------------------- /main/build.sbt: -------------------------------------------------------------------------------- 1 | scalaJSSettings 2 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.0 2 | -------------------------------------------------------------------------------- /project/build.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.1") 2 | -------------------------------------------------------------------------------- /main/src/main/scala/Example.scala: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | import scala.scalajs.js 4 | import js.annotation.JSExport 5 | 6 | @JSExport 7 | object Example { 8 | @JSExport 9 | def helloWorld() = "Hello World!" 10 | } 11 | -------------------------------------------------------------------------------- /test/src/test/coffeescript/example-test.coffee: -------------------------------------------------------------------------------- 1 | example = require('./example') 2 | should = require('should') 3 | 4 | describe('example', -> 5 | describe('helloWorld()', -> 6 | it('should return "Hello World!"', -> 7 | example.Example().helloWorld().should.be.equal('Hello World!') 8 | ) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/src/test/scala/ExampleSpec.scala: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | import org.specs2.mutable.SpecificationWithJUnit 4 | 5 | final class ExampleSpec extends SpecificationWithJUnit { 6 | "Example helloWorld()" should { 7 | "return String" in { 8 | Example.helloWorld() must beEqualTo("Hello World!") 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /main/src/main/coffeescript/example.coffee: -------------------------------------------------------------------------------- 1 | fs = require('fs') 2 | vm = require('vm') 3 | 4 | scala = {} 5 | sandbox = (path, context) -> 6 | buffer = fs.readFileSync(path) 7 | vm.runInNewContext(buffer, context, path) 8 | 9 | sandbox(__dirname + '/main/target/scala-2.11/scala-node-main-opt.js', scala) 10 | 11 | module.exports = scala 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | scala: 3 | - "2.11.1" 4 | install: 5 | - "rm -rf ~/.nvm" 6 | - "curl -L https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh" 7 | - "source ~/.nvm/nvm.sh" 8 | - "nvm install 0.10" 9 | - "nvm use 0.10" 10 | script: 11 | - "npm install grunt-cli" 12 | - "npm install" 13 | - "grunt test" 14 | -------------------------------------------------------------------------------- /project/build.scala: -------------------------------------------------------------------------------- 1 | import sbt._ 2 | import Keys._ 3 | 4 | object CoreBuild extends Build { 5 | lazy val root = Project("root", file("."), 6 | settings = Defaults.defaultSettings ++ Seq( 7 | scalaVersion := "2.11.1" 8 | ) 9 | ) aggregate(test) 10 | 11 | lazy val test: Project = Project("test", file("test"), 12 | settings = Defaults.defaultSettings ++ Seq( 13 | name := "scala-node-test", 14 | version := "0.2.0", 15 | scalaVersion := "2.11.1", 16 | libraryDependencies ++= Seq("org.specs2" %% "specs2" % "2.3.12" % "test") 17 | ) 18 | ) dependsOn(main % "compile") 19 | 20 | lazy val main: Project = Project("main", file("main"), delegates = root :: Nil, 21 | settings = Defaults.defaultSettings ++ Seq( 22 | name := "scala-node-main", 23 | version := "0.2.0", 24 | scalaVersion := "2.11.1" 25 | ) 26 | ) 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Rocky Madden (http://rockymadden.com/)", 3 | "description": "Proof of concept to determine if Scala.js could be leveraged to make a Node.js module. It can.", 4 | "devDependencies": { 5 | "coffee-script": "1.7.x", 6 | "grunt": "0.4.x", 7 | "grunt-cli": "0.1.x", 8 | "grunt-contrib-coffee": "0.10.x", 9 | "grunt-contrib-copy": "0.5.x", 10 | "grunt-mocha-cov": "0.2.x", 11 | "grunt-shell": "0.7.x", 12 | "mocha": "1.20.x", 13 | "mocha-term-cov-reporter": "0.2.x", 14 | "should": "4.0.x" 15 | }, 16 | "engines": {"node": ">=0.10.0"}, 17 | "homepage": "http://rockymadden.com/scala-node/", 18 | "keywords": ["scala", "scala.js"], 19 | "main": "target/example.js", 20 | "name": "scala-node", 21 | "repository": {"type": "git", "url": "git://github.com/rockymadden/scala-node.git"}, 22 | "scripts": {"prepublish": "grunt make"}, 23 | "version": "0.2.0" 24 | } 25 | -------------------------------------------------------------------------------- /Gruntfile.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (grunt) -> 2 | grunt.initConfig 3 | pkg: grunt.file.readJSON 'package.json' 4 | coffee: 5 | main: files: [{ 6 | expand: true 7 | cwd: 'main/src/main/coffeescript/' 8 | src: ['**/*.coffee'] 9 | dest: 'target/' 10 | ext: '.js' 11 | }] 12 | test: files: [{ 13 | expand: true 14 | cwd: 'test/src/test/coffeescript/' 15 | src: ['**/*.coffee'] 16 | dest: 'target/' 17 | ext: '.js' 18 | }] 19 | copy: 20 | main: files: [src: ['main/target/scala-2.11/**'], dest: 'target/'] 21 | test: files: [src: ['test/target/scala-2.11/**'], dest: 'target/'] 22 | mochacov: 23 | options: 24 | files: ['target/**/*-test.js'] 25 | require: ['should'] 26 | test: options: reporter: 'spec' 27 | shell: 28 | sbtMain: 29 | command: 'sbt main/fullOptJS' 30 | options: stdout: true 31 | sbtTest: 32 | command: 'sbt test/test' 33 | options: 34 | failOnError: true 35 | stdout: true 36 | 37 | grunt.loadNpmTasks('grunt-contrib-coffee') 38 | grunt.loadNpmTasks('grunt-contrib-copy') 39 | grunt.loadNpmTasks('grunt-mocha-cov') 40 | grunt.loadNpmTasks('grunt-shell') 41 | 42 | grunt.registerTask('make', ['shell:sbtMain', 'coffee:main', 'copy:main']) 43 | grunt.registerTask('test', ['make', 'coffee:test', 'copy:test', 'shell:sbtTest', 'mochacov:test']) 44 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | #scala-node [![Build Status](https://travis-ci.org/rockymadden/scala-node.png?branch=master)](http://travis-ci.org/rockymadden/scala-node) 2 | 3 | Proof of concept to determine if [Scala.js](https://github.com/scala-js/scala-js) could be leveraged to make a [Node.js](https://github.com/joyent/node) module. It can. 4 | 5 | __With this structure you can:__ 6 | * Use Scala test frameworks (e.g. specs2) to test your Scala codebase prior to JavaScript compilation. 7 | * Use JavaScript test frameworks (e.g. mocha) to test your JavaScript codebase. This includes your Scala.js compiled code. 8 | 9 | ## Usage 10 | 11 | ``` bash 12 | $ npm install # Dependencies 13 | $ grunt make # Build 14 | $ grunt test # Test 15 | $ npm publish # Publish 16 | ``` 17 | 18 | ## License 19 | ``` 20 | The MIT License (MIT) 21 | 22 | Copyright (c) 2014 Rocky Madden (http://rockymadden.com/) 23 | 24 | Permission is hereby granted, free of charge, to any person obtaining a copy 25 | of this software and associated documentation files (the "Software"), to deal 26 | in the Software without restriction, including without limitation the rights 27 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | copies of the Software, and to permit persons to whom the Software is 29 | furnished to do so, subject to the following conditions: 30 | 31 | The above copyright notice and this permission notice shall be included in 32 | all copies or substantial portions of the Software. 33 | 34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 40 | THE SOFTWARE. 41 | ``` 42 | --------------------------------------------------------------------------------