Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Run coffeescripts directly

  • Loading branch information...
commit d26fd96b7a9b8b7cebe02f36bc0ef0791c6ef0ac 1 parent a342093
David Francisco authored July 14, 2011

Showing 2 changed files with 15 additions and 7 deletions. Show diff stats Hide diff stats

  1. 4  package.json
  2. 18  web.coffee
4  package.json
@@ -9,9 +9,9 @@
9 9
   "main": "web.js",
10 10
   "preferGlobal": true,
11 11
   "bin": {
12  
-    "escrito": "web.js"
  12
+    "escrito": "web.coffee"
13 13
   },
14  
-  "scripts": { "start": "node web.js" },
  14
+  "scripts": { "start": "coffee web.coffee" },
15 15
   "config" : {
16 16
     "port" : "3000",
17 17
     "database" : "memory"
18  web.coffee
... ...
@@ -1,4 +1,12 @@
1  
-#!/usr/bin/env node
  1
+#!/usr/bin/env coffee
  2
+
  3
+# Try also to require locally (this is a known coffeescript bug - http://github.com/jashkenas/coffee-script/issues/1035)
  4
+requireModule = (filename) ->
  5
+  try
  6
+    require(filename)
  7
+  catch error
  8
+    require("#{__dirname}/node_modules/#{filename}")
  9
+
2 10
 
3 11
 # Processing the command line parameters
4 12
 opt = require('optimist')
@@ -51,17 +59,17 @@ runServer = (argv, sharejs, connect, sys, crypto) ->
51 59
   sys.puts "Escrito is running at http://localhost:#{argv.p}/"
52 60
 
53 61
 
54  
-connect = require('connect')
  62
+connect = requireModule('connect')
  63
+crypto  = requireModule('crypto')
55 64
 sys     = require('sys')
56  
-crypto  = require('crypto')
57 65
 
58 66
 try
59  
-  sharejs = require('share').server
  67
+  sharejs = requireModule('share').server
60 68
   runServer(opt.argv)
61 69
 catch error
62 70
   # Build ShareJS (this is not currently done automatically by ShareJS)
63 71
   exec = require('child_process').exec
64 72
   exec "cd #{__dirname} && cake build-dependencies", (err, stdout, stderr) ->
65 73
     throw err if err
66  
-    sharejs = require('share').server
  74
+    sharejs = requireModule('share').server
67 75
     runServer(opt.argv, sharejs, connect, sys, crypto)

0 notes on commit d26fd96

Please sign in to comment.
Something went wrong with that request. Please try again.