Permalink
Browse files

Merge pull request #13 from alexstrat/master

[new feature] Monitor mode : specify a command to execute before reload browser and rerun specs
  • Loading branch information...
2 parents 27b5258 + d87742f commit e13da4fdf50a4d7b261741eb7608a404a5bc60da @amaierhofer amaierhofer committed Oct 30, 2011
Showing with 27 additions and 4 deletions.
  1. +4 −0 README.md
  2. +2 −1 lib/jasmine-runner.js
  3. +18 −3 lib/monitor.js
  4. +3 −0 lib/template/jasmine.json
View
4 README.md
@@ -31,6 +31,10 @@ Specifies where to load source files from
### spec_dir
Specifies where to load specs from
+### mon
+####build_cmd
+In monitor mode : specify here a command to execute when files change but before browser reloads and specs rerun. For example a build command.
+
### externals
An array of miscelanious scripts to include, like jquery
View
3 lib/jasmine-runner.js
@@ -41,7 +41,8 @@
}
var server = require('server').newServer(config);
server.start();
- require('monitor').startMonitor(server);
+ build_cmd = (typeof config.mon != 'undefined') ? config.mon.build_cmd : undefined;
+ require('monitor').startMonitor(server, build_cmd);
});
},
ci:function(){
View
21 lib/monitor.js
@@ -9,7 +9,7 @@ var fs = require('fs'),
fs.writeFileSync(flag, '');
-var startMonitor = function(server) {
+var startMonitor = function(server, build_cmd) {
var cmd = 'find . -type f -newer ' + flag + ' -print';
setInterval(function(){
exec(cmd, function (error, stdout, stderr) {
@@ -22,8 +22,23 @@ var startMonitor = function(server) {
if (files.length) {
var files = files.filter(function(f){ return f.match(/(.js|.coffee)$/) });
if (server && files.length) {
- console.log('[monitor] sending reload command');
- server.rerun();
+
+ if(typeof build_cmd != 'undefined') {
+ console.log("[monitor] executing command : '"+build_cmd+"'")
+ exec(build_cmd, function(error, stdout, stderr){
+ if(error || stderr) return;
+
+ (stdout = stdout.split(/\n/)).pop();
+ console.log(stdout.join('\n'));
+
+ fs.writeFileSync(flag, '');
+ console.log('[monitor] sending reload command');
+ server.rerun();
+ });
+ }else{
+ console.log('[monitor] sending reload command');
+ server.rerun();
+ }
}
}
}
View
3 lib/template/jasmine.json
@@ -1,6 +1,9 @@
{
"src_dir" : "/public/javascript/",
"spec_dir" : "/spec/",
+ "mon" : {
+ "build_cmd" : "echo 'building instruction executing....'"
+ },
"server":{
"port":8124
},

0 comments on commit e13da4f

Please sign in to comment.