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

Allow command line parameters port and database type

  • Loading branch information...
dmfrancisco committed Jul 14, 2011
1 parent 522a009 commit a3a1af30e0e8959c35e75b378701bddfad04c317
Showing with 41 additions and 32 deletions.
  1. +5 −4 Cakefile
  2. +1 −1 Procfile
  3. +1 −2 editor/index.coffee
  4. +34 −25 web.coffee
View
@@ -1,12 +1,13 @@
-# Run "cake build"
+# Run "cake build-dependencies && cake build"
{exec} = require 'child_process'
-task 'build', 'Build the .js files', (options) ->
+task 'build-dependencies', 'Compile all coffee files from ShareJS', (options) ->
exec "coffee --compile --bare --output node_modules/share/lib/ node_modules/share/src/", (err, stdout, stderr) ->
throw err if err
- console.log stdout + stderr
+ console.log stdout + stderr || 'build-dependencies done.'
+task 'build', 'Build the .js files', (options) ->
exec "coffee -c web.coffee editor/index.coffee", (err, stdout, stderr) ->
throw err if err
- console.log stdout + stderr
+ console.log stdout + stderr || 'build done.'
View
@@ -1 +1 @@
-web: cake build && node web.js
+web: cake build-dependencies && cake build && node web.js
View
@@ -37,10 +37,9 @@ render = (content, name, docName, res, port) ->
res.writeHead 200, {'content-type': 'text/html'}
res.end html
-module.exports = (docName, model, res) ->
+module.exports = (port, docName, model, res) ->
name = docName
docName = "doc:" + docName
- port = process.env.PORT || 3000
model.getSnapshot docName, (data) ->
if data == null
View
@@ -1,12 +1,31 @@
-# Run "npm install", "cake build" and "foreman start" or "node web.js"
+#!/usr/bin/env node
-# require.paths.push '/usr/local/node/lib/node_modules'
-#!/usr/bin/env coffee
-
-connect = require 'connect'
+# Run "npm install", "cake build" and "node web.js"
+connect = require('connect')
sharejs = require('share').server
-sys = require 'sys'
-crypto = require('crypto')
+sys = require('sys')
+crypto = require('crypto')
+
+
+# Processing the command line parameters
+opt = require('optimist')
+ .usage('Collaborative writing with Markdown & Textile.\nUsage: $0 [-p port -d database]')
+ .options('p', {
+ alias: 'port',
+ default: process.env.PORT || process.env.npm_package_config_port || 3000,
+ describe: 'Runs escrito on the specified port.'
+ })
+ .options('d', {
+ alias: 'database',
+ default: process.env.npm_package_config_database || 'memory',
+ describe: "Uses the specified database type. Supported values are 'memory' and 'redis'."
+ })
+ .alias('h', 'help')
+
+if opt.argv.h
+ opt.showHelp()
+ process.exit()
+
server = connect(
connect.favicon(__dirname + '/public/favicon.ico'),
@@ -22,28 +41,18 @@ server = connect(
app.get '/:docName', (req, res, next) ->
docName = req.params.docName
- editor docName, server.model, res, next
-
- # The 404 route
- # app.get '/*', (req, res, next) ->
- # fs.readFile './public/404.html', encoding = 'utf8', (err, data) ->
- # console.log(data)
- # res.writeHead 200, {'Content-Type': 'text/html'}
- # res.write data
- # res.end()
+ editor opt.argv.p, docName, server.model, res, next
)
+
+# # If you're hosting this on Heroku and you're using RedisToGo
# if process.env.REDISTOGO_URL
-# # Using RedisToGo Heroku Add-on
# rtg = require("url").parse(process.env.REDISTOGO_URL)
-# options = { db: { type: 'redis', hostname: rtg.port, port: rtg.hostname } } # ShareJS has a bug and the params are swapped
-# else
-# options = { db: { type: 'redis' } } # Local
-
-options = { db: { type: 'memory' } }
+# # ShareJS has a bug and the params are swapped
+# options = { db: { type: 'redis', hostname: rtg.port, port: rtg.hostname } }
-# Attach the sharejs REST and Socket.io interfaces to the server
+options = { db: { type: opt.argv.d } }
sharejs.attach server, options
+server.listen(opt.argv.p)
-server.listen(process.env.PORT || 3000)
-sys.puts "Escrito is running at #{process.env.PORT}!"
+sys.puts "Escrito is running at http://localhost:#{opt.argv.p}/"

0 comments on commit a3a1af3

Please sign in to comment.