Browse files

Generate ids on the server and use those as shared function names.

  • Loading branch information...
1 parent 0d3a5a9 commit 96b0995e38751be2ebc2dd3b9c5f2c73817eb378 @epeli committed Jun 20, 2011
Showing with 30 additions and 19 deletions.
  1. +10 −3 lib/main.coffee
  2. +6 −6 lib/web/clientscripts/main.coffee
  3. +14 −10 lib/web/server.coffee
View
13 lib/main.coffee
@@ -9,14 +9,17 @@ gex = require "gex"
findit = require "findit"
iniparser = require "iniparser"
-
port = 5678
+
+
class Watcher extends EventEmitter
constructor: (@name, @cwd, @settings) ->
super
+ @id = @idfy @name
+
@settings.glob ||= "*"
@settings.watchdir ||= "."
@@ -27,6 +30,11 @@ class Watcher extends EventEmitter
@running = false
@exitstatus = 0
+ idfy: (name) ->
+ # Goofy iding function. Removes bad stuff from name. Nowjs dies if there is
+ # dots in path etc. This should be enough unique. If not, user has way too
+ # similar task names :P
+ safename = name.replace( /[^a-zA-z]/g, "").toLowerCase()
resetOutputs: ->
@@ -73,9 +81,8 @@ class Watcher extends EventEmitter
@running = false
if err
- id = @name.replace /[^a-zA-z]/g, ""
console.log """Error in '#{ @name }'
- details http://localhost:#{ port }/##{ id }"""
+ details http://localhost:#{ port }/##{ @id }"""
@exitstatus = err.code
else
console.log "\nRan", @name, "successfully!\n", (new Date) + 2*60*60
View
12 lib/web/clientscripts/main.coffee
@@ -15,7 +15,7 @@ class WatcherRemote extends JQEvenEmitter
constructor: (options) ->
super
@status = "ok"
- @id = options.name.replace /[^a-zA-z]/g, ""
+ @id = options.id
@name = options.name
@lastUpdated = (new Date()).getTime()
@@ -24,7 +24,7 @@ class WatcherRemote extends JQEvenEmitter
@active = false
@update options
- remote = now[@name] = {}
+ remote = now[@id] = {}
remote.sendStdout = (data) =>
@stdout += data
@@ -112,14 +112,14 @@ class WatcherManager
@watchers = {}
createWatcher: (options) ->
- if not @watchers[options.name]?
+ if not @watchers[options.id]?
model = new WatcherRemote options
- w = @watchers[options.name] = new WatcherView
+ w = @watchers[options.id] = new WatcherView
model: model
el: $("<div>").appendTo("body")
@notifies.add model
else
- w = @watchers[options.name]
+ w = @watchers[options.id]
w.model.update options
w.render()
@@ -131,7 +131,7 @@ class RerunButton
@el = ops.el
@watcher = ops.watcher
@el.click =>
- now.manualRun @watcher.model.name
+ now.manualRun @watcher.model.id
false
View
24 lib/web/server.coffee
@@ -32,9 +32,10 @@ app.get "/:name", renderApp
everyone.on "connect", ->
ws = []
- for name, w of watchers
+ for id, w of watchers
ws.push
- name: name
+ id: id
+ name: w.name
stdout: w.stdout
stderr: w.stderr
stdboth: w.stdboth
@@ -43,23 +44,26 @@ everyone.on "connect", ->
@now.init ws
-everyone.now.manualRun = (name) ->
- watcher = watchers[name]
+everyone.now.manualRun = (id) ->
+ watcher = watchers[id]
watcher.onModified "", true
exports.registerWatcher = (watcher) ->
- watchers[watcher.name] = watcher
+
+
+ console.log "registering", watcher.id
+ watchers[watcher.id] = watcher
watcher.on "stdout", (data) ->
- everyone.now[watcher.name]?.sendStdout(data)
+ everyone.now[watcher.id]?.sendStdout(data)
watcher.on "stderr", (data) ->
- everyone.now[watcher.name]?.sendStderr(data)
+ everyone.now[watcher.id]?.sendStderr(data)
watcher.on "stdboth", (data) ->
- everyone.now[watcher.name]?.sendStdboth(data)
+ everyone.now[watcher.id]?.sendStdboth(data)
watcher.on "start", (data) ->
- everyone.now[watcher.name]?.sendReset()
+ everyone.now[watcher.id]?.sendReset()
watcher.on "end", (exitstatus) ->
- everyone.now[watcher.name]?.sendExitStatus exitstatus
+ everyone.now[watcher.id]?.sendExitStatus exitstatus
exports.start = (port=8080) ->

0 comments on commit 96b0995

Please sign in to comment.