Permalink
Browse files

Add web view for tasks.

  • Loading branch information...
1 parent c14cc1d commit 6d9bf414cf5c17a7adbedb8fade1fef6bd1d0c0a @epeli committed Jun 19, 2011
View
@@ -8,7 +8,7 @@ independent solution for all of those.
You use it by defining a projectwatch.cfg file(s) to your project directories.
In the file you define what files should be monitored and what command should
-be executed if a change is detected.
+be executed when a change is detected.
Here's an example file
@@ -17,15 +17,21 @@ Here's an example file
glob = *.coffee
cmd = coffee --output js/ src/*
-Command
+and now command
projectwatch path/to/my/project
will go through every directory of your project looking for projectwatch.cfg
files and will start monitors defined in those.
+## Webserver
-## Synopsis
+Because shells are intended for a one output only it gets very messy if you
+have several running applications on one shell. That's why Projectwatch comes
+with embedded webserver which provides a HTML based view for your task
+outputs. The view is updated instantly as your tasks are being run.
+
+## Usage
projectwatch [dir1[,dir2[,...]]]
@@ -78,3 +84,12 @@ Now hack and send some cool pull requests via Github :)
GNU GENERAL PUBLIC LICENSE Version 3. See LICENCE.txt.
+## TODOs
+
+Todos before 1.0.0
+
+- Use some nice command line option parser
+- Get rid off socket.io logging messages
+- Enable custom error detection
+- Notify about errors using HTML5 desktop notifications
+
@@ -1,12 +1,12 @@
-[My project coffees]
+[myproject:coffeescript]
watchdir = ./src
glob = *.coffee
cmd = coffee --output js/ src/*
-[Just another]
-watchdir = ./src
-glob = *.coffee
-cmd = echo "We can have several watchers in one config"
+[myproject:jslint]
+watchdir = ./js
+glob = *.js
+cmd = jslint js/*.js
@@ -1,4 +1,4 @@
-[My project SCSSs]
+[myproject:compass]
watchdir = ./scss
glob = *.scss
cmd = compass compile --css-dir css/ --sass-dir scss/
@@ -3,4 +3,5 @@ p {
span {
color: red;
}
+
}
@@ -1,7 +1,7 @@
-[Long runnin command]
+[myproject:tests]
watchdir = .
glob = *.txt
-cmd = echo "this will take a long time" && sleep 5
+cmd = echo "Running tests simulation" && sleep 5 && echo "DONE" && exit 0
View
@@ -1,6 +1,7 @@
path = require "path"
fs = require "fs"
+{ EventEmitter } = require 'events'
{exec} = require "child_process"
watch = require "watch"
@@ -9,9 +10,13 @@ findit = require "findit"
iniparser = require "iniparser"
-class Watcher
+port = 8080
+
+class Watcher extends EventEmitter
constructor: (@name, @cwd, @settings) ->
+ super
+
@settings.glob ||= "*"
@settings.watchdir ||= "."
@@ -20,6 +25,15 @@ class Watcher
@rerun = false
@running = false
+ @exitstatus = 0
+
+
+
+ resetOutputs: ->
+ @stdout = ""
+ @stderr = ""
+ @stdboth = ""
+
start: ->
@@ -50,12 +64,24 @@ class Watcher
runCMD: ->
+ @resetOutputs()
+ @emit "start"
+
@running = true
cmd = exec @settings.cmd, cwd: @cwd, (err) =>
@running = false
if err
- console.log "Error in '#{ @name }'"
+ id = @name.replace /[^a-zA-z]/g, ""
+ console.log """Error in '#{ @name }'
+ details http://localhost:#{ port }/##{ id }"""
+ @exitstatus = err.code
+ else
+ @exitstatus = 0
+
+ console.log @name, "Emitting", @exitstatus
+ @emit "end", @exitstatus
+
if @rerun
# There has been a change(s) during this run. Let's rerun it.
@@ -65,16 +91,26 @@ class Watcher
else
console.log "\nRan", @name, "successfully!", (new Date) + 2*60*60
- cmd.stdout.on "data", (data) -> process.stdout.write data
- cmd.stderr.on "data", (data) -> process.stderr.write data
+ cmd.stdout.on "data", (data) =>
+ @stdout += data.toString()
+ @stdboth += data.toString()
+ @emit "stdout", data.toString()
+ @emit "stdboth", data.toString()
-exports.run = ->
+ cmd.stderr.on "data", (data) =>
+ @stderr += data.toString()
+ @stdboth += data.toString()
+ @emit "stderr", data.toString()
+ @emit "stdboth", data.toString()
+
+
+webserver = require __dirname + "/web/server.coffee"
+exports.run = ->
dirs = process.argv.splice(2)
dirs.push process.cwd() unless dirs.length
- watchers = {}
console.log "Searching projectwatch.cfg files from #{ dirs }\n"
@@ -88,7 +124,11 @@ exports.run = ->
watcher = new Watcher name, path.dirname(filepath), settings
watcher.start()
watcher.runCMD()
- watchers[name] = watcher
+
+ webserver.registerWatcher watcher
+
+ webserver.start(port)
+
Oops, something went wrong.

0 comments on commit 6d9bf41

Please sign in to comment.