From a220b8d6f12439fd5ff48ba98d5a9e808f0639d6 Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Sat, 19 Oct 2013 21:21:42 -0400 Subject: [PATCH 1/3] Update index.js --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0bcfa40..425d8e6 100644 --- a/index.js +++ b/index.js @@ -116,7 +116,12 @@ FirefoxREPL.prototype = { this.repl.prompt = this.getPrompt(); } }, - + startConsoleListener : function(){ + this.tab.Console.on("console-api-call", function(event){ + this.write((event + "\n").yellow); + this.repl.displayPrompt(); + }); + }, getPrompt: function() { var parts = url.parse(this.tab.url); From 68e83aede8ed20c8f733747ebf34a3ce545bfd8f Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Sun, 20 Oct 2013 02:42:53 -0400 Subject: [PATCH 2/3] Add Console Logging. Collects most errors from the assigned tab. Added IDE launching capabilities --- index.js | 274 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 207 insertions(+), 67 deletions(-) diff --git a/index.js b/index.js index 425d8e6..eb79312 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,10 @@ var util = require("util"), - url = require("url"), - path = require("path"), - repl = require("repl"), - colors = require("colors"), - FirefoxClient = require("firefox-client"); + url = require("url"), + path = require("path"), + repl = require("repl"), + colors = require("colors"), + FirefoxClient = require("firefox-client"); +var exec = require('child_process').exec; const PROP_SHOW_COUNT = 5; @@ -12,13 +13,14 @@ module.exports = FirefoxREPL; function FirefoxREPL() {} FirefoxREPL.prototype = { - start: function(options) { - this.connect(options, function(err, tab) { + + start: function (options) { + this.connect(options, function (err, tab) { if (err) throw err; console.log(tab.url.yellow); - this.setTab(tab) + this.setTab(tab); this.repl = repl.start({ prompt: this.getPrompt(), @@ -29,30 +31,33 @@ FirefoxREPL.prototype = { }); this.defineCommands(); - }.bind(this)) + this.startConsoleListener(); + + }.bind(this)); }, - connect: function(options, cb) { + connect: function (options, cb) { var client = new FirefoxClient(); - client.connect(options.port, options.host, function() { + client.connect(options.port, options.host, function () { client.selectedTab(cb); - }) - client.on("error", function(error) { + }); + client.on("error", function (error) { if (error.code == "ECONNREFUSED") { - throw new Error(error.code - + ": Firefox isn't listening for connections"); + throw new Error(error.code + ": Firefox isn't listening for connections"); } throw error; - }) + }); client.on("end", this.quit); this.client = client; }, - writer: function(output) { + writer: function (output) { if (!output || output.type != "object") { // let inspect do its thing if it's a literal - return util.inspect(output, { colors: true }); + return util.inspect(output, { + colors: true + }); } // do our own object summary var str = ""; @@ -63,31 +68,32 @@ FirefoxREPL.prototype = { // show first N properties of an object, starting with getters var getters = output.safeGetterValues; var names = Object.keys(getters).slice(0, PROP_SHOW_COUNT); - names.map(function(name) { + names.map(function (name) { props[name] = getters[name]; - }) + }); // then the own properties var ownProps = output.ownProps; var remaining = PROP_SHOW_COUNT - names.length; if (remaining) { names = Object.keys(ownProps).slice(0, remaining); - names.map(function(name) { + names.map(function (name) { props[name] = ownProps[name]; }); } // write out a few properties and their values var strs = []; - for (name in props) { + for (var name in props) { var value = props[name].value; value = this.transformResult(value); if (value && value.type == "object") { value = ("[object " + value.class + "]").cyan; - } - else { - value = util.inspect(props[name].value, { colors: true }); + } else { + value = util.inspect(props[name].value, { + colors: true + }); } strs.push(name.magenta + ": " + value); } @@ -97,32 +103,28 @@ FirefoxREPL.prototype = { var total = Object.keys(getters).length + Object.keys(ownProps).length; var more = total - PROP_SHOW_COUNT; if (more > 0) { - str += ", ..." + (more + " more").grey + str += ", ..." + (more + " more").grey; } str += " } "; return str; }, - write: function(str, cb) { + write: function (str, cb) { this.repl.outputStream.write(str, cb); }, - setTab: function(tab) { + setTab: function (tab) { this.tab = tab; if (this.repl) { // repl.prompt not documented in REPL module this.repl.prompt = this.getPrompt(); } + this.startConsoleListener(); }, - startConsoleListener : function(){ - this.tab.Console.on("console-api-call", function(event){ - this.write((event + "\n").yellow); - this.repl.displayPrompt(); - }); - }, - getPrompt: function() { + + getPrompt: function () { var parts = url.parse(this.tab.url); var name = parts.hostname; @@ -133,12 +135,109 @@ FirefoxREPL.prototype = { }, // compliant with node REPL module eval function reqs - eval: function(cmd, context, filename, cb) { + eval: function (cmd, context, filename, cb) { this.evalInTab(cmd, cb); }, - evalInTab: function(input, cb) { - this.tab.Console.evaluateJS(input, function(err, resp) { + startConsoleListener: function () { + + this.tab.Console.on("console-api-call", function (event) { + var mesg = ""; + var lineNumber = event.lineNumber; + + var loc = url.parse(event.filename, true).pathname; + + if (this.storage.length > 2000) { + this.storage.length = 0; + this.consoleErrorCount = 0; + } + this.storage.push({ + msg: mesg, + lineNum: lineNumber, + columnNum: 0, + path: loc + }); + + + mesg = "Error # " + this.consoleErrorCount + " : " + mesg; + this.consoleErrorCount = this.consoleErrorCount + 1; + for (var i = 0; i < event.arguments.length; i = i + 1) { + + if (event.level === "error") { + mesg += (event.arguments[i]).red; // no idea whats going on here yet. + } else if (event.level === "log") { + mesg += (event.arguments[i]).white; + } else if (event.level === "warning") { + mesg += (event.arguments[i]).yellow; + } else if (event.level === "info") { + if (typeof (event.arguments[i].client) !== "object") { + mesg += (event.arguments[i]).green; + } else { + mesg += "Unknown Error occured at " + loc + "@" + event.lineNumber + "(thats all we know)"; + mesg = mesg.red; + } + } + } + + if (mesg !== undefined && mesg !== null) { + this.write(mesg + "\n "); + } else { + console.dir(event); + } + + this.repl.displayPrompt(); + + }.bind(this)); + + this.tab.Console.on("page - error ", function (event) { + + var msg = event.errorMessage; + var lineNumber = event.lineNumber; + var columnNumber = event.columnNumber; + var loc = url.parse(event.sourceName, true).pathname; + + if (this.storage.length > 2000) { + this.storage.length = 0; + this.consoleErrorCount = 0; + } + this.storage.push({ + msg: msg, + lineNum: lineNumber, + columnNum: columnNumber, + path: loc + }); + + + msg = "Error # " + this.consoleErrorCount + ": " + msg; + this.consoleErrorCount = this.consoleErrorCount + 1; + if (event.warning === true) { + + msg = msg.yellow; + } else if (event.error === true) { + + msg = msg.red; + } else if (event.exception === true) { + + msg = msg.cyan; + } else { + msg = msg; + } + // } + if (msg !== undefined && msg !== null) { + this.write(msg + "\n "); + } else { + console.dir(event); + } + + this.repl.displayPrompt(); + }.bind(this)); + + this.tab.Console.startListening(); + }, + storage: [], + consoleErrorCount: 0, + evalInTab: function (input, cb) { + this.tab.Console.evaluateJS(input, function (err, resp) { if (err) throw err; if (resp.exception) { @@ -148,58 +247,99 @@ FirefoxREPL.prototype = { var result = resp.result; - if (result.type == "object") { - result.ownPropertiesAndPrototype(function(err, resp) { + if (result.type == "object ") { + result.ownPropertiesAndPrototype(function (err, resp) { if (err) return cb(err); result.safeGetterValues = resp.safeGetterValues; result.ownProps = resp.ownProperties; cb(null, result); - }) - } - else { + }); + } else { cb(null, this.transformResult(resp.result)); } - }.bind(this)) + }.bind(this)); }, - transformResult: function(result) { + transformResult: function (result) { switch (result.type) { - case "undefined": - return undefined; - case "null": - return null; + case "undefined ": + return undefined; + case "null ": + return null; } return result; }, - defineCommands: function() { - this.repl.defineCommand('tabs', { - help: 'list currently open tabs', + defineCommands: function () { + this.repl.defineCommand("tabs", { + help: "list currently open tabs ", action: this.listTabs.bind(this) - }) + }); - this.repl.defineCommand('quit', { - help: 'quit fxconsole', + this.repl.defineCommand("quit", { + help: "quit fxconsole ", action: this.quit - }) + }); - this.repl.defineCommand('switch', { - help: 'switch to evaluating in another tab by index', + this.repl.defineCommand("switch", { + help: "switch to evaluating in another tab by index", action: this.switchTab.bind(this) - }) + }); + + this.repl.defineCommand("go", { + help: "launch ide with said error number ", + action: this.launch.bind(this) + }); + }, + launch: function (errorNo) { + var success = false; + if (parseInt(errorNo) === "NaN") { + throw new Error("Error number was not a number."); + } + + var ac = this.storage[errorNo]; + for (var i in this.paths) { + var path = ac.path; + var sp = path.split(i); + + if (sp.length > 1) { + var exPath = this.paths[i] + sp[1]; + var editor = this.editor; - switchTab: function(index) { - this.client.listTabs(function(err, tabs) { + var cmd = editor.command + " " + exPath + editor.line + ac.lineNum + editor.column + ac.columnNum; + cmd = cmd; + console.log("launching: " + cmd); + + exec(cmd); + success = true; + this.repl.displayPrompt(); + } + } + if (success !== true) { + console.log("Can 't Launch : No Path Match"); + } + + }, + paths: { + "/emp-map/": "/workspace/projects/extensible-mapping-platform/trunk/emp-map/src/main/webapp/", + "/cpce-map-api/": "/workspace/projects/extensible-mapping-platform/trunk/emp-map-api/src/main/webapp/" + }, + editor: { + command: "/home/johnsonnc/Downloads/Sublime\\ Text\\ 2/sublime_text", + line: ":", + column: ":" + }, + switchTab: function (index) { + this.client.listTabs(function (err, tabs) { if (err) throw err; var tab = tabs[index]; if (!tab) { this.write("no tab at index " + index + "\n"); - } - else { + } else { this.setTab(tab); this.write((this.tab.url + "\n").yellow); } @@ -208,8 +348,8 @@ FirefoxREPL.prototype = { }.bind(this)); }, - listTabs: function() { - this.client.listTabs(function(err, tabs) { + listTabs: function () { + this.client.listTabs(function (err, tabs) { if (err) throw err; var strs = ""; @@ -224,7 +364,7 @@ FirefoxREPL.prototype = { }.bind(this)); }, - quit: function() { + quit: function () { process.exit(0); } -} +}; \ No newline at end of file From 34727e6a6c6f121ba1915829883bc23411665553 Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Sun, 20 Oct 2013 02:52:34 -0400 Subject: [PATCH 3/3] Update index.js Removed some unneeded code. --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index eb79312..67aad10 100644 --- a/index.js +++ b/index.js @@ -324,11 +324,11 @@ FirefoxREPL.prototype = { }, paths: { - "/emp-map/": "/workspace/projects/extensible-mapping-platform/trunk/emp-map/src/main/webapp/", - "/cpce-map-api/": "/workspace/projects/extensible-mapping-platform/trunk/emp-map-api/src/main/webapp/" + "/a-url-path/": "/workspace/projects/eee/trunk/eee/src/main/webapp/", + "/another-url-path/": "/workspace/projects/eee/trunk/eee/src/main/webapp/" }, editor: { - command: "/home/johnsonnc/Downloads/Sublime\\ Text\\ 2/sublime_text", + command: "/home/user/Downloads/Sublime\\ Text\\ 2/sublime_text", line: ":", column: ":" }, @@ -367,4 +367,4 @@ FirefoxREPL.prototype = { quit: function () { process.exit(0); } -}; \ No newline at end of file +};