Skip to content

Commit

Permalink
Replace nodebug.cmd with nodebug.js
Browse files Browse the repository at this point in the history
  • Loading branch information
billyzkid committed Jun 27, 2012
1 parent 3fe0b6a commit 0aca57b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
npm-debug.log
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -18,6 +18,6 @@ To debug unit tests:

## What it does

1. Starts node-inspector
2. Executes the specified script with the node debugger attached
3. Launches the debugging interface in Chrome
1. Executes the specified script with the node debugger attached (i.e. --debug-brk)
2. Starts node-inspector
3. Launches the debugging interface (i.e. Chrome)
14 changes: 0 additions & 14 deletions bin/nodebug.cmd

This file was deleted.

70 changes: 70 additions & 0 deletions bin/nodebug.js
@@ -0,0 +1,70 @@
#!/usr/bin/env node

var fs = require("fs");
var path = require("path");
var child_process = require("child_process");
var optimist = require("optimist");

var argv = optimist
.usage("Usage: nodebug script.js [options]")
.options("help", { alias: "h", boolean: true, describe: "Show this help and exit" })
.options("port", { "default": 5858, describe: "Debug port used by node" })
.options("web-host", { "default": "127.0.0.1", string: true, describe: "Web host used by node-inspector" })
.options("web-port", { "default": 8080, describe: "Web port used by node-inspector" })
.argv;

if (argv["help"] || !argv["_"].length) {
optimist.showHelp();
process.exit();
}

var config = {
nodePath: getNodePath(),
nodeArgs: [ "--debug-brk=" + argv["port"] ].concat(argv["_"]),
nodeInspectorPath: getNodeInspectorPath(),
nodeInspectorArgs: [ "--web-host=" + argv["web-host"], "--web-port=" + argv["web-port"] ],
webBrowserPath: getWebBrowserPath(),
webBrowserArgs: [ "http://" + argv["web-host"] + ":" + argv["web-port"] + "/debug?port=" + argv["port"] ]
};

function getNodePath() {
return process.execPath;
}

function getNodeInspectorPath() {
if (process.platform === "win32") {
return path.join(__dirname, "..\\node_modules\\.bin\\node-inspector.cmd");
} else {
// TODO: support darwin, freebsd, linux, solaris, etc.
console.error("unsupported platform");
process.exit(1);
}
}

function getWebBrowserPath() {
if (process.platform === "win32") {
var paths = [
path.join(process.env["LocalAppData"], ".\\Google\\Chrome\\Application\\chrome.exe"),
path.join(process.env["ProgramFiles"], ".\\Google\\Chrome\\Application\\chrome.exe"),
path.join(process.env["ProgramFiles(x86)"], ".\\Google\\Chrome\\Application\\chrome.exe")
];
} else {
// TODO: support darwin, freebsd, linux, solaris, etc.
console.error("unsupported platform");
process.exit(1);
}

for (var i = 0, l = paths.length, p; i < l; i++) {
p = paths[i];
if (fs.existsSync(p)) {
return p;
}
}

console.error("web browser not found");
process.exit(1);
}

child_process.spawn(config.nodePath, config.nodeArgs, { stdio: "inherit" }).on("exit", process.exit);
child_process.execFile(config.nodeInspectorPath, config.nodeInspectorArgs);
child_process.execFile(config.webBrowserPath, config.webBrowserArgs);
9 changes: 5 additions & 4 deletions package.json
Expand Up @@ -3,24 +3,25 @@
"description": "Command-line utility that simplifies node debugging",
"keywords": ["debug", "debugger", "debugging", "node", "inspector", "chrome", "cli"],
"author": "Will Allan <billyzkid@yahoo.com>",
"version": "0.1.0",
"version": "0.1.1",
"preferGlobal": true,
"licenses": [{
"type": "MIT",
"url": "https://raw.github.com/billyzkid/nodebug/master/LICENSE"
}],
"bin": {
"nodebug": "./bin/nodebug.cmd"
"nodebug": "./bin/nodebug.js"
},
"dependencies": {
"node-inspector": "0.2.x"
"node-inspector": "0.1.x",
"optimist": "0.3.x"
},
"repository": {
"type": "git",
"url": "https://github.com/billyzkid/nodebug.git"
},
"engines": {
"node": ">=0.6.0"
"node": ">=0.8.0"
},
"bugs": "https://github.com/billyzkid/nodebug/issues"
}

0 comments on commit 0aca57b

Please sign in to comment.