Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #8 from wronex/master

New lines in error messages and support for Coffee scripts.
  • Loading branch information...
commit e30dd02b9769294c522db11a8574213456293cd3 2 parents d432528 + 789dd42
authored August 04, 2012
38  bin/always.js
@@ -13,12 +13,12 @@ var fs = require('fs')
13 13
   , Monitor = require('../lib/monitor')
14 14
   , args = process.argv
15 15
   , managed = []
16  
-  , specials = /^\s+|\s+$/gmi
17 16
   , previousEvent
18 17
   , directory
19 18
   , node = null
20 19
   , file = null
21 20
   , app = null
  21
+  , parser = 'node' // will change depending on file extension
22 22
   , cleaned
23 23
   , beep = false
24 24
   , version = 'v1.1.1';
@@ -69,8 +69,18 @@ if (args.length === 2) {
69 69
 
70 70
 function initializeDevelopment(){
71 71
   app = npm(args[2]);
  72
+  
  73
+  if (path.extname(app) == '.coffee') {
  74
+    // The file contains coffee script, use coffee to run it. Does this work on
  75
+    // other platforms?
  76
+    parser = process.platform.substr(0,3) == 'win' ? 'coffee.cmd' : 'coffee';
  77
+  } else {
  78
+    // No parser required, use node.
  79
+    parser = 'node';
  80
+  }
  81
+  
72 82
   logger(version);
73  
-  logger('Starting ' +file.green +' with Node');
  83
+  logger('Starting '+ file.green +' with '+ parser);
74 84
   start();
75 85
 };
76 86
 
@@ -82,7 +92,7 @@ function initializeDevelopment(){
82 92
  function help(){
83 93
   console.log([
84 94
     '',
85  
-    'Usage: always <options> <app.js>'.cyan,
  95
+    'Usage: always <options> <app.js|app.coffee>'.cyan,
86 96
     '=> always app.js'.green,
87 97
     '',
88 98
     'Options:',
@@ -189,6 +199,19 @@ function exists(file){
189 199
 };
190 200
 
191 201
 /**
  202
+ * @method trim
  203
+ * @url http://blog.stevenlevithan.com/archives/faster-trim-javascript
  204
+ * @param {String} str String to trim and clean.
  205
+ **/
  206
+function trim(str){
  207
+  var str = str.replace(/^\s\s*/, ''),
  208
+      ws = /\s/,
  209
+	  i = str.length;
  210
+  while (ws.test(str.charAt(--i)));
  211
+  return str.slice(0, i + 1);
  212
+}
  213
+
  214
+/**
192 215
  * @method start
193 216
  * @param {String} app NodeJS file
194 217
  **/
@@ -196,16 +219,17 @@ function exists(file){
196 219
 function start(){
197 220
   if (!exists(app)){
198 221
     return false;
199  
-  } else {
200  
-    node = spawn('node', [app]);
  222
+  } else {    
  223
+    node = spawn(parser, [app]);
  224
+    
201 225
     // watch node child process file
202 226
     initializeFileMonitor(app);
203 227
     node.stdout.on('data', function(data){
204  
-      cleaned = data.toString().replace(specials, '');
  228
+      cleaned = trim(data.toString());
205 229
       appLogger(cleaned);
206 230
     });
207 231
     node.stderr.on('data', function(data){
208  
-      cleaned = data.toString().replace(specials, '');
  232
+      cleaned = trim(data.toString());
209 233
       appLogger(cleaned, true);
210 234
     });
211 235
     node.stderr.on('data', function (data) {
3  lib/monitor.js
... ...
@@ -1,4 +1,3 @@
1  
-
2 1
 /**
3 2
  * @list dependencies
4 3
  **/
@@ -9,7 +8,7 @@ var monitor
9 8
   , path = require('path')
10 9
   , events = require('events')
11 10
   , EventEmitter = events.EventEmitter
12  
-  , exts = /(.*?)\.(js|ejs|json|yaml)$/i
  11
+  , exts = /(.*?)\.(js|ejs|json|yaml|coffee)$/i
13 12
   , watched = [];
14 13
 
15 14
 /**
3  package.json
@@ -11,7 +11,8 @@
11 11
   "contributors": [
12 12
     { "name": "Edward Hotchkiss","email": "edwardhotchkiss@me.com" },
13 13
     { "name": "mugenen","email": "https://twitter.com/#!/Scaled_Wurm" },
14  
-    { "name": "MikeMayer", "github": "https://github.com/MikeMayer" }
  14
+    { "name": "MikeMayer", "github": "https://github.com/MikeMayer" },
  15
+    { "name": "Wronex", "github": "https://github.com/wronex" }
15 16
   ],
16 17
   "keywords":["always","process","forever","error","uncaught"],
17 18
   "engines":{

0 notes on commit e30dd02

Please sign in to comment.
Something went wrong with that request. Please try again.