This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Run coffeescripts directly

  • Loading branch information...
dmfrancisco committed Jul 14, 2011
1 parent a342093 commit d26fd96b7a9b8b7cebe02f36bc0ef0791c6ef0ac
Showing with 15 additions and 7 deletions.
  1. +2 −2 package.json
  2. +13 −5 web.coffee
View
@@ -9,9 +9,9 @@
"main": "web.js",
"preferGlobal": true,
"bin": {
- "escrito": "web.js"
+ "escrito": "web.coffee"
},
- "scripts": { "start": "node web.js" },
+ "scripts": { "start": "coffee web.coffee" },
"config" : {
"port" : "3000",
"database" : "memory"
View
@@ -1,4 +1,12 @@
-#!/usr/bin/env node
+#!/usr/bin/env coffee
+
+# Try also to require locally (this is a known coffeescript bug - http://github.com/jashkenas/coffee-script/issues/1035)
+requireModule = (filename) ->
+ try
+ require(filename)
+ catch error
+ require("#{__dirname}/node_modules/#{filename}")
+
# Processing the command line parameters
opt = require('optimist')
@@ -51,17 +59,17 @@ runServer = (argv, sharejs, connect, sys, crypto) ->
sys.puts "Escrito is running at http://localhost:#{argv.p}/"
-connect = require('connect')
+connect = requireModule('connect')
+crypto = requireModule('crypto')
sys = require('sys')
-crypto = require('crypto')
try
- sharejs = require('share').server
+ sharejs = requireModule('share').server
runServer(opt.argv)
catch error
# Build ShareJS (this is not currently done automatically by ShareJS)
exec = require('child_process').exec
exec "cd #{__dirname} && cake build-dependencies", (err, stdout, stderr) ->
throw err if err
- sharejs = require('share').server
+ sharejs = requireModule('share').server
runServer(opt.argv, sharejs, connect, sys, crypto)

0 comments on commit d26fd96

Please sign in to comment.