Permalink
Browse files

better error reporting and messages

  • Loading branch information...
1 parent 2d05865 commit bcb0ea6a159e891821d9c241b13473f4c1786534 @AriaMinaei committed Mar 29, 2013
Showing with 179 additions and 21 deletions.
  1. +51 −0 lib/ansi-color.js
  2. +34 −12 lib/jitter.js
  3. +48 −0 src/ansi-color.coffee
  4. +46 −9 src/jitter.coffee
View
51 lib/ansi-color.js
@@ -0,0 +1,51 @@
+// Generated by CoffeeScript 1.6.2
+(function() {
+ var ANSI_CODES, setColor;
+
+ setColor = function(str, color) {
+ var ansi_str, attr, color_attrs, i;
+
+ if (!color) {
+ return str;
+ }
+ color_attrs = color.split("+");
+ ansi_str = "";
+ i = 0;
+ attr = void 0;
+ while (attr = color_attrs[i]) {
+ ansi_str += "\u001b[" + ANSI_CODES[attr] + "m";
+ i++;
+ }
+ ansi_str += str + "\u001b[" + ANSI_CODES["off"] + "m";
+ return ansi_str;
+ };
+
+ ANSI_CODES = {
+ off: 0,
+ bold: 1,
+ italic: 3,
+ underline: 4,
+ blink: 5,
+ inverse: 7,
+ hidden: 8,
+ black: 30,
+ red: 31,
+ green: 32,
+ yellow: 33,
+ blue: 34,
+ magenta: 35,
+ cyan: 36,
+ white: 37,
+ black_bg: 40,
+ red_bg: 41,
+ green_bg: 42,
+ yellow_bg: 43,
+ blue_bg: 44,
+ magenta_bg: 45,
+ cyan_bg: 46,
+ white_bg: 47
+ };
+
+ exports.set = setColor;
+
+}).call(this);
View
46 lib/jitter.js
@@ -42,7 +42,7 @@
(function() {
- var BANNER, CoffeeScript, baseSource, baseTarget, baseTest, compile, compileScript, compileScripts, die, e, exec, fs, isSubpath, isWatched, jsPath, notifyGrowl, optionParser, options, optparse, parseOptions, path, print, puts, q, readScript, rootCompile, runTests, target_ext, targetlib, testFiles, usage, watchScript, writeJS, writeSourceMap, _ref,
+ var BANNER, CoffeeScript, baseSource, baseTarget, baseTest, color, compile, compileScript, compileScripts, die, e, exec, fs, isSubpath, isWatched, jsPath, notifyGrowl, optionParser, options, optparse, parseOptions, path, print, puts, q, readScript, rootCompile, runTests, target_ext, targetlib, testFiles, usage, watchScript, writeJS, writeSourceMap, _ref,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
fs = require('fs');
@@ -51,6 +51,8 @@
optparse = require('./optparse');
+ color = require('./ansi-color').set;
+
if (path.basename(process.argv[1]) === 'witter') {
targetlib = 'coco';
target_ext = '.coco';
@@ -106,7 +108,7 @@
}
for (name in dirs) {
dir = dirs[name];
- q(path.exists, dir, function(exists) {
+ q(fs.exists, dir, function(exists) {
if (!exists) {
return die("" + name + " directory '" + dir + "' does not exist.");
} else if (!fs.statSync(dir).isDirectory()) {
@@ -185,7 +187,7 @@
};
compileScript = function(source, target, options) {
- var code, coffeePath, currentJS, err, js, jsFilename, mapFilename, mapPath, numOfParentDirs, pathToRoot, slashedTargetPath, sourceMap, targetPath;
+ var code, coffeePath, currentJS, err, js, jsFilename, mapFilename, mapPath, msg, numOfParentDirs, pathToRoot, slashedTargetPath, sourceMap, targetPath;
targetPath = jsPath(source, target);
try {
@@ -238,13 +240,27 @@
writeSourceMap(sourceMap, mapPath);
}
if (currentJS != null) {
- return puts('Recompiled ' + source);
+ return puts('\nRecompiled ' + source);
} else {
- return puts('Compiled ' + source);
+ return puts('\nCompiled ' + source);
}
} catch (_error) {
err = _error;
- puts('Error: ' + source + ': ' + err.message);
+ msg = (function() {
+ var name, ret;
+
+ name = path.basename(source);
+ ret = '\nError: ';
+ ret += source.substr(0, source.length - name.length);
+ ret += color(name + ':' + (err.location.first_line + 1), 'bold');
+ ret = color(ret, 'red');
+ ret += '\n\n ' + err.message + '\n';
+ return ret;
+ })();
+ puts(msg);
+ if (options != null ? options.beep : void 0) {
+ console.log("\007");
+ }
return notifyGrowl(source, err.message);
}
};
@@ -287,18 +303,24 @@
};
runTests = function() {
- var test, _i, _len, _results;
+ var output, test, _i, _len, _results;
_results = [];
for (_i = 0, _len = testFiles.length; _i < _len; _i++) {
test = testFiles[_i];
- puts("Running " + test);
+ output = "\nRunning " + test;
_results.push(exec("node " + test, function(error, stdout, stderr) {
- print(stdout);
- print(stderr);
if (stderr) {
- return notifyGrowl(test, stderr);
+ notifyGrowl(test, stderr);
+ }
+ if (stderr && (options != null ? options.beep : void 0)) {
+ console.log("\007");
+ output += color(' ' + 'FAILED ->', 'red');
+ output += '\n' + stdout + stderr + '\n';
+ } else {
+ output += color(' ' + 'PASSED', 'green');
}
+ return puts(output);
}));
}
return _results;
@@ -307,7 +329,7 @@
parseOptions = function() {
var arg, _ref1;
- optionParser = new optparse.OptionParser([['-b', '--bare', 'compile without the top-level function wrapper'], ['-m', '--map', 'compile with source maps']], BANNER);
+ optionParser = new optparse.OptionParser([['-b', '--bare', 'compile without the top-level function wrapper'], ['-m', '--map', 'compile with source maps'], ['-p', '--beep', 'make a beep sound on errors']], BANNER);
options = optionParser.parse(process.argv);
_ref1 = (function() {
var _i, _results;
View
48 src/ansi-color.coffee
@@ -0,0 +1,48 @@
+# https://github.com/loopj/commonjs-ansi-color
+setColor = (str, color) ->
+
+ return str unless color
+
+ color_attrs = color.split("+")
+ ansi_str = ""
+ i = 0
+ attr = undefined
+
+ while attr = color_attrs[i]
+
+ ansi_str += "\u001b[" + ANSI_CODES[attr] + "m"
+
+ i++
+
+ ansi_str += str + "\u001b[" + ANSI_CODES["off"] + "m"
+
+ ansi_str
+
+ANSI_CODES =
+
+ off: 0
+ bold: 1
+ italic: 3
+ underline: 4
+ blink: 5
+ inverse: 7
+ hidden: 8
+ black: 30
+ red: 31
+ green: 32
+ yellow: 33
+ blue: 34
+ magenta: 35
+ cyan: 36
+ white: 37
+ black_bg: 40
+ red_bg: 41
+ green_bg: 42
+ yellow_bg: 43
+ blue_bg: 44
+ magenta_bg: 45
+ cyan_bg: 46
+ white_bg: 47
+
+
+exports.set = setColor
View
55 src/jitter.coffee
@@ -43,6 +43,7 @@
fs = require 'fs'
path = require 'path'
optparse = require './optparse'
+color = require('./ansi-color').set
if path.basename(process.argv[1]) is 'witter'
@@ -96,7 +97,7 @@ compileScripts = (options) ->
for name, dir of dirs
- q path.exists, dir, (exists) ->
+ q fs.exists, dir, (exists) ->
unless exists
@@ -239,15 +240,37 @@ compileScript = (source, target, options) ->
if currentJS?
- puts 'Recompiled '+ source
+ puts '\nRecompiled '+ source
else
- puts 'Compiled '+ source
+ puts '\nCompiled '+ source
catch err
- puts 'Error: ' + source + ': ' + err.message
+ # console.log err.location
+ #
+ msg = do ->
+
+ name = path.basename source
+
+ # + source + ':' + (err.location.first_line + 1) + ': ' + err.message,
+
+ ret = '\nError: '
+ ret += source.substr(0, source.length - name.length)
+ ret += color name + ':' + (err.location.first_line + 1), 'bold'
+
+ ret = color ret, 'red'
+
+ ret += '\n\n ' + err.message + '\n'
+
+ ret
+
+ puts msg
+
+ if options?.beep
+
+ `console.log("\007")`
notifyGrowl source, err.message
@@ -297,20 +320,34 @@ runTests = ->
for test in testFiles
- puts "Running #{test}"
+ output = "\nRunning #{test}"
exec "node #{test}", (error, stdout, stderr) ->
- print stdout
- print stderr
-
notifyGrowl test, stderr if stderr
+ if stderr and options?.beep
+
+ `console.log("\007")`
+
+ output += color ' ' + 'FAILED ->', 'red'
+ output += '\n' + stdout + stderr + '\n'
+
+ else
+
+ output += color ' ' + 'PASSED', 'green'
+
+ puts output
+
+ # print stdout
+ # print stderr
+
parseOptions = ->
optionParser = new optparse.OptionParser [
['-b', '--bare', 'compile without the top-level function wrapper'],
- ['-m', '--map', 'compile with source maps']
+ ['-m', '--map', 'compile with source maps'],
+ ['-p', '--beep', 'make a beep sound on errors'],
], BANNER
options = optionParser.parse process.argv

0 comments on commit bcb0ea6

Please sign in to comment.