Browse files

Use Walker instead of findit. Some status clean up.

  • Loading branch information...
1 parent 0df4c6d commit d31870bf40fd17f83e49dc1d2684598334d8b7f7 @epeli committed Jul 16, 2011
Showing with 27 additions and 26 deletions.
  1. +13 −5 lib/main.coffee
  2. +9 −14 lib/web/clientscripts/main.coffee
  3. +4 −6 lib/web/server.coffee
  4. +1 −1 package.json
View
18 lib/main.coffee
@@ -3,10 +3,10 @@ path = require "path"
fs = require "fs"
{ EventEmitter } = require 'events'
{exec} = require "child_process"
+walker = require "walker"
watch = require "watch"
gex = require "gex"
-findit = require "findit"
iniparser = require "iniparser"
port = 5678
@@ -35,6 +35,7 @@ class Watcher extends EventEmitter
@rerun = false
@running = false
@exitstatus = 0
+ @status = "start"
idfy: (name) ->
# Goofy iding function. Removes bad stuff from name. Nowjs dies if there is
@@ -59,6 +60,10 @@ class Watcher extends EventEmitter
monitor.on "created", (file) => @onModified(file)
monitor.on "changed", (file) => @onModified(file)
+ emitStatus: (status) ->
+ @status = status
+ @emit "status", @status
+
onModified: (filepath, manual=false) ->
if not manual
@@ -71,6 +76,8 @@ class Watcher extends EventEmitter
# Oh we are already running. Just request restart for this change.
if @running
+ console.log "Marking rerun because #{ filepath } changed"
+ @emitStatus "rerun"
@rerun = true
else
@runCMD()
@@ -81,9 +88,8 @@ class Watcher extends EventEmitter
runCMD: ->
@resetOutputs()
- @emit "start"
-
@running = true
+ @emitStatus "running"
cmd = exec @settings.cmd, cwd: @cwd, (err) =>
@running = false
@@ -98,13 +104,15 @@ class Watcher extends EventEmitter
@exitstatus = 1
if @exitstatus isnt 0
+ @emitStatus "error"
console.log "Error in '#{ @name }'
details http://localhost:#{ port }/##{ @id }"
else
console.log "\nRan", @name, "successfully!\n", (new Date) + 2*60*60
@exitstatus = 0
+ @emitStatus "success"
+
- @emit "end", @exitstatus
if @rerun
@@ -137,7 +145,7 @@ exports.run = ->
console.log "Searching projectwatch.cfg files from #{ dirs }\n"
for searchDir in dirs
- finder = findit.find(searchDir)
+ finder = walker searchDir
finder.on "file", (filepath) ->
if path.basename(filepath) is "projectwatch.cfg"
iniparser.parse filepath, (err, settingsObs) ->
View
23 lib/web/clientscripts/main.coffee
@@ -14,7 +14,8 @@ class WatcherRemote extends JQEvenEmitter
constructor: (options) ->
super
- @status = "ok"
+ console.log "init status", options.status
+ @status = options.status
@id = options.id
@name = options.name
@cmd = options.cmd
@@ -42,20 +43,13 @@ class WatcherRemote extends JQEvenEmitter
@reset()
@emit "update"
- remote.sendExitStatus = (exitstatus) =>
+ remote.sendStatus = (status) =>
# Emits update
- console.log "Got exitstatus from server", exitstatus, @id
- @setStatus exitstatus
-
-
- setStatus: (exitstatus) ->
- # Blueprint classes
- if exitstatus is 0
- @status = "success"
- else
- @status = "error"
+ console.log "Got status from server", status, @id
+ @status = status
@emit "update"
+
reset: ->
@stdout = ""
@stderr = ""
@@ -65,8 +59,9 @@ class WatcherRemote extends JQEvenEmitter
@stdout = data.stdout
@stderr = data.stderr
@stdboth = data.stdboth
- # This will emit update
- @setStatus data.exitstatus
+ console.log "update status", data.status
+ @status = data.status
+ @emit "update"
class WatcherView
View
10 lib/web/server.coffee
@@ -41,7 +41,7 @@ everyone.on "connect", ->
stdout: w.stdout
stderr: w.stderr
stdboth: w.stdboth
- exitstatus: w.exitstatus
+ status: w.status
cmd: w.settings.cmd
cfgfile: "#{ w.settings.watchdir }/projectwatch.cfg"
@@ -54,8 +54,6 @@ everyone.now.manualRun = (id) ->
exports.registerWatcher = (watcher) ->
-
- console.log "registering", watcher.id
watchers[watcher.id] = watcher
watcher.on "stdout", (data) ->
@@ -64,10 +62,10 @@ exports.registerWatcher = (watcher) ->
everyone.now[watcher.id]?.sendStderr(data)
watcher.on "stdboth", (data) ->
everyone.now[watcher.id]?.sendStdboth(data)
- watcher.on "start", (data) ->
+ watcher.on "running", (data) ->
everyone.now[watcher.id]?.sendReset()
- watcher.on "end", (exitstatus) ->
- everyone.now[watcher.id]?.sendExitStatus exitstatus
+ watcher.on "status", (status) ->
+ everyone.now[watcher.id]?.sendStatus status
exports.start = (port=8080) ->
View
2 package.json
@@ -12,7 +12,7 @@
, "dependencies": {
"coffee-script": ""
, "watch": ""
- , "findit": ""
+ , "walker": ""
, "iniparser": ""
, "underscore": ""
, "gex": ""

0 comments on commit d31870b

Please sign in to comment.