Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Coffee script support #16

Open
wants to merge 4 commits into from

1 participant

This page is out of date. Refresh to see the latest.
Showing with 37 additions and 2 deletions.
  1. +1 −0  README.markdown
  2. +30 −2 bin/spark
  3. +6 −0 examples/coffee/app.coffee
View
1  README.markdown
@@ -16,6 +16,7 @@ Spark provides the following options when starting a server.
- Can change the working directory before running the app
- `--comment` option to label processes in system tools like `ps` or `htop`
- Pass arbitrary code or environment variables to the app
+ - Support [coffee-script](http://jashkenas.github.com/coffee-script/)
## Making an app spark compatible
View
32 bin/spark
@@ -39,6 +39,22 @@ var comment;
var workers;
/**
+ * Coffee script support
+ */
+
+var fileExtname
+
+try {
+ var coffee = require('coffee-script');
+ require.registerExtension('.coffee', function (content) {
+ return coffee.compile(content);
+ });
+ fileExtname = /\.(js|coffee)$/;
+} catch (_) {
+ fileExtname = /\.js$/;
+}
+
+/**
* Verbose output.
*/
@@ -157,7 +173,7 @@ function mkdirs(path, mode) {
*/
function modulePath(path){
- return path.replace(/\.js$/, '');
+ return path.replace(fileExtname, '');
}
/**
@@ -253,8 +269,20 @@ function getAppPath() {
} else if (exists(path + 'server.js')) {
log('detected server.js');
path += 'server';
+ } else if (exists(path + 'app.coffee')) {
+ if (!require.extensions['.coffee']) {
+ abort('coffee-script not found, try `npm install coffee-script`');
+ }
+ log('detected app.coffee');
+ path += 'app';
+ } else if (exists(path + 'server.coffee')) {
+ if (!require.extensions['.coffee']) {
+ abort('coffee-script not found, try `npm install coffee-script`');
+ }
+ log('detected server.coffee');
+ path += 'server';
} else {
- abort('app not found, pass a module path, or create {app,server}.js');
+ abort('app not found, pass a module path, or create {app,server}.{js,coffee}');
}
}
View
6 examples/coffee/app.coffee
@@ -0,0 +1,6 @@
+# port from node example app
+http = require('http')
+
+module.exports = http.createServer (req, res) ->
+ res.writeHead(200, { 'Content-Type': 'text/plain' })
+ res.end(this.env.name)
Something went wrong with that request. Please try again.